summaryrefslogtreecommitdiff
path: root/libc/string/wstring.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-06-16 04:50:09 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-06-16 04:50:09 +0000
commitb34bab24093904492a924303d4e24faffee2cd87 (patch)
treec6b72498c5425885faab8a98cedaf0cb8cc4ad2a /libc/string/wstring.c
parent889b08e7656a5975f033bdf87ff4bf6366d03606 (diff)
Add memmem().
Diffstat (limited to 'libc/string/wstring.c')
-rw-r--r--libc/string/wstring.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libc/string/wstring.c b/libc/string/wstring.c
index 9661893d5..343e82b6c 100644
--- a/libc/string/wstring.c
+++ b/libc/string/wstring.c
@@ -1462,6 +1462,40 @@ char *_glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen)
#endif
/**********************************************************************/
+#ifdef L_memmem
+
+void *memmem(const void *haystack, size_t haystacklen,
+ const void *needle, size_t needlelen)
+{
+ register const char *ph;
+ register const char *pn;
+ const char *plast;
+ size_t n;
+
+ if (needlelen == 0) {
+ return (void *) haystack;
+ }
+
+ if (haystacklen >= needlelen) {
+ ph = (const char *) haystack;
+ pn = (const char *) needle;
+ plast = ph + (haystacklen - needlelen);
+
+ do {
+ n = 0;
+ while (ph[n] == pn[n]) {
+ if (++n == needlelen) {
+ return (void *) ph;
+ }
+ }
+ } while (++ph <= plast);
+ }
+
+ return NULL;
+}
+
+#endif
+/**********************************************************************/
#ifdef L_wmempcpy
#define L_mempcpy
#define Wmempcpy wmempcpy