diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/Makefile | 2 | ||||
-rw-r--r-- | lib/libc/string/strchr.c | 3 | ||||
-rw-r--r-- | lib/libc/string/strlen.c | 19 |
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile index b2aea30..ab68ab0 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -13,6 +13,8 @@ SRC=\ string/memset.c \ string/memcmp.c \ string/memchr.c \ + string/strlen.c \ + string/strchr.c ${BUILDDIR}/libc.a: ${SRC} diff --git a/lib/libc/string/strchr.c b/lib/libc/string/strchr.c index 09b4d43..f8b3339 100644 --- a/lib/libc/string/strchr.c +++ b/lib/libc/string/strchr.c @@ -2,9 +2,8 @@ char *strchr(const char *s, int c) { do { - if ((char)c == *s) { + if ((char)c == *s) return (char*)s; - } } while (*s++ != '\0'); return NULL; } diff --git a/lib/libc/string/strlen.c b/lib/libc/string/strlen.c new file mode 100644 index 0000000..a1a73b6 --- /dev/null +++ b/lib/libc/string/strlen.c @@ -0,0 +1,19 @@ +#include <string.h> + +size_t +strlen(const char *s) +{ + int n; + for (n = 0; s[n]; n++) + ; + return n; +} + +size_t +strnlen(const char *s, size_t max) +{ + int n; + for (n = 0; s[n] && n < max; n++) + ; + return n; +} |