summaryrefslogtreecommitdiff
path: root/lib/libc/string/strchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string/strchr.c')
-rw-r--r--lib/libc/string/strchr.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/libc/string/strchr.c b/lib/libc/string/strchr.c
new file mode 100644
index 0000000..09b4d43
--- /dev/null
+++ b/lib/libc/string/strchr.c
@@ -0,0 +1,20 @@
+#include <string.h>
+
+char *strchr(const char *s, int c) {
+ do {
+ if ((char)c == *s) {
+ return (char*)s;
+ }
+ } while (*s++ != '\0');
+ return NULL;
+}
+
+char *strrchr(const char *s, int c)
+{
+ const char *last = NULL;
+ do {
+ if (*s == (char)c)
+ last = s;
+ } while (*s++);
+ return (char *)last;
+}