summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDaniel Campora <daniel@wipy.io>2015-04-28 15:44:14 +0200
committerDaniel Campora <daniel@wipy.io>2015-04-28 16:48:20 +0200
commitabea1c38a94183999c07c848f0b48ca55b42b653 (patch)
tree0c84f86e6c877909bf075860259ec532f977a6cf
parent9fbc265eb81257bfce9337ebeea12379a24b7472 (diff)
downloadmicropython-abea1c38a94183999c07c848f0b48ca55b42b653.tar.gz
micropython-abea1c38a94183999c07c848f0b48ca55b42b653.zip
lib/libc: Add memchr. We already have strchr, but memchr is useful too.
-rw-r--r--lib/libc/string0.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/libc/string0.c b/lib/libc/string0.c
index 136c1b49cc..8ba118b705 100644
--- a/lib/libc/string0.c
+++ b/lib/libc/string0.c
@@ -114,6 +114,18 @@ int memcmp(const void *s1, const void *s2, size_t n) {
return 0;
}
+void *memchr(const void *s, int c, size_t n) {
+ if (n != 0) {
+ const unsigned char *p = s;
+
+ do {
+ if (*p++ == c)
+ return ((void *)(p - 1));
+ } while (--n != 0);
+ }
+ return 0;
+}
+
size_t strlen(const char *str) {
int len = 0;
for (const char *s = str; *s; s++) {