summaryrefslogtreecommitdiff
path: root/lib/replace/replace.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-01-02 10:01:11 +1100
committerAndrew Tridgell <tridge@samba.org>2010-01-02 10:08:12 +1100
commitfef3c910da421e890925e5e61275fc457da87f6e (patch)
tree3884c2b98c9ccf3b13b11f2c156769014c1e5527 /lib/replace/replace.c
parent00b39c70f57882a453a8d2e6b0f1f37fd39a2d2a (diff)
downloadsamba-fef3c910da421e890925e5e61275fc457da87f6e.tar.gz
samba-fef3c910da421e890925e5e61275fc457da87f6e.tar.bz2
samba-fef3c910da421e890925e5e61275fc457da87f6e.zip
libreplace: some systems don't have memmem()
added rep_memmem() and a testsuite
Diffstat (limited to 'lib/replace/replace.c')
-rw-r--r--lib/replace/replace.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index fc15717349..17fd46bcc8 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -681,3 +681,26 @@ char *rep_realpath(const char *path, char *resolved_path)
return NULL;
}
#endif
+
+
+#ifndef HAVE_MEMMEM
+void *rep_memmem(const void *haystack, size_t haystacklen,
+ const void *needle, size_t needlelen)
+{
+ if (needlelen == 0) {
+ return discard_const(haystack);
+ }
+ while (haystacklen >= needlelen) {
+ char *p = memchr(haystack, *(const char *)needle,
+ haystacklen-(needlelen-1));
+ if (!p) return NULL;
+ if (memcmp(p, needle, needlelen) == 0) {
+ return p;
+ }
+ haystack = p+1;
+ haystacklen -= (p - (const char *)haystack) + 1;
+ }
+ return NULL;
+}
+#endif
+