summaryrefslogtreecommitdiff
path: root/libc/string
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-11 23:54:37 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-11 23:54:37 +0000
commita99617fe8fdb56b3e877558bfd6572ce65ad39de (patch)
tree26c3182125188cb7681885830ea7e32e179c7565 /libc/string
parentd1c3ee2a075fc4e855e352e5a5cf10371f2e77aa (diff)
Finish reorganizing things. At least I think I've finished.
Diffstat (limited to 'libc/string')
-rw-r--r--libc/string/Makefile13
-rw-r--r--libc/string/bcmp.c13
-rw-r--r--libc/string/bcopy.c15
-rw-r--r--libc/string/bzero.c15
-rw-r--r--libc/string/strerror.c46
-rw-r--r--libc/string/strsep.c81
6 files changed, 155 insertions, 28 deletions
diff --git a/libc/string/Makefile b/libc/string/Makefile
index 171970c9a..e4f332ba4 100644
--- a/libc/string/Makefile
+++ b/libc/string/Makefile
@@ -29,10 +29,14 @@ MOBJ=strlen.o strcat.o strcpy.o strcmp.o strncat.o strncpy.o strncmp.o \
strchr.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \
memmove.o memcmp.o memchr.o
-CSRC=strpbrk.c strsep.c strstr.c strtok.c strcspn.c \
- config.c strspn.c strcasecmp.c strncasecmp.c
+MSRC1=index.c
+MOBJ1=index.o rindex.o
+
+CSRC=strpbrk.c strsep.c strstr.c strtok.c strcspn.c config.c \
+ strspn.c strcasecmp.c strncasecmp.c strerror.c sys_siglist.c \
+ bcopy.c bzero.c bcmp.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
-OBJS=$(MOBJ) $(COBJS)
+OBJS=$(MOBJ) $(MOBJ1) $(COBJS)
all: $(OBJS) $(LIBC)
@@ -44,6 +48,9 @@ ar-target: $(OBJS)
$(MOBJ): $(MSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+$(MOBJ1): $(MSRC1)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+
$(OBJS): Makefile
clean:
diff --git a/libc/string/bcmp.c b/libc/string/bcmp.c
new file mode 100644
index 000000000..b3bec9034
--- /dev/null
+++ b/libc/string/bcmp.c
@@ -0,0 +1,13 @@
+/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+
+int bcmp(const __ptr_t dest, const __ptr_t src, size_t len)
+{
+ return memcmp(dest, src, len);
+}
+
diff --git a/libc/string/bcopy.c b/libc/string/bcopy.c
new file mode 100644
index 000000000..7f929db73
--- /dev/null
+++ b/libc/string/bcopy.c
@@ -0,0 +1,15 @@
+/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+
+void bcopy(const __ptr_t src, __ptr_t dest, size_t len)
+{
+/* (void) memcpy(dest, src, len); */
+ while (len--)
+ *(char *) (dest++) = *(char *) (src++);
+}
+
diff --git a/libc/string/bzero.c b/libc/string/bzero.c
new file mode 100644
index 000000000..f726032a8
--- /dev/null
+++ b/libc/string/bzero.c
@@ -0,0 +1,15 @@
+/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+
+void bzero(__ptr_t dest, size_t len)
+{
+ /* (void) memset(dest, '\0', len); */
+ while (len--)
+ *(char *) (dest++) = '\0';
+}
+
diff --git a/libc/string/strerror.c b/libc/string/strerror.c
new file mode 100644
index 000000000..6eeac104e
--- /dev/null
+++ b/libc/string/strerror.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+extern char *itoa(int);
+
+/* Return a string descibing the errno code in ERRNUM.
+ The storage is good only until the next call to strerror.
+ Writing to the storage causes undefined behavior. */
+char *strerror(int err)
+{
+ static char retbuf[80];
+
+ if (sys_nerr) {
+ if (err < 0 || err >= sys_nerr)
+ goto unknown;
+ return sys_errlist[err];
+ }
+
+ if (err <= 0)
+ goto unknown;
+
+ unknown:
+ printf("sys_nerr=%d\n", sys_nerr);
+ strcpy(retbuf, "Unknown Error: errno=");
+ strcat(retbuf, (char *) itoa(err));
+ return retbuf;
+}
diff --git a/libc/string/strsep.c b/libc/string/strsep.c
index 797807a91..797b74400 100644
--- a/libc/string/strsep.c
+++ b/libc/string/strsep.c
@@ -1,34 +1,65 @@
-/* Copyright (C) 1992, 1993 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+/* Copyright (C) 1992, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <string.h>
-char *strsep( char **pp, const char *delim)
+char * strsep( char **stringp, const char *delim)
{
- char *p, *q;
-
- if (!(p = *pp))
- return 0;
- if ((q = strpbrk(p, delim))) {
- *pp = q + 1;
- *q = '\0';
- } else
- *pp = 0;
- return p;
+ char *begin, *end;
+
+ begin = *stringp;
+ if (begin == NULL)
+ return NULL;
+
+ /* A frequent case is when the delimiter string contains only one
+ character. Here we don't need to call the expensive `strpbrk'
+ function and instead work using `strchr'. */
+ if (delim[0] == '\0' || delim[1] == '\0')
+ {
+ char ch = delim[0];
+
+ if (ch == '\0')
+ end = NULL;
+ else
+ {
+ if (*begin == ch)
+ end = begin;
+ else if (*begin == '\0')
+ end = NULL;
+ else
+ end = strchr (begin + 1, ch);
+ }
+ }
+ else
+ /* Find the end of the token. */
+ end = strpbrk (begin, delim);
+
+ if (end)
+ {
+ /* Terminate the token and set *STRINGP past NUL character. */
+ *end++ = '\0';
+ *stringp = end;
+ }
+ else
+ /* No more delimiters; this is the last token. */
+ *stringp = NULL;
+
+ return begin;
}
+