aboutsummaryrefslogtreecommitdiff
path: root/src/common/libc/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/libc/string.c')
-rw-r--r--src/common/libc/string.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/libc/string.c b/src/common/libc/string.c
index e1ed21e..4b99dda 100644
--- a/src/common/libc/string.c
+++ b/src/common/libc/string.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
#include <string.h>
#include <kogata/malloc.h>
@@ -149,4 +150,51 @@ int strcoll(const char *s1, const char *s2) {
return strcmp(s1, s2);
}
+void *memchr(const void *s, int c, size_t n) {
+ unsigned char *p = (unsigned char*)s;
+ for (size_t i = 0; i < n; i++) {
+ if (p[i] == (unsigned char)c)
+ return &p[i];
+ }
+ return NULL;
+}
+
+size_t strspn(const char *s, const char *accept) {
+ size_t l = 0;
+ while (s[l] != 0) {
+ bool ok = false;
+ for (const char* p = accept; *p != 0; p++) {
+ if (s[l] == *p) {
+ ok = true;
+ break;
+ }
+ }
+ if (!ok) break;
+ l++;
+ }
+ return l;
+}
+
+const char *strstr(const char *haystack, const char *needle) {
+ for (const char* p = haystack; *p != 0; p++) {
+ if (!strcmp(p, needle)) return p;
+ }
+ return NULL;
+}
+
+char* strerror(int errnum) {
+ // TODO
+ return "(unspecified error)";
+}
+
+const char *strpbrk(const char *s, const char *accept) {
+ while (*s) {
+ for (const char *p = accept; *p != 0; p++) {
+ if (*s == *p) return s;
+ }
+ s++;
+ }
+ return NULL;
+}
+
/* vim: set ts=4 sw=4 tw=0 noet :*/