diff options
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/include/string.h | 2 | ||||
-rw-r--r-- | src/user/lib/stdlib.c | 8 | ||||
-rw-r--r-- | src/user/lib/string.c | 8 |
3 files changed, 13 insertions, 5 deletions
diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h index 8930bee..9e08ae5 100644 --- a/src/user/lib/include/string.h +++ b/src/user/lib/include/string.h @@ -4,3 +4,5 @@ int isspace(char c); long strtol(const char *restrict s, char **restrict end, int base); + +char *strchr(const char *s, int c); diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c index 11ca7b6..857b40e 100644 --- a/src/user/lib/stdlib.c +++ b/src/user/lib/stdlib.c @@ -36,11 +36,9 @@ int execv(const char *path, char *const argv[]) { fseek(file, 2, SEEK_SET); if (fgets(buf, sizeof buf, file)) { const char *argv [] = {buf, path, NULL}; - // TODO strchr - char *s = buf; - while (*s && *s != '\n') s++; - *s = '\0'; - execv(argv[0], (void*)argv); + char *endl = strchr(buf, '\n'); + if (endl) *endl = '\0'; + execv(buf, (void*)argv); } } diff --git a/src/user/lib/string.c b/src/user/lib/string.c index 77b996c..92b2e51 100644 --- a/src/user/lib/string.c +++ b/src/user/lib/string.c @@ -49,3 +49,11 @@ long strtol(const char *restrict s, char **restrict end, int base) { if (end) *end = (void*)s; return res * sign; } + +char *strchr(const char *s, int c) { + while (*s) { + if (*s == c) return s; + s++; + } + return NULL; +} |