From ef30871f679f15e3ce36d0ac222a5240b76e1c19 Mon Sep 17 00:00:00 2001 From: Armin Luntzer <armin.luntzer@univie.ac.at> Date: Tue, 12 Nov 2019 16:07:58 +0100 Subject: [PATCH] add memset32(), memset16() --- include/kernel/string.h | 3 +++ lib/string.c | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/kernel/string.h b/include/kernel/string.h index c0bd31d..b39f375 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 d4d52f4..51a37bf 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 -- GitLab