diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/string.h | 4 | ||||
-rw-r--r-- | src/commonlib/bsd/string.c | 20 | ||||
-rw-r--r-- | src/include/string.h | 2 | ||||
-rw-r--r-- | src/lib/string.c | 16 |
4 files changed, 24 insertions, 18 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/string.h b/src/commonlib/bsd/include/commonlib/bsd/string.h index bbd4754800..8e8b896e7e 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/string.h +++ b/src/commonlib/bsd/include/commonlib/bsd/string.h @@ -3,8 +3,12 @@ #ifndef _COMMONLIB_BSD_STRING_H_ #define _COMMONLIB_BSD_STRING_H_ +#include <stddef.h> #include <stdint.h> +size_t strlen(const char *src); +size_t strnlen(const char *str, size_t maxlen); + unsigned int skip_atoi(char **ptr); #endif /* _COMMONLIB_BSD_STRING_H_ */ diff --git a/src/commonlib/bsd/string.c b/src/commonlib/bsd/string.c index 3286d41b1c..a9dce39e8d 100644 --- a/src/commonlib/bsd/string.c +++ b/src/commonlib/bsd/string.c @@ -2,6 +2,26 @@ #include <commonlib/bsd/string.h> #include <ctype.h> +#include <stddef.h> + +size_t strlen(const char *str) +{ + const char *ptr = str; + + while (*ptr++) + ; + return ptr - str - 1; +} + +size_t strnlen(const char *str, size_t maxlen) +{ + const char *ptr = str; + const char *end = str + maxlen + 1; + + while (*ptr++ && ptr < end) + ; + return ptr - str - 1; +} unsigned int skip_atoi(char **ptr) { diff --git a/src/include/string.h b/src/include/string.h index 30d014a006..bbf1c3a362 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -13,8 +13,6 @@ int memcmp(const void *s1, const void *s2, size_t n); void *memchr(const void *s, int c, size_t n); char *strdup(const char *s); char *strconcat(const char *s1, const char *s2); -size_t strnlen(const char *src, size_t max); -size_t strlen(const char *src); char *strchr(const char *s, int c); char *strncpy(char *to, const char *from, size_t count); char *strcpy(char *dst, const char *src); diff --git a/src/lib/string.c b/src/lib/string.c index a7f8074fc7..25d37b68f0 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -33,22 +33,6 @@ char *strconcat(const char *s1, const char *s2) return d; } -size_t strnlen(const char *src, size_t max) -{ - size_t i = 0; - while ((*src++) && (i < max)) - i++; - return i; -} - -size_t strlen(const char *src) -{ - size_t i = 0; - while (*src++) - i++; - return i; -} - char *strchr(const char *s, int c) { do { |