diff options
author | Marvin Borner | 2020-04-15 16:35:29 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-15 16:35:29 +0200 |
commit | aa3d1b4689e6dadd982fe1e5ca8af69ca39c617d (patch) | |
tree | 8d4eff1df3031e601cb50cf005130a591fce35a1 /src/kernel/lib/string | |
parent | 10cd931d75a02942c5ad254cef2e56b515122fa3 (diff) |
Added ext2 filesystem
Diffstat (limited to 'src/kernel/lib/string')
-rw-r--r-- | src/kernel/lib/string/strncmp.c | 16 | ||||
-rw-r--r-- | src/kernel/lib/string/strsep.c | 25 | ||||
-rw-r--r-- | src/kernel/lib/string/strstr.c | 25 |
3 files changed, 66 insertions, 0 deletions
diff --git a/src/kernel/lib/string/strncmp.c b/src/kernel/lib/string/strncmp.c new file mode 100644 index 0000000..4dbac59 --- /dev/null +++ b/src/kernel/lib/string/strncmp.c @@ -0,0 +1,16 @@ +int strncmp(const char *s1, const char *s2, int c) +{ + int result = 0; + + while (c) { + result = *s1 - *s2++; + + if ((result != 0) || (*s1++ == 0)) { + break; + } + + c--; + } + + return result; +}
\ No newline at end of file diff --git a/src/kernel/lib/string/strsep.c b/src/kernel/lib/string/strsep.c new file mode 100644 index 0000000..8f5201e --- /dev/null +++ b/src/kernel/lib/string/strsep.c @@ -0,0 +1,25 @@ +#include <stddef.h> + +char *strsep(char **stringp, const char *delim) +{ + char *s; + const char *spanp; + int c, sc; + char *tok; + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } +}
\ No newline at end of file diff --git a/src/kernel/lib/string/strstr.c b/src/kernel/lib/string/strstr.c new file mode 100644 index 0000000..d58b4d5 --- /dev/null +++ b/src/kernel/lib/string/strstr.c @@ -0,0 +1,25 @@ +#include <stdint.h> +#include <kernel/lib/stdlib.h> + +char *strstr(const char *in, const char *str) +{ + char c; + uint32_t len; + + c = *str++; + if (!c) + return (char *)in; + + len = strlen(str); + do { + char sc; + + do { + sc = *in++; + if (!sc) + return (char *)0; + } while (sc != c); + } while (strncmp(in, str, len) != 0); + + return (char *)(in - 1); +}
\ No newline at end of file |