libdl: end must be bigger than start
[uclibc-ng.git] / libc / string / memmem.c
blob1b3a0bab6f233f8e35cfdeba1883eff222073589
1 /*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 #include "_string.h"
10 #ifdef __USE_GNU
11 void *memmem(const void *haystack, size_t haystacklen,
12 const void *needle, size_t needlelen)
14 register const char *ph;
15 register const char *pn;
16 const char *plast;
17 size_t n;
19 if (needlelen == 0) {
20 return (void *) haystack;
23 if (haystacklen >= needlelen) {
24 ph = (const char *) haystack;
25 pn = (const char *) needle;
26 plast = ph + (haystacklen - needlelen);
28 do {
29 n = 0;
30 while (ph[n] == pn[n]) {
31 if (++n == needlelen) {
32 return (void *) ph;
35 } while (++ph <= plast);
38 return NULL;
40 #endif