Browse Source

Finish reorganizing things. At least I think I've finished.

Eric Andersen 23 years ago
parent
commit
a99617fe8f

+ 9 - 4
Makefile

@@ -20,11 +20,16 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-#MALLOC = malloc
-MALLOC = malloc-simple
+#--------------------------------------------------------
+#
+#There are a number of configurable options in Rules.make
+#
+#--------------------------------------------------------
+
+
+
+DIRS = misc pwd_grp stdio string termios unistd net signal stdlib sysdeps
 
-DIRS = error getent $(MALLOC) misc regex stdio \
-	    string termios time sysdeps shm #rpc
 all: libc.a
 
 libc.a: halfclean headers subdirs

+ 3 - 0
include/stdlib.h

@@ -106,6 +106,9 @@ extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__));
 extern long int labs __P ((long int __x)) __attribute__ ((__const__));
 extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__));
 
+/* Generate a unique temporary file name from TEMPLATE. */
+extern char *mktemp __P ((char *__template));
+extern int mkstemp __P ((char *__template));
 
 
 #endif /* __STDLIB_H */

+ 18 - 3
libc/inet/Makefile

@@ -24,6 +24,8 @@ TOPDIR=../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 
+DIRS = #rpc
+
 MSRC=addr.c
 MOBJ=inet_aton.o inet_addr.o inet_ntoa.o
 
@@ -34,9 +36,11 @@ MOBJ2=encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \
 	opennameservers.o closenameservers.o resolvename.o gethostbyname.o\
 	gethostbyaddr.o
 OBJS=$(MOBJ) $(MOBJ2)
+
+
 all: $(OBJS) $(LIBC)
 
-$(LIBC): ar-target
+$(LIBC): ar-target subdirs
 
 ar-target: $(OBJS)
 	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
@@ -49,6 +53,17 @@ $(MOBJ2): $(MSRC2)
 
 $(OBJS): Makefile
 
-clean:
-	rm -f *.[oa] *~ core
+clean: subdirs_clean
+	rm -f libc.a
+
+subdirs: $(patsubst %, _dir_%, $(DIRS))
+subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS))
+
+$(patsubst %, _dir_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dir_%, %, $@)
+
+$(patsubst %, _dirclean_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
+
+.PHONY: dummy
 

+ 1 - 1
libc/inet/rpc/Makefile

@@ -20,7 +20,7 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-TOPDIR=../
+TOPDIR=../../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 CFLAGS+=-I$(TOPDIR)include/linux

+ 1 - 1
libc/misc/Makefile

@@ -21,7 +21,7 @@
 # respective copyright holders.
 
 
-DIRS = assert crypt ctype fnmatch glob lsearch
+DIRS = assert crypt ctype fnmatch glob internals lsearch regex shm time
 
 all: libc.a
 

+ 42 - 0
libc/misc/internals/Makefile

@@ -0,0 +1,42 @@
+# Makefile for uCLibc
+#
+# Copyright (C) 2000 by Lineo, inc.
+#
+# This program 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.
+#
+# This program 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 General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Derived in part from the Linux-8086 C library, the GNU C Library, and several
+# other sundry sources.  Files within this library are copyright by their
+# respective copyright holders.
+
+TOPDIR=../../
+include $(TOPDIR)Rules.make
+LIBC=$(TOPDIR)libc.a
+
+CSRC=itoa.c ltoa.c ltostr.c
+COBJS=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(COBJS)
+
+all: $(OBJS) $(LIBC)
+
+$(LIBC): ar-target
+
+ar-target: $(OBJS)
+	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
+
+$(OBJS): Makefile
+
+clean:
+	rm -f *.[oa] *~ core
+

+ 21 - 0
libc/misc/internals/itoa.c

@@ -0,0 +1,21 @@
+/* itoa.c <ndf@linux.mit.edu> */
+#define __MAX_INT_CHARS 7
+
+char *itoa(int i)
+{
+	static char a[__MAX_INT_CHARS];
+	char *b = a + sizeof(a) - 1;
+	int sign = (i < 0);
+
+	if (sign)
+		i = -i;
+	*b = 0;
+	do {
+		*--b = '0' + (i % 10);
+		i /= 10;
+	}
+	while (i);
+	if (sign)
+		*--b = '-';
+	return b;
+}

+ 40 - 0
libc/misc/internals/ltoa.c

@@ -0,0 +1,40 @@
+/* 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.
+ */
+
+static char buf[12];
+
+extern char *ultoa();
+
+char *ltoa(val)
+long val;
+{
+	char *p;
+	int flg = 0;
+
+	if (val < 0) {
+		flg++;
+		val = -val;
+	}
+	p = ultoa(val);
+	if (flg)
+		*--p = '-';
+	return p;
+}
+
+char *ultoa(val)
+unsigned long val;
+{
+	char *p;
+
+	p = buf + sizeof(buf);
+	*--p = '\0';
+
+	do {
+		*--p = '0' + val % 10;
+		val /= 10;
+	}
+	while (val);
+	return p;
+}

+ 52 - 0
libc/misc/internals/ltostr.c

@@ -0,0 +1,52 @@
+/* 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.
+ */
+
+static char buf[34];
+
+extern char *ultostr();
+
+char *ltostr(val, radix, uppercase)
+long val;
+int radix;
+int uppercase;
+{
+	char *p;
+	int flg = 0;
+
+	if (val < 0) {
+		flg++;
+		val = -val;
+	}
+	p = ultostr(val, radix, uppercase);
+	if (p && flg)
+		*--p = '-';
+	return p;
+}
+
+char *ultostr(val, radix, uppercase)
+unsigned long val;
+int radix;
+int uppercase;
+{
+	register char *p;
+	register int c;
+
+	if (radix > 36 || radix < 2)
+		return 0;
+
+	p = buf + sizeof(buf);
+	*--p = '\0';
+
+	do {
+		c = val % radix;
+		val /= radix;
+		if (c > 9)
+			*--p = (uppercase ? 'A' : 'a') - 10 + c;
+		else
+			*--p = '0' + c;
+	}
+	while (val);
+	return p;
+}

+ 1 - 1
libc/misc/regex/Makefile

@@ -20,7 +20,7 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-TOPDIR=../
+TOPDIR=../../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 

+ 1 - 1
libc/misc/time/Makefile

@@ -20,7 +20,7 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-TOPDIR=../
+TOPDIR=../../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 

+ 42 - 0
libc/signal/Makefile

@@ -0,0 +1,42 @@
+# Makefile for uCLibc
+#
+# Copyright (C) 2000 by Lineo, inc.
+#
+# This program 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.
+#
+# This program 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 General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Derived in part from the Linux-8086 C library, the GNU C Library, and several
+# other sundry sources.  Files within this library are copyright by their
+# respective copyright holders.
+
+TOPDIR=../
+include $(TOPDIR)Rules.make
+LIBC=$(TOPDIR)libc.a
+
+CSRC=raise.c
+COBJS=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(COBJS)
+
+all: $(OBJS) $(LIBC)
+
+$(LIBC): ar-target
+
+ar-target: $(OBJS)
+	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
+
+$(OBJS): Makefile
+
+clean:
+	rm -f *.[oa] *~ core
+

+ 15 - 0
libc/signal/raise.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 <signal.h>
+#include <sys/types.h>
+
+int raise(signo)
+int signo;
+{
+	return kill(getpid(), signo);
+}
+

+ 1 - 1
libc/stdio/Makefile

@@ -36,7 +36,7 @@ MOBJ2=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o snprintf.o vs
 MSRC3=scanf.c
 MOBJ3=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o
 
-CSRC=dputs.c
+CSRC=dputs.c popen.c perror.c remove.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
 

+ 19 - 0
libc/stdio/perror.c

@@ -0,0 +1,19 @@
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+void perror(str)
+__const char *str;
+{
+	register char *ptr;
+
+	if (str) {
+		write(2, str, strlen(str));
+		write(2, ": ", 2);
+	} else
+		write(2, "perror: ", 8);
+
+	ptr = strerror(errno);
+	write(2, ptr, strlen(ptr));
+	write(2, "\n", 1);
+}

+ 49 - 0
libc/stdio/popen.c

@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+
+FILE *popen(command, rw)
+char *command;
+char *rw;
+{
+	int pipe_fd[2];
+	int pid, reading;
+
+	if (pipe(pipe_fd) < 0)
+		return NULL;
+	reading = (rw[0] == 'r');
+
+	pid = vfork();
+	if (pid < 0) {
+		close(pipe_fd[0]);
+		close(pipe_fd[1]);
+		return NULL;
+	}
+	if (pid == 0) {
+		close(pipe_fd[!reading]);
+		close(reading);
+		if (pipe_fd[reading] != reading) {
+			dup2(pipe_fd[reading], reading);
+			close(pipe_fd[reading]);
+		}
+
+		execl("/bin/sh", "sh", "-c", command, (char *) 0);
+		_exit(255);
+	}
+
+	close(pipe_fd[reading]);
+	return fdopen(pipe_fd[!reading], rw);
+}
+
+int pclose(fd)
+FILE *fd;
+{
+	int waitstat;
+
+	if (fclose(fd) != 0)
+		return EOF;
+	wait(&waitstat);
+	return waitstat;
+}

+ 23 - 0
libc/stdio/remove.c

@@ -0,0 +1,23 @@
+/* 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>
+#include <errno.h>
+
+int remove(src)
+__const char *src;
+{
+	extern int errno;
+	int er = errno;
+	int rv = unlink(src);
+
+	if (rv < 0 && errno == EISDIR)
+		rv = rmdir(src);
+	if (rv >= 0)
+		errno = er;
+	return rv;
+}
+

+ 18 - 7
libc/stdlib/Makefile

@@ -24,23 +24,22 @@ TOPDIR=../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 
-MSRC=aliases.c
-MOBJ=abs.o remove.o creat.o bcopy.o bzero.o # raise.o bcmp.o index.o rindex.o 
+DIRS = $(MALLOC)
+
 
 MSRC2=atexit.c
 MOBJ2=on_exit.o atexit.o __do_exit.o exit.o
 
-CSRC=atoi.c atol.c ltoa.c ltostr.c ctype.c qsort.c bsearch.c rand.c lsearch.c \
-	getopt.c glob.c fnmatch.c itoa.c strtod.c strtol.c crypt.c sleep.c \
-	mkstemp.c  mktemp.c realpath.c getenv.c putenv.c popen.c system.c \
-	getcwd.c setenv.c execl.c execv.c execlp.c execvp.c execvep.c
+
+CSRC =	abort.c getenv.c  mktemp.c  qsort.c  realpath.c strtod.c strtoul.c \
+	abs.c   bsearch.c mkstemp.c putenv.c rand.c setenv.c strtol.c system.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 OBJS=$(MOBJ) $(MOBJ2) $(COBJS)
 
 
 all: $(OBJS) $(LIBC)
 
-$(LIBC): ar-target
+$(LIBC): ar-target subdirs
 
 ar-target: $(OBJS)
 	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
@@ -53,6 +52,18 @@ $(MOBJ2): $(MSRC2)
 
 $(OBJ): Makefile
 
+subdirs: $(patsubst %, _dir_%, $(DIRS))
+subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS))
+
+$(patsubst %, _dir_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dir_%, %, $@)
+
+$(patsubst %, _dirclean_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
+
 clean:
 	rm -f *.[oa] *~ core
 
+.PHONY: dummy
+
+

+ 13 - 0
libc/stdlib/abs.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 abs(int arg1)
+{
+	return arg1 > 0 ? arg1 : -arg1;
+}
+

+ 1 - 1
libc/stdlib/malloc-simple/Makefile

@@ -20,7 +20,7 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-TOPDIR=../
+TOPDIR=../../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 

+ 6 - 2
libc/stdlib/malloc-simple/alloc.c

@@ -67,8 +67,12 @@ void *calloc(size_t num, size_t size)
 void *malloc(size_t len)
 {
 	void *result = mmap((void *) 0, len, PROT_READ | PROT_WRITE,
-						//MAP_SHARED | MAP_ANONYMOUS, 0, 0);
-						MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+#ifdef __HAS_NO_MMU__
+						MAP_SHARED | MAP_ANONYMOUS, 0, 0
+#else
+						MAP_PRIVATE | MAP_ANONYMOUS, 0, 0
+#endif
+						    );
 
 	if (result == (void *) -1)
 		return 0;

+ 1 - 1
libc/stdlib/malloc/Makefile

@@ -20,7 +20,7 @@
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 
-TOPDIR=../
+TOPDIR=../../
 include $(TOPDIR)Rules.make
 LIBC=$(TOPDIR)libc.a
 

+ 7 - 1
libc/stdlib/malloc/malloc.c

@@ -190,7 +190,13 @@ static void *hunk_alloc(int size)
   if ((p = free_h[size]) == NULL)
   {
     if ((p = (Hunk_t*)mmap(HUNK_MSTART,HUNK_MSIZE,PROT_READ|PROT_WRITE,
-	MAP_PRIVATE|MAP_ANON,0,0)) == (Hunk_t*)MAP_FAILED)
+#ifdef __HAS_NO_MMU__
+	MAP_PRIVATE|MAP_ANONYMOUS
+#else
+
+	MAP_SHARED|MAP_ANONYMOUS
+#endif
+	,0,0)) == (Hunk_t*)MAP_FAILED)
       return NULL;
     memset(p,0,HUNK_MSIZE);
     p->id = HUNK_ID;

+ 10 - 3
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:

+ 13 - 0
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);
+}
+

+ 15 - 0
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++);
+}
+

+ 15 - 0
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';
+}
+

+ 46 - 0
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;
+}

+ 56 - 25
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;
 }
+

+ 53 - 0
libc/unistd/Makefile

@@ -0,0 +1,53 @@
+# Makefile for uCLibc
+#
+# Copyright (C) 2000 by Lineo, inc.
+#
+# This program 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.
+#
+# This program 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 General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Derived in part from the Linux-8086 C library, the GNU C Library, and several
+# other sundry sources.  Files within this library are copyright by their
+# respective copyright holders.
+
+TOPDIR=../
+include $(TOPDIR)Rules.make
+LIBC=$(TOPDIR)libc.a
+
+
+CSRC=execl.c execlp.c execv.c execvep.c execvp.c getcwd.c getopt.c sleep.c
+COBJS=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(COBJS)
+
+
+all: $(OBJS) $(LIBC)
+
+$(LIBC): ar-target subdirs
+
+ar-target: $(OBJS)
+	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
+
+$(OBJ): Makefile
+
+subdirs: $(patsubst %, _dir_%, $(DIRS))
+subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS))
+
+$(patsubst %, _dir_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dir_%, %, $@)
+
+$(patsubst %, _dirclean_%, $(DIRS)) : dummy
+	$(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
+
+clean:
+	rm -f *.[oa] *~ core
+

+ 7 - 0
test/string/string.c

@@ -580,14 +580,21 @@ test_strsep (void)
   equal(one+2, "b", 49);
   equal(one+4, "c", 50);
 
+printf( "A\n");
   {
     char text[] = "This,is,a,test";
     char *list = strdup (text);
+printf( "B\n");
     equal (strsep (&list, ","), "This", 51);
+printf( "C\n");
     equal (strsep (&list, ","), "is", 52);
+printf( "D\n");
     equal (strsep (&list, ","), "a", 53);
+printf( "E\n");
     equal (strsep (&list, ","), "test", 54);
+printf( "F\n");
     check (strsep (&list, ",") == NULL, 55);
+printf( "G\n");
   }
 
   cp = strcpy(one, "a,b, c,, ,d,");