summaryrefslogtreecommitdiff
path: root/libc/string/i386/memchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/i386/memchr.c')
-rw-r--r--libc/string/i386/memchr.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/libc/string/i386/memchr.c b/libc/string/i386/memchr.c
index bff0538d7..772251cee 100644
--- a/libc/string/i386/memchr.c
+++ b/libc/string/i386/memchr.c
@@ -33,6 +33,7 @@
#include <string.h>
#undef memchr
+//#define memchr TESTING
void *memchr(const void *s, int c, size_t count)
{
void *edi;
@@ -51,4 +52,24 @@ void *memchr(const void *s, int c, size_t count)
);
return edi;
}
+#ifndef memchr
libc_hidden_def(memchr)
+#else
+/* Uncomment TESTING, gcc -D__USE_GNU -m32 -Os memchr.c -o memchr
+ * and run ./memchr
+ */
+int main()
+{
+ static const char str[] = "abc.def";
+ printf((char*)memchr(str, '.',-2) - str == 3 ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.',-1) - str == 3 ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 0) == NULL ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 1) == NULL ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 2) == NULL ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 3) == NULL ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 4) - str == 3 ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str, '.', 5) - str == 3 ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str+3, '.', 0) == NULL ? "ok\n" : "BAD!\n");
+ printf((char*)memchr(str+3, '.', 5) - str == 3 ? "ok\n" : "BAD!\n");
+}
+#endif