diff options
Diffstat (limited to 'libc/string')
-rw-r--r-- | libc/string/Makefile | 13 | ||||
-rw-r--r-- | libc/string/string.c | 15 | ||||
-rw-r--r-- | libc/string/strstr.c | 34 |
3 files changed, 51 insertions, 11 deletions
diff --git a/libc/string/Makefile b/libc/string/Makefile index 488c69549..c9b70829e 100644 --- a/libc/string/Makefile +++ b/libc/string/Makefile @@ -26,7 +26,7 @@ include $(TOPDIR)Rules.mak MSRC=string.c MOBJ=strlen.o strcat.o strcpy.o strchr.o strcmp.o strncat.o strncpy.o \ strncmp.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \ - memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o + memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o stpcpy.o ifeq ($(HAS_LOCALE),true) MOBJ += strcoll.o @@ -35,11 +35,14 @@ endif MSRC1=strsignal.c MOBJ1=strsignal.o psignal.o -CSRC=strpbrk.c strsep.c strstr.c strtok.c strtok_r.c strcspn.c \ +MSRC2=strstr.c +MOBJ2=strstr.o strcasestr.o + +CSRC=strpbrk.c strsep.c strtok.c strtok_r.c strcspn.c \ strspn.c strcasecmp.c strncasecmp.c strerror.c bcopy.c bzero.c \ bcmp.c sys_errlist.c COBJS=$(patsubst %.c,%.o, $(CSRC)) -OBJS=$(MOBJ) $(MOBJ1) $(COBJS) +OBJS=$(MOBJ) $(MOBJ1) $(MOBJ2) $(COBJS) all: $(OBJS) $(LIBC) @@ -52,6 +55,10 @@ $(MOBJ): $(MSRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(STRIPTOOL) -x -R .note -R .comment $*.o +$(MOBJ2): $(MSRC2) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(STRIPTOOL) -x -R .note -R .comment $*.o + $(MOBJ1): $(MSRC1) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(STRIPTOOL) -x -R .note -R .comment $*.o diff --git a/libc/string/string.c b/libc/string/string.c index 27649b43b..0a1ced8b3 100644 --- a/libc/string/string.c +++ b/libc/string/string.c @@ -58,6 +58,21 @@ char *strcpy(char *dst, const char *src) } #endif +/********************** Function stpcpy ************************************/ + +#ifdef L_stpcpy +char *stpcpy(char *dst, const char *src) +{ + register char *ptr = dst; + + while (*src) + *dst++ = *src++; + *dst = '\0'; + + return dst; +} +#endif + /********************** Function strcmp ************************************/ #ifdef L_strcmp diff --git a/libc/string/strstr.c b/libc/string/strstr.c index b1890559b..6742e69cb 100644 --- a/libc/string/strstr.c +++ b/libc/string/strstr.c @@ -25,6 +25,7 @@ * as much fun trying to understand it, as I had to write it :-). * * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ +/* added strcasestr support, davidm@lineo.com */ #if HAVE_CONFIG_H # include <config.h> @@ -36,9 +37,26 @@ typedef unsigned chartype; +#if defined(L_strstr) + +#define VAL(x) (x) +#define FUNC strstr #undef strstr -char *strstr( const char *phaystack, const char *pneedle) +#elif defined(L_strcasestr) + +#include <ctype.h> +#define VAL(x) tolower(x) +#define FUNC strcasestr +#undef strcasestr + +#else + +#error "No target function defined." + +#endif + +char * FUNC ( const char *phaystack, const char *pneedle) { register const unsigned char *haystack, *needle; register chartype b, c; @@ -54,7 +72,7 @@ char *strstr( const char *phaystack, const char *pneedle) if (c == '\0') goto ret0; } - while (c != b); + while (VAL(c) != VAL(b)); c = *++needle; if (c == '\0') @@ -70,39 +88,39 @@ char *strstr( const char *phaystack, const char *pneedle) a = *++haystack; if (a == '\0') goto ret0; - if (a == b) + if (VAL(a) == VAL(b)) break; a = *++haystack; if (a == '\0') goto ret0; shloop:} - while (a != b); + while (VAL(a) != VAL(b)); jin:a = *++haystack; if (a == '\0') goto ret0; - if (a != c) + if (VAL(a) != VAL(c)) goto shloop; rhaystack = haystack-- + 1; rneedle = needle; a = *rneedle; - if (*rhaystack == a) + if (VAL(*rhaystack) == VAL(a)) do { if (a == '\0') goto foundneedle; ++rhaystack; a = *++needle; - if (*rhaystack != a) + if (VAL(*rhaystack) != VAL(a)) break; if (a == '\0') goto foundneedle; ++rhaystack; a = *++needle; } - while (*rhaystack == a); + while (VAL(*rhaystack) == VAL(a)); needle = rneedle; /* took the register-poor approach */ |