diff options
author | Damien George <damien.p.george@gmail.com> | 2019-10-30 12:14:52 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-10-30 12:14:52 +1100 |
commit | 4e1b03d45c4d6be9ad9615f63a1146c46a4136d7 (patch) | |
tree | a7fcebaac6c4208b1d71ebed00282f47f3ffb079 /lib/libc/string0.c | |
parent | 660a61a38830b67cb4f2b6f921d1db60f51c41a4 (diff) |
lib/libc/string0: Add simple implementations of strspn and strcspn.
They are needed for littlefs.
Diffstat (limited to 'lib/libc/string0.c')
-rw-r--r-- | lib/libc/string0.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libc/string0.c b/lib/libc/string0.c index c2f2abd0f..8c86bf65f 100644 --- a/lib/libc/string0.c +++ b/lib/libc/string0.c @@ -217,3 +217,19 @@ char *strstr(const char *haystack, const char *needle) return (char *) haystack; return 0; } + +size_t strspn(const char *s, const char *accept) { + const char *ss = s; + while (*s && strchr(accept, *s) != NULL) { + ++s; + } + return s - ss; +} + +size_t strcspn(const char *s, const char *reject) { + const char *ss = s; + while (*s && strchr(reject, *s) == NULL) { + ++s; + } + return s - ss; +} |