Skip to content

Commit 16b00dc

Browse files
Seija KijinJeff Law
Seija Kijin
authored and
Jeff Law
committed
Make strstr.c in libiberty ANSI compliant
libiberty/ * strstr.c (strstr): Make implementation ANSI/POSIX compliant.
1 parent d503104 commit 16b00dc

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

libiberty/strstr.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,20 @@ length, the function returns @var{string}.
1616
1717
*/
1818

19-
20-
/* FIXME: The above description is ANSI compiliant. This routine has not
21-
been validated to comply with it. -fnf */
22-
2319
#include <stddef.h>
2420

25-
extern char *strchr (const char *, int);
26-
extern int strncmp (const void *, const void *, size_t);
21+
extern int memcmp (const void *, const void *, size_t);
2722
extern size_t strlen (const char *);
2823

2924
char *
3025
strstr (const char *s1, const char *s2)
3126
{
32-
const char *p = s1;
3327
const size_t len = strlen (s2);
34-
35-
for (; (p = strchr (p, *s2)) != 0; p++)
28+
while (*s1)
3629
{
37-
if (strncmp (p, s2, len) == 0)
38-
return (char *)p;
30+
if (!memcmp (s1, s2, len))
31+
return (char *)s1;
32+
++s1;
3933
}
4034
return (0);
4135
}

0 commit comments

Comments
 (0)