1
1
/* Replacements for routines missing on some systems.
2
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
2
Copyright (C) 1995-2005 Free Software Foundation, Inc.
4
4
This file is part of GNU Wget.
121
121
#endif /* not HAVE_STRNCASECMP */
123
123
#ifndef HAVE_STRSTR
124
/* From GNU libc 2.0.6. */
125
/* Return the first ocurrence of NEEDLE in HAYSTACK. */
124
/* From GNU libc 2.3.5. */
127
127
* My personal strstr() implementation that beats most other algorithms.
128
128
* Until someone tells me otherwise, I assume that this is the
131
131
* as much fun trying to understand it, as I had to write it :-).
133
133
* Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
134
135
typedef unsigned chartype;
137
strstr (phaystack, pneedle)
138
const char *phaystack;
140
strstr (const char *phaystack, const char *pneedle)
141
register const unsigned char *haystack, *needle;
142
register chartype b, c;
142
const unsigned char *haystack, *needle;
144
const unsigned char *rneedle;
144
146
haystack = (const unsigned char *) phaystack;
145
needle = (const unsigned char *) pneedle;
148
if ((b = *(needle = (const unsigned char *) pneedle)))
150
haystack--; /* possible ANSI violation */
151
haystack--; /* possible ANSI violation */
156
if (!(a = *++haystack))
161
if (!(c = *++needle))
161
162
goto foundneedle;
168
register const unsigned char *rhaystack, *rneedle;
183
jin: a = *++haystack;
190
rhaystack = haystack-- + 1;
172
if ((a = *++haystack) == c)
179
for (; a != b; a = *++haystack)
183
if ((a = *++haystack) == b)
208
while (*rhaystack == a);
210
needle = rneedle; /* took the register-poor approach */
189
while ((a = *++haystack) != c);
195
const unsigned char *rhaystack;
196
if (*(rhaystack = haystack-- + 1) == (a = *(rneedle = needle)))
201
if (*++rhaystack != (a = *++needle))
206
while (*++rhaystack == (a = *++needle));
207
needle = rneedle; /* took the register-poor aproach */
217
return (char*) haystack;
215
return (char *) haystack;
1437
/* A simple usleep implementation based on select(). For Unix and
1438
Unix-like systems. */
1441
usleep (unsigned long usec)
1446
select (0, NULL, NULL, NULL, &tm);
1450
#endif /* not WINDOWS */
1451
#endif /* not HAVE_USLEEP */
1454
/* Currently unused in Wget. Uncomment if we start using memmove
1458
1436
#ifndef HAVE_MEMMOVE
1460
1438
memmove (char *dest, const char *source, unsigned length)
1475
1453
#endif /* not HAVE_MEMMOVE */
1479
1455
/* fnmatch is a POSIX function, but we include an implementation for
1480
1456
the sake of systems that don't have it. Furthermore, according to
1481
1457
anecdotal evidence, historical implementations of fnmatch are buggy