diff --git a/include/kernel/string.h b/include/kernel/string.h index c0bd31db6a4192a3ef23f0fbf1ab05e3730ee260..b39f37523bffa2953d379057cc8afc830e2ef02e 100644 --- a/include/kernel/string.h +++ b/include/kernel/string.h @@ -29,6 +29,9 @@ void *memcpy(void *dest, const void *src, size_t n); char *strcpy(char *dest, const char *src); void bzero(void *s, size_t n); +void *memset16(void *s, uint16_t c, size_t n); +void *memset32(void *s, uint32_t c, size_t n); + int isdigit(int c); int isspace(int c); int isalpha(int c); diff --git a/lib/string.c b/lib/string.c index d4d52f409e9c09eec85b275f0032013da173807b..51a37bf7bd38099eaf22f0258f4a0488f5c4d023 100644 --- a/lib/string.c +++ b/lib/string.c @@ -158,6 +158,7 @@ char *strdup(const char *s) char *dup; + if (!s) return NULL; @@ -583,7 +584,7 @@ EXPORT_SYMBOL(atoi); /** - * @brief fills a memory area with with the constant byte c + * @brief fills a memory area with the constant byte c * * @param s a pointer to the memory area * @param c the byte to set @@ -604,6 +605,49 @@ void *memset(void *s, int c, size_t n) EXPORT_SYMBOL(memset); +/** + * @brief fills a memory area with the constant uint16_t c + * + * @param s a pointer to the memory area + * @param c the uint16_t to set + * @param n the number of uint16_t elements to fill + * + * @returns a pointer to the memory area s + */ + +void *memset16(void *s, uint16_t c, size_t n) +{ + uint16_t *p = s; + + while (n--) + *p++ = c; + + return s; +} +EXPORT_SYMBOL(memset16); + + +/** + * @brief fills a memory area with the constant uint32_t c + * + * @param s a pointer to the memory area + * @param c the uint32_t to set + * @param n the number of uint32_t elements to fill + * + * @returns a pointer to the memory area s + */ + +void *memset32(void *s, uint32_t c, size_t n) +{ + uint32_t *p = s; + + while (n--) + *p++ = c; + + return s; +} +EXPORT_SYMBOL(memset32); + /** * @brief convert a string to a long integer