summaryrefslogtreecommitdiff
path: root/libc/string/i386/memchr.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-19 13:51:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-19 13:51:38 +0000
commit6c106c856412c027ff78a9661386b3a42a52cf36 (patch)
tree7ad4c7fbe228eca31768ba355ebf0d933a406cfe /libc/string/i386/memchr.c
parent6232f9122d61ee11edca902d95e04144f9c5b3c1 (diff)
strncat: shorter version for i386, add small embedded test
memchr: add small embedded test strnlen: make small embedded test easier to use strncmp: reformat assembly to make it readable, no code changes (verified with objdump) text data bss dec hex filename - 46 0 0 46 2e libc/string/i386/strncat.os + 39 0 0 39 27 libc/string/i386/strncat.os
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