diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-11 23:54:37 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-11 23:54:37 +0000 |
commit | a99617fe8fdb56b3e877558bfd6572ce65ad39de (patch) | |
tree | 26c3182125188cb7681885830ea7e32e179c7565 | |
parent | d1c3ee2a075fc4e855e352e5a5cf10371f2e77aa (diff) |
Finish reorganizing things. At least I think I've finished.
31 files changed, 599 insertions, 52 deletions
@@ -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 diff --git a/include/stdlib.h b/include/stdlib.h index 08af451f0..581c8cce7 100644 --- a/include/stdlib.h +++ b/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 */ diff --git a/libc/inet/Makefile b/libc/inet/Makefile index 07d84d6eb..572263eb1 100644 --- a/libc/inet/Makefile +++ b/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 diff --git a/libc/inet/rpc/Makefile b/libc/inet/rpc/Makefile index cc6403648..a9a4717ac 100644 --- a/libc/inet/rpc/Makefile +++ b/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 diff --git a/libc/misc/Makefile b/libc/misc/Makefile index 03d2b2b40..30c92fcf8 100644 --- a/libc/misc/Makefile +++ b/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 diff --git a/libc/misc/internals/Makefile b/libc/misc/internals/Makefile new file mode 100644 index 000000000..eb4e61ac8 --- /dev/null +++ b/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 + diff --git a/libc/misc/internals/itoa.c b/libc/misc/internals/itoa.c new file mode 100644 index 000000000..a683b8018 --- /dev/null +++ b/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; +} diff --git a/libc/misc/internals/ltoa.c b/libc/misc/internals/ltoa.c new file mode 100644 index 000000000..da8b6d3df --- /dev/null +++ b/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; +} diff --git a/libc/misc/internals/ltostr.c b/libc/misc/internals/ltostr.c new file mode 100644 index 000000000..da6fad232 --- /dev/null +++ b/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; +} diff --git a/libc/misc/regex/Makefile b/libc/misc/regex/Makefile index 006ea75cc..7289186f7 100644 --- a/libc/misc/regex/Makefile +++ b/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 diff --git a/libc/misc/time/Makefile b/libc/misc/time/Makefile index e3c2c26d6..e5387a56a 100644 --- a/libc/misc/time/Makefile +++ b/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 diff --git a/libc/signal/Makefile b/libc/signal/Makefile new file mode 100644 index 000000000..ab2a996c5 --- /dev/null +++ b/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 + diff --git a/libc/signal/raise.c b/libc/signal/raise.c new file mode 100644 index 000000000..b666789b4 --- /dev/null +++ b/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); +} + diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile index fbd0bbf15..874dcae7f 100644 --- a/libc/stdio/Makefile +++ b/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) diff --git a/libc/stdio/perror.c b/libc/stdio/perror.c new file mode 100644 index 000000000..d6274c056 --- /dev/null +++ b/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); +} diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c new file mode 100644 index 000000000..a07c411eb --- /dev/null +++ b/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; +} diff --git a/libc/stdio/remove.c b/libc/stdio/remove.c new file mode 100644 index 000000000..115b871bb --- /dev/null +++ b/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; +} + diff --git a/libc/stdlib/Makefile b/libc/stdlib/Makefile index da402be6c..b4211ecf7 100644 --- a/libc/stdlib/Makefile +++ b/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 + + diff --git a/libc/stdlib/abs.c b/libc/stdlib/abs.c new file mode 100644 index 000000000..044a334b1 --- /dev/null +++ b/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; +} + diff --git a/libc/stdlib/malloc-simple/Makefile b/libc/stdlib/malloc-simple/Makefile index c2f8827b5..e46415536 100644 --- a/libc/stdlib/malloc-simple/Makefile +++ b/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 diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c index cf4835c97..f31105d4e 100644 --- a/libc/stdlib/malloc-simple/alloc.c +++ b/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; diff --git a/libc/stdlib/malloc/Makefile b/libc/stdlib/malloc/Makefile index fe3f8b424..0824e71a8 100644 --- a/libc/stdlib/malloc/Makefile +++ b/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 diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 1a0b61aa5..4ed9fe873 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/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; 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; } + diff --git a/libc/unistd/Makefile b/libc/unistd/Makefile new file mode 100644 index 000000000..1095e1a37 --- /dev/null +++ b/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 + diff --git a/test/string/string.c b/test/string/string.c index c59262717..2492755d0 100644 --- a/test/string/string.c +++ b/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,"); |