aboutsummaryrefslogtreecommitdiff
path: root/src/common/libc/string.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2016-07-16 01:28:04 +0200
committerAlex Auvolat <alex@adnab.me>2016-07-16 01:28:04 +0200
commit59000174aa50ed6b2d24a71576d15e6a53c5be0c (patch)
tree38e0a7623f1b83c4dabb1fddfc49014e623f6456 /src/common/libc/string.c
parent32407e728971006ed3d0885e01c22fb66c8adc57 (diff)
downloadkogata-59000174aa50ed6b2d24a71576d15e6a53c5be0c.tar.gz
kogata-59000174aa50ed6b2d24a71576d15e6a53c5be0c.zip
Add stubs for many libc functions, and a few implemenations too
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 :*/