diff --git a/common/lib/libc.c b/common/lib/libc.c new file mode 100644 index 00000000..25b6323f --- /dev/null +++ b/common/lib/libc.c @@ -0,0 +1,45 @@ +#include +#include +#include + +size_t strnlen(const char *str, size_t maxlen) { + size_t len; + + for (len = 0; len < maxlen && str[len]; len++); + + return len; +} + +void *memchr(const void *ptr, int ch, size_t n) { + uint8_t *p = (uint8_t *)ptr; + + for (size_t i = 0; i < n; i++) { + if (p[i] == ch) { + return (void *)ptr + i; + } + } + + return NULL; +} + +char *strchr(const char *str, int ch) { + for (size_t i = 0; str[i]; i++) { + if (str[i] == ch) { + return (char *)str + i; + } + } + + return NULL; +} + +char *strrchr(const char *str, int ch) { + char *p = NULL; + + for (size_t i = 0; str[i]; i++) { + if (str[i] == ch) { + p = (char *)str + i; + } + } + + return p; +} diff --git a/common/lib/libc.s2.c b/common/lib/libc.s2.c index 07aefc47..11bd4461 100644 --- a/common/lib/libc.s2.c +++ b/common/lib/libc.s2.c @@ -112,48 +112,6 @@ size_t strlen(const char *str) { return len; } -size_t strnlen(const char *str, size_t maxlen) { - size_t len; - - for (len = 0; len < maxlen && str[len]; len++); - - return len; -} - -void *memchr(const void *ptr, int ch, size_t n) { - uint8_t *p = (uint8_t *)ptr; - - for (size_t i = 0; i < n; i++) { - if (p[i] == ch) { - return (void *)ptr + i; - } - } - - return NULL; -} - -char *strchr(const char *str, int ch) { - for (size_t i = 0; str[i]; i++) { - if (str[i] == ch) { - return (char *)str + i; - } - } - - return NULL; -} - -char *strrchr(const char *str, int ch) { - char *p = NULL; - - for (size_t i = 0; str[i]; i++) { - if (str[i] == ch) { - p = (char *)str + i; - } - } - - return p; -} - int inet_pton(const char *src, void *dst) { uint8_t array[4]; const char *current = src;