Skip to content
Snippets Groups Projects
Commit e087ee65 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

add string functions:

 * isdigit
 * snprintf
 * vprintf
 * vsprintf
 * vsnprintf
parent 54ef15ce
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,12 @@ ...@@ -8,9 +8,12 @@
#define _KERNEL_STRING_H_ #define _KERNEL_STRING_H_
#include <kernel/types.h> #include <kernel/types.h>
#include <stdarg.h>
#include <limits.h>
int sprintf(char *str, const char *format, ...); int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
int strcmp(const char *s1, const char *s2); int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n);
char *strpbrk(const char *s, const char *accept); char *strpbrk(const char *s, const char *accept);
...@@ -25,8 +28,14 @@ void *memcpy(void *dest, const void *src, size_t n); ...@@ -25,8 +28,14 @@ void *memcpy(void *dest, const void *src, size_t n);
char *strcpy(char *dest, const char *src); char *strcpy(char *dest, const char *src);
void bzero(void *s, size_t n); void bzero(void *s, size_t n);
int isdigit(int c);
int isspace(int c); int isspace(int c);
int atoi(const char *nptr); int atoi(const char *nptr);
int vprintf(const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif /* _KERNEL_STRING_H_ */ #endif /* _KERNEL_STRING_H_ */
...@@ -4,6 +4,7 @@ lib-$(CONFIG_PAGE_MAP) += page.o ...@@ -4,6 +4,7 @@ lib-$(CONFIG_PAGE_MAP) += page.o
lib-$(CONFIG_AR) += ar.o lib-$(CONFIG_AR) += ar.o
lib-$(CONFIG_CHUNK) += chunk.o lib-$(CONFIG_CHUNK) += chunk.o
lib-y += string.o lib-y += string.o
lib-y += vsnprintf.o
lib-y += elf.o lib-y += elf.o
lib-y += data_proc_tracker.o lib-y += data_proc_tracker.o
lib-y += data_proc_task.o lib-y += data_proc_task.o
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <kernel/export.h> #include <kernel/export.h>
#include <kernel/types.h> #include <kernel/types.h>
#include <kernel/string.h> #include <kernel/string.h>
#include <kernel/printk.h>
/** /**
...@@ -25,7 +26,6 @@ ...@@ -25,7 +26,6 @@
* @returns <0, 0 or > 0 if s1 is less than, matches or greater than s2 * @returns <0, 0 or > 0 if s1 is less than, matches or greater than s2
*/ */
#include <kernel/printk.h>
int strcmp(const char *s1, const char *s2) int strcmp(const char *s1, const char *s2)
{ {
unsigned char c1, c2; unsigned char c1, c2;
...@@ -350,11 +350,6 @@ EXPORT_SYMBOL(bzero); ...@@ -350,11 +350,6 @@ EXPORT_SYMBOL(bzero);
#include <stdarg.h>
#include <limits.h>
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
/** /**
* @brief print a string into a buffer * @brief print a string into a buffer
* *
...@@ -380,6 +375,66 @@ int sprintf(char *str, const char *format, ...) ...@@ -380,6 +375,66 @@ int sprintf(char *str, const char *format, ...)
EXPORT_SYMBOL(sprintf); EXPORT_SYMBOL(sprintf);
/**
* @brief print a string into a buffer of a given maximum size
*
* @param str the destination buffer
* @param size the size of the destination buffer
* @param format the format string buffer
* @param ... arguments to the format string
*
* @return the number of characters written to buf
*/
int snprintf(char *str, size_t size, const char *format, ...)
{
int n;
va_list ap;
va_start(ap, format);
n = vsnprintf(str, size, format, ap);
va_end(ap);
return n;
}
EXPORT_SYMBOL(snprintf);
/**
* @brief format a string and print it into a buffer
*
* @param str the destination buffer
* @param format the format string buffer
* @param ... arguments to the format string
*
* @return the number of characters written to buf
*/
int vsprintf(char *str, const char *format, va_list ap)
{
return vsnprintf(str, INT_MAX, format, ap);
}
EXPORT_SYMBOL(vsprintf);
/**
* @brief format a string and print it to the standard output
*
* @param format the format string buffer
* @param ... arguments to the format string
*
* @return the number of characters written to stdout
*/
int vprintf(const char *format, va_list ap)
{
return vsnprintf(NULL, INT_MAX, format, ap);
}
EXPORT_SYMBOL(vprintf);
/** /**
* @brief check if a character is a white space * @brief check if a character is a white space
* *
...@@ -416,6 +471,21 @@ int isspace(int c) ...@@ -416,6 +471,21 @@ int isspace(int c)
} }
EXPORT_SYMBOL(isspace); EXPORT_SYMBOL(isspace);
/**
* @brief check if a character is a digit
*
* @param c the character to test
*
* @returns 0 if not a digit
*/
int isdigit(int c)
{
return '0' <= c && c <= '9';
}
EXPORT_SYMBOL(isdigit);
/** /**
* @brief convert a string to an integer * @brief convert a string to an integer
* *
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment