summaryrefslogtreecommitdiff
path: root/libc/string
diff options
context:
space:
mode:
authorDavid McCullough <davidm@snapgear.com>2001-07-04 11:29:02 +0000
committerDavid McCullough <davidm@snapgear.com>2001-07-04 11:29:02 +0000
commitf5fc8d4321de6a8cd913bafde705993d96a5e820 (patch)
tree089bb21da63f63a76a4534cbc040aea854d10cb1 /libc/string
parent0d85794e9b8a873a44a373d4936c5c26e1a574c9 (diff)
Added stpcpy and strcasestr along with some code to test them.
Diffstat (limited to 'libc/string')
-rw-r--r--libc/string/Makefile13
-rw-r--r--libc/string/string.c15
-rw-r--r--libc/string/strstr.c34
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 */