From 02fec4701cee79f875c1d02b8b4aee09380dbcb8 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Thu, 4 Jan 2001 20:04:45 +0000 Subject: integrate dietlibc/stdio per default for cdrom and disk only installs --- mdk-stage1/dietlibc/lib/__dtostr.c | 82 +++++++++++ mdk-stage1/dietlibc/lib/__lltostr.c | 34 +++++ mdk-stage1/dietlibc/lib/__ltostr.c | 34 +++++ mdk-stage1/dietlibc/lib/__xmknod.c | 6 + mdk-stage1/dietlibc/lib/_brk.c | 14 ++ mdk-stage1/dietlibc/lib/abort.c | 14 ++ mdk-stage1/dietlibc/lib/accept.c | 14 ++ mdk-stage1/dietlibc/lib/alarm.c | 47 ++++++ mdk-stage1/dietlibc/lib/alloc.c | 217 ++++++++++++++++++++++++++++ mdk-stage1/dietlibc/lib/assert_fail.c | 27 ++++ mdk-stage1/dietlibc/lib/atexit.c | 23 +++ mdk-stage1/dietlibc/lib/atof.c | 5 + mdk-stage1/dietlibc/lib/atoi.c | 8 + mdk-stage1/dietlibc/lib/atol.c | 8 + mdk-stage1/dietlibc/lib/bind.c | 12 ++ mdk-stage1/dietlibc/lib/cfgetospeed.c | 6 + mdk-stage1/dietlibc/lib/closedir.c | 28 ++++ mdk-stage1/dietlibc/lib/connect.c | 14 ++ mdk-stage1/dietlibc/lib/creat64.c | 5 + mdk-stage1/dietlibc/lib/errlist.c | 132 +++++++++++++++++ mdk-stage1/dietlibc/lib/errno_location.c | 5 + mdk-stage1/dietlibc/lib/execl.c | 24 +++ mdk-stage1/dietlibc/lib/execvp.c | 55 +++++++ mdk-stage1/dietlibc/lib/ftw.c | 52 +++++++ mdk-stage1/dietlibc/lib/getdomainname.c | 17 +++ mdk-stage1/dietlibc/lib/getenv.c | 17 +++ mdk-stage1/dietlibc/lib/gethostname.c | 18 +++ mdk-stage1/dietlibc/lib/getpeername.c | 13 ++ mdk-stage1/dietlibc/lib/getservent.c | 141 ++++++++++++++++++ mdk-stage1/dietlibc/lib/getsockname.c | 13 ++ mdk-stage1/dietlibc/lib/getsockopt.c | 13 ++ mdk-stage1/dietlibc/lib/htons.c | 12 ++ mdk-stage1/dietlibc/lib/if_indextoname.c | 29 ++++ mdk-stage1/dietlibc/lib/if_nametoindex.c | 27 ++++ mdk-stage1/dietlibc/lib/isalnum.c | 6 + mdk-stage1/dietlibc/lib/isalpha.c | 6 + mdk-stage1/dietlibc/lib/isascii.c | 6 + mdk-stage1/dietlibc/lib/isatty.c | 20 +++ mdk-stage1/dietlibc/lib/isblank.c | 6 + mdk-stage1/dietlibc/lib/isdigit.c | 6 + mdk-stage1/dietlibc/lib/isspace.c | 6 + mdk-stage1/dietlibc/lib/listen.c | 13 ++ mdk-stage1/dietlibc/lib/lockf.c | 37 +++++ mdk-stage1/dietlibc/lib/longjmp.c | 51 +++++++ mdk-stage1/dietlibc/lib/memccmp.c | 17 +++ mdk-stage1/dietlibc/lib/memccpy.c | 19 +++ mdk-stage1/dietlibc/lib/memchr.c | 9 ++ mdk-stage1/dietlibc/lib/memcmp.c | 14 ++ mdk-stage1/dietlibc/lib/memcpy.c | 12 ++ mdk-stage1/dietlibc/lib/memmove.c | 23 +++ mdk-stage1/dietlibc/lib/memset.c | 9 ++ mdk-stage1/dietlibc/lib/mkfifo.c | 6 + mdk-stage1/dietlibc/lib/nop.c | 7 + mdk-stage1/dietlibc/lib/open64.c | 11 ++ mdk-stage1/dietlibc/lib/opendir.c | 63 ++++++++ mdk-stage1/dietlibc/lib/perror.c | 16 ++ mdk-stage1/dietlibc/lib/pread.c | 10 ++ mdk-stage1/dietlibc/lib/pread64.c | 13 ++ mdk-stage1/dietlibc/lib/putenv.c | 37 +++++ mdk-stage1/dietlibc/lib/puts.c | 6 + mdk-stage1/dietlibc/lib/raise.c | 8 + mdk-stage1/dietlibc/lib/readdir.c | 83 +++++++++++ mdk-stage1/dietlibc/lib/recv.c | 13 ++ mdk-stage1/dietlibc/lib/recvfrom.c | 12 ++ mdk-stage1/dietlibc/lib/rewind.c | 6 + mdk-stage1/dietlibc/lib/rewinddir.c | 17 +++ mdk-stage1/dietlibc/lib/sbrk.c | 20 +++ mdk-stage1/dietlibc/lib/seekdir.c | 15 ++ mdk-stage1/dietlibc/lib/send.c | 13 ++ mdk-stage1/dietlibc/lib/sendto.c | 13 ++ mdk-stage1/dietlibc/lib/set_errno.c | 9 ++ mdk-stage1/dietlibc/lib/setsockopt.c | 13 ++ mdk-stage1/dietlibc/lib/sigaddset.c | 21 +++ mdk-stage1/dietlibc/lib/sigemptyset.c | 14 ++ mdk-stage1/dietlibc/lib/sigjmp.c | 36 +++++ mdk-stage1/dietlibc/lib/sleep.c | 11 ++ mdk-stage1/dietlibc/lib/snprintf.c | 14 ++ mdk-stage1/dietlibc/lib/socket.c | 12 ++ mdk-stage1/dietlibc/lib/sprintf.c | 15 ++ mdk-stage1/dietlibc/lib/sscanf.c | 13 ++ mdk-stage1/dietlibc/lib/strcat.c | 18 +++ mdk-stage1/dietlibc/lib/strchr.c | 16 ++ mdk-stage1/dietlibc/lib/strcmp.c | 16 ++ mdk-stage1/dietlibc/lib/strcpy.c | 15 ++ mdk-stage1/dietlibc/lib/strcspn.c | 17 +++ mdk-stage1/dietlibc/lib/strdup.c | 9 ++ mdk-stage1/dietlibc/lib/strerror.c | 10 ++ mdk-stage1/dietlibc/lib/strlcat.c | 72 +++++++++ mdk-stage1/dietlibc/lib/strlcpy.c | 68 +++++++++ mdk-stage1/dietlibc/lib/strlen.c | 47 ++++++ mdk-stage1/dietlibc/lib/strncat.c | 19 +++ mdk-stage1/dietlibc/lib/strncmp.c | 6 + mdk-stage1/dietlibc/lib/strncpy.c | 10 ++ mdk-stage1/dietlibc/lib/strpbrk.c | 11 ++ mdk-stage1/dietlibc/lib/strrchr.c | 18 +++ mdk-stage1/dietlibc/lib/strspn.c | 17 +++ mdk-stage1/dietlibc/lib/strstr.c | 15 ++ mdk-stage1/dietlibc/lib/strtod.c | 52 +++++++ mdk-stage1/dietlibc/lib/strtok.c | 6 + mdk-stage1/dietlibc/lib/strtok_r.c | 21 +++ mdk-stage1/dietlibc/lib/strtol.c | 15 ++ mdk-stage1/dietlibc/lib/strtoll.c | 15 ++ mdk-stage1/dietlibc/lib/strtoul.c | 39 +++++ mdk-stage1/dietlibc/lib/strtoull.c | 39 +++++ mdk-stage1/dietlibc/lib/sys_siglist.c | 37 +++++ mdk-stage1/dietlibc/lib/tcgetattr.c | 7 + mdk-stage1/dietlibc/lib/tcsetattr.c | 23 +++ mdk-stage1/dietlibc/lib/telldir.c | 38 +++++ mdk-stage1/dietlibc/lib/ttyname.c | 59 ++++++++ mdk-stage1/dietlibc/lib/vfork.c | 6 + mdk-stage1/dietlibc/lib/vfprintf.c | 15 ++ mdk-stage1/dietlibc/lib/vprintf.c | 20 +++ mdk-stage1/dietlibc/lib/vsnprintf.c | 239 ++++++++++++++++++++++++++++++ mdk-stage1/dietlibc/lib/vsprintf.c | 11 ++ mdk-stage1/dietlibc/lib/vsscanf.c | 241 +++++++++++++++++++++++++++++++ mdk-stage1/dietlibc/lib/wait.c | 6 + mdk-stage1/dietlibc/lib/wait3.c | 5 + 117 files changed, 3231 insertions(+) create mode 100644 mdk-stage1/dietlibc/lib/__dtostr.c create mode 100644 mdk-stage1/dietlibc/lib/__lltostr.c create mode 100644 mdk-stage1/dietlibc/lib/__ltostr.c create mode 100644 mdk-stage1/dietlibc/lib/__xmknod.c create mode 100644 mdk-stage1/dietlibc/lib/_brk.c create mode 100644 mdk-stage1/dietlibc/lib/abort.c create mode 100644 mdk-stage1/dietlibc/lib/accept.c create mode 100644 mdk-stage1/dietlibc/lib/alarm.c create mode 100644 mdk-stage1/dietlibc/lib/alloc.c create mode 100644 mdk-stage1/dietlibc/lib/assert_fail.c create mode 100644 mdk-stage1/dietlibc/lib/atexit.c create mode 100644 mdk-stage1/dietlibc/lib/atof.c create mode 100644 mdk-stage1/dietlibc/lib/atoi.c create mode 100644 mdk-stage1/dietlibc/lib/atol.c create mode 100644 mdk-stage1/dietlibc/lib/bind.c create mode 100644 mdk-stage1/dietlibc/lib/cfgetospeed.c create mode 100644 mdk-stage1/dietlibc/lib/closedir.c create mode 100644 mdk-stage1/dietlibc/lib/connect.c create mode 100644 mdk-stage1/dietlibc/lib/creat64.c create mode 100644 mdk-stage1/dietlibc/lib/errlist.c create mode 100644 mdk-stage1/dietlibc/lib/errno_location.c create mode 100644 mdk-stage1/dietlibc/lib/execl.c create mode 100644 mdk-stage1/dietlibc/lib/execvp.c create mode 100644 mdk-stage1/dietlibc/lib/ftw.c create mode 100644 mdk-stage1/dietlibc/lib/getdomainname.c create mode 100644 mdk-stage1/dietlibc/lib/getenv.c create mode 100644 mdk-stage1/dietlibc/lib/gethostname.c create mode 100644 mdk-stage1/dietlibc/lib/getpeername.c create mode 100644 mdk-stage1/dietlibc/lib/getservent.c create mode 100644 mdk-stage1/dietlibc/lib/getsockname.c create mode 100644 mdk-stage1/dietlibc/lib/getsockopt.c create mode 100644 mdk-stage1/dietlibc/lib/htons.c create mode 100644 mdk-stage1/dietlibc/lib/if_indextoname.c create mode 100644 mdk-stage1/dietlibc/lib/if_nametoindex.c create mode 100644 mdk-stage1/dietlibc/lib/isalnum.c create mode 100644 mdk-stage1/dietlibc/lib/isalpha.c create mode 100644 mdk-stage1/dietlibc/lib/isascii.c create mode 100644 mdk-stage1/dietlibc/lib/isatty.c create mode 100644 mdk-stage1/dietlibc/lib/isblank.c create mode 100644 mdk-stage1/dietlibc/lib/isdigit.c create mode 100644 mdk-stage1/dietlibc/lib/isspace.c create mode 100644 mdk-stage1/dietlibc/lib/listen.c create mode 100644 mdk-stage1/dietlibc/lib/lockf.c create mode 100644 mdk-stage1/dietlibc/lib/longjmp.c create mode 100644 mdk-stage1/dietlibc/lib/memccmp.c create mode 100644 mdk-stage1/dietlibc/lib/memccpy.c create mode 100644 mdk-stage1/dietlibc/lib/memchr.c create mode 100644 mdk-stage1/dietlibc/lib/memcmp.c create mode 100644 mdk-stage1/dietlibc/lib/memcpy.c create mode 100644 mdk-stage1/dietlibc/lib/memmove.c create mode 100644 mdk-stage1/dietlibc/lib/memset.c create mode 100644 mdk-stage1/dietlibc/lib/mkfifo.c create mode 100644 mdk-stage1/dietlibc/lib/nop.c create mode 100644 mdk-stage1/dietlibc/lib/open64.c create mode 100644 mdk-stage1/dietlibc/lib/opendir.c create mode 100644 mdk-stage1/dietlibc/lib/perror.c create mode 100644 mdk-stage1/dietlibc/lib/pread.c create mode 100644 mdk-stage1/dietlibc/lib/pread64.c create mode 100644 mdk-stage1/dietlibc/lib/putenv.c create mode 100644 mdk-stage1/dietlibc/lib/puts.c create mode 100644 mdk-stage1/dietlibc/lib/raise.c create mode 100644 mdk-stage1/dietlibc/lib/readdir.c create mode 100644 mdk-stage1/dietlibc/lib/recv.c create mode 100644 mdk-stage1/dietlibc/lib/recvfrom.c create mode 100644 mdk-stage1/dietlibc/lib/rewind.c create mode 100644 mdk-stage1/dietlibc/lib/rewinddir.c create mode 100644 mdk-stage1/dietlibc/lib/sbrk.c create mode 100644 mdk-stage1/dietlibc/lib/seekdir.c create mode 100644 mdk-stage1/dietlibc/lib/send.c create mode 100644 mdk-stage1/dietlibc/lib/sendto.c create mode 100644 mdk-stage1/dietlibc/lib/set_errno.c create mode 100644 mdk-stage1/dietlibc/lib/setsockopt.c create mode 100644 mdk-stage1/dietlibc/lib/sigaddset.c create mode 100644 mdk-stage1/dietlibc/lib/sigemptyset.c create mode 100644 mdk-stage1/dietlibc/lib/sigjmp.c create mode 100644 mdk-stage1/dietlibc/lib/sleep.c create mode 100644 mdk-stage1/dietlibc/lib/snprintf.c create mode 100644 mdk-stage1/dietlibc/lib/socket.c create mode 100644 mdk-stage1/dietlibc/lib/sprintf.c create mode 100644 mdk-stage1/dietlibc/lib/sscanf.c create mode 100644 mdk-stage1/dietlibc/lib/strcat.c create mode 100644 mdk-stage1/dietlibc/lib/strchr.c create mode 100644 mdk-stage1/dietlibc/lib/strcmp.c create mode 100644 mdk-stage1/dietlibc/lib/strcpy.c create mode 100644 mdk-stage1/dietlibc/lib/strcspn.c create mode 100644 mdk-stage1/dietlibc/lib/strdup.c create mode 100644 mdk-stage1/dietlibc/lib/strerror.c create mode 100644 mdk-stage1/dietlibc/lib/strlcat.c create mode 100644 mdk-stage1/dietlibc/lib/strlcpy.c create mode 100644 mdk-stage1/dietlibc/lib/strlen.c create mode 100644 mdk-stage1/dietlibc/lib/strncat.c create mode 100644 mdk-stage1/dietlibc/lib/strncmp.c create mode 100644 mdk-stage1/dietlibc/lib/strncpy.c create mode 100644 mdk-stage1/dietlibc/lib/strpbrk.c create mode 100644 mdk-stage1/dietlibc/lib/strrchr.c create mode 100644 mdk-stage1/dietlibc/lib/strspn.c create mode 100644 mdk-stage1/dietlibc/lib/strstr.c create mode 100644 mdk-stage1/dietlibc/lib/strtod.c create mode 100644 mdk-stage1/dietlibc/lib/strtok.c create mode 100644 mdk-stage1/dietlibc/lib/strtok_r.c create mode 100644 mdk-stage1/dietlibc/lib/strtol.c create mode 100644 mdk-stage1/dietlibc/lib/strtoll.c create mode 100644 mdk-stage1/dietlibc/lib/strtoul.c create mode 100644 mdk-stage1/dietlibc/lib/strtoull.c create mode 100644 mdk-stage1/dietlibc/lib/sys_siglist.c create mode 100644 mdk-stage1/dietlibc/lib/tcgetattr.c create mode 100644 mdk-stage1/dietlibc/lib/tcsetattr.c create mode 100644 mdk-stage1/dietlibc/lib/telldir.c create mode 100644 mdk-stage1/dietlibc/lib/ttyname.c create mode 100644 mdk-stage1/dietlibc/lib/vfork.c create mode 100644 mdk-stage1/dietlibc/lib/vfprintf.c create mode 100644 mdk-stage1/dietlibc/lib/vprintf.c create mode 100644 mdk-stage1/dietlibc/lib/vsnprintf.c create mode 100644 mdk-stage1/dietlibc/lib/vsprintf.c create mode 100644 mdk-stage1/dietlibc/lib/vsscanf.c create mode 100644 mdk-stage1/dietlibc/lib/wait.c create mode 100644 mdk-stage1/dietlibc/lib/wait3.c (limited to 'mdk-stage1/dietlibc/lib') diff --git a/mdk-stage1/dietlibc/lib/__dtostr.c b/mdk-stage1/dietlibc/lib/__dtostr.c new file mode 100644 index 000000000..def091f16 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__dtostr.c @@ -0,0 +1,82 @@ +/* convert double to string. Helper for sprintf. */ + +int __dtostr(double d,char *buf,int maxlen,int prec) { + unsigned long long *x=(unsigned long long *)&d; + /* step 1: extract sign, mantissa and exponent */ + signed int s=*x>>63; + signed long e=((*x>>52)&((1<<11)-1))-1023; +/* unsigned long long m=*x & ((1ull<<52)-1); */ + /* step 2: exponent is base 2, compute exponent for base 10 */ + signed long e10=1+(long)(e*0.30102999566398119802); /* log10(2) */ + /* step 3: calculate 10^e10 */ + int i; + double tmp=10.0; + char *oldbuf=buf; + int initial=1; + + if (s) { d=-d; *buf='-'; --maxlen; buf++; } + if ((i=e10)>=0) { + while (i>10) { tmp=tmp*1e10; i-=10; } + while (i>1) { tmp=tmp*10; --i; } + } else { + i=(e10=-e10); + while (i>10) { tmp=tmp*1e-10; i-=10; } + while (i>1) { tmp=tmp/10; --i; } + } + while (d/tmp<1) { + --e10; + tmp/=10.0; + } + /* step 4: see if precision is sufficient to display all digits */ + if (e10>prec) { + /* use scientific notation */ + int len=__dtostr(d/tmp,buf,maxlen,prec); + if (len==0) return 0; + maxlen-=len; buf+=len; + if (--maxlen>=0) { + *buf='e'; + ++buf; + } + for (len=1000; len>0; len/=10) { + if (e10>=len || !initial) { + if (--maxlen>=0) { + *buf=(e10/len)+'0'; + ++buf; + } + initial=0; + e10=e10%len; + } + } + if (maxlen>=0) return buf-oldbuf; + return 0; + } + /* step 5: loop through the digits, inserting the decimal point when + * appropriate */ + for (; prec>0; ) { + double tmp2=d/tmp; + char c; + d-=((int)tmp2*tmp); + c=((int)tmp2); + if ((!initial)||c) { + if (--maxlen>=0) { + initial=0; + *buf=c+'0'; + ++buf; + } else + return 0; + --prec; + } + if (tmp>0.5 && tmp<1.5) { + tmp=1e-1; + initial=0; + if (--maxlen>=0) { + *buf='.'; + ++buf; + } else + return 0; + } else + tmp/=10.0; + } + *buf=0; + return buf-oldbuf; +} diff --git a/mdk-stage1/dietlibc/lib/__lltostr.c b/mdk-stage1/dietlibc/lib/__lltostr.c new file mode 100644 index 000000000..f53dcfb80 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__lltostr.c @@ -0,0 +1,34 @@ +#include + +static char *num="0123456789abcdefghijklmnopqrstuvwxyz"; + +int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase) +{ + char *tmp; + int j=0; + + s[--size]=0; + + tmp=s+size; + + if ((base==0)||(base>36)) base=10; + + j=0; + if (!i) + { + *(--tmp)='0'; + j=1; + } + + while((tmp>s)&&(i)) + { + tmp--; + *tmp=num[i%base]; + if ((UpCase)&&(*tmp>96)) (*tmp)-=' '; + i=i/base; + j++; + } + memmove(s,tmp,j+1); + + return j; +} diff --git a/mdk-stage1/dietlibc/lib/__ltostr.c b/mdk-stage1/dietlibc/lib/__ltostr.c new file mode 100644 index 000000000..b2ebeb074 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__ltostr.c @@ -0,0 +1,34 @@ +#include + +static char *num="0123456789abcdefghijklmnopqrstuvwxyz"; + +int __ltostr(char *s, int size, unsigned long i, int base, char UpCase) +{ + char *tmp; + int j=0; + + s[--size]=0; + + tmp=s+size; + + if ((base==0)||(base>36)) base=10; + + j=0; + if (!i) + { + *(--tmp)='0'; + j=1; + } + + while((tmp>s)&&(i)) + { + tmp--; + *tmp=num[i%base]; + if ((UpCase)&&(*tmp>96)) (*tmp)-=' '; + i=i/base; + j++; + } + memmove(s,tmp,j+1); + + return j; +} diff --git a/mdk-stage1/dietlibc/lib/__xmknod.c b/mdk-stage1/dietlibc/lib/__xmknod.c new file mode 100644 index 000000000..4739a1f5f --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__xmknod.c @@ -0,0 +1,6 @@ +#include + +int __xmknod(int ver,char* filename,mode_t mode,dev_t *dev) { + return mknod(filename,mode,*dev); +} + diff --git a/mdk-stage1/dietlibc/lib/_brk.c b/mdk-stage1/dietlibc/lib/_brk.c new file mode 100644 index 000000000..6d0b29c03 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/_brk.c @@ -0,0 +1,14 @@ +#include + +extern int __diet_brk(void *end_data_segment); + +void* __curbrk=0; + +int __brk(void *end_data_segment) { + int res; + if ((res=__diet_brk(end_data_segment))==0) + __curbrk=end_data_segment; + return res; +} + +int brk (void *end_data_segment) __attribute__((weak,alias("__brk"))); diff --git a/mdk-stage1/dietlibc/lib/abort.c b/mdk-stage1/dietlibc/lib/abort.c new file mode 100644 index 000000000..e6374c5ac --- /dev/null +++ b/mdk-stage1/dietlibc/lib/abort.c @@ -0,0 +1,14 @@ +#include +#include +#include + +extern int exit(int code) __attribute__ ((noreturn)); + +void abort() { + sigset_t t; + if (!sigemptyset(&t) && !sigaddset(&t, SIGABRT)) + sigprocmask(SIG_UNBLOCK, &t, 0); + while (1) + if (raise(SIGABRT)) + exit(127); +} diff --git a/mdk-stage1/dietlibc/lib/accept.c b/mdk-stage1/dietlibc/lib/accept.c new file mode 100644 index 000000000..a7ae824eb --- /dev/null +++ b/mdk-stage1/dietlibc/lib/accept.c @@ -0,0 +1,14 @@ +#include + +extern int socketcall(int callno,long* args); + +int accept(int a, void * addr, void * addr2) { +#ifdef __i386__ + return socketcall(SYS_ACCEPT, (long*)&a); +#else + unsigned long args[] = { a, (long) addr, (long) addr2 }; + return socketcall(SYS_ACCEPT, args); +#endif +} + +int __libc_accept(int a, void * addr, void * addr2) __attribute__((weak,alias("accept"))); diff --git a/mdk-stage1/dietlibc/lib/alarm.c b/mdk-stage1/dietlibc/lib/alarm.c new file mode 100644 index 000000000..fd35372f2 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/alarm.c @@ -0,0 +1,47 @@ +/* Copyright (C) 1991, 1992, 1994, 1997 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include + +/* Schedule an alarm. In SECONDS seconds, the process will get a SIGALRM. + If SECONDS is zero, any currently scheduled alarm will be cancelled. + The function returns the number of seconds remaining until the last + alarm scheduled would have signaled, or zero if there wasn't one. + There is no return value to indicate an error, but you can set `errno' + to 0 and check its value after calling `alarm', and this might tell you. + The signal may come late due to processor scheduling. */ +unsigned int +alarm (seconds) + unsigned int seconds; +{ + struct itimerval old, new; + unsigned int retval; + + new.it_interval.tv_usec = 0; + new.it_interval.tv_sec = 0; + new.it_value.tv_usec = 0; + new.it_value.tv_sec = (long int) seconds; + if (setitimer (ITIMER_REAL, &new, &old) < 0) + return 0; + + retval = old.it_value.tv_sec; + if (old.it_value.tv_usec) + ++retval; + return retval; +} diff --git a/mdk-stage1/dietlibc/lib/alloc.c b/mdk-stage1/dietlibc/lib/alloc.c new file mode 100644 index 000000000..7e3bedc74 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/alloc.c @@ -0,0 +1,217 @@ +/* + * malloc/free by O.Dreesen + */ + +#include +#include +#include + +#if 0 +#include +#define _LIBC +#include +#endif + +#include + +#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) +#define MAP_ANON MAP_ANONYMOUS +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void*)-1) +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +extern void * mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset); +extern void *memset(void *s, int c, size_t n); +extern void *memcpy(void *dest, const void *src, size_t n); + +typedef struct t_alloc_head { + struct t_alloc_head *ptr; + unsigned long size; +} alloc_head; + +/* guess what ? the virtual block size */ +#define MEM_BLOCK_SIZE 4096 + +/* minimum allocated bytes */ +#define MEM_ALLOC_MIN 4 + +/* Initial start position in memory */ +#define MEM_ALLOC_START ((char*)0x18000000) + +/* Make every block align */ +#define MEM_ALIGN(s) (((s)+MEM_ALLOC_MIN-1)&(~(MEM_ALLOC_MIN-1))) +#define PAGE_ALIGN(s) (((s)+MEM_BLOCK_SIZE-1)&(~(MEM_BLOCK_SIZE-1))) +#define PAGE_ALIGNP(p) ((char*)PAGE_ALIGN((size_t)(p))) + +#define END_OF_BLOCK(p) ((alloc_head*)(((char*)(p))+((p)->size))) +#define START_BLOCK(p) ((alloc_head*)(((char*)(p))-sizeof(alloc_head))) +#define START_DATA(p) (((char*)(p))+sizeof(alloc_head)) +#define MIN_ALLOC(s) (((((s)+sizeof(alloc_head)-1)/MEM_ALLOC_MIN)+1)*MEM_ALLOC_MIN) + +/* freelist handler */ +static alloc_head base = {&base,0}; +static char *alloc_get_end = MEM_ALLOC_START; + +void free(void *ptr) +{ + alloc_head *prev,*p,*block; + + if (ptr==NULL) return; + + block=START_BLOCK(ptr); + prev=&base; + for (p=prev->ptr ; ; prev=p, p=p->ptr) + { + if ((block>prev)&&(blockp)&&(blockp)&&(block>prev)) break; /* block after freelist */ + + /* emergency escape: freelist has ONLY one entry the freelist base */ + if (p->ptr==p) break; + } + prev->ptr = block; + + if (END_OF_BLOCK(block)==p) + { /* join right neighbor */ + block->ptr = p->ptr; + block->size += p->size; + } + else + block->ptr = p; + + if (END_OF_BLOCK(prev)==block) + { /* join left neighbor */ + prev->size += block->size; + prev->ptr = block->ptr; + } +} + +static void *alloc_get_mem(unsigned long size) +{ + char *tmp; + alloc_head *ah; + + size=PAGE_ALIGN(size); + + /* map free pages @ alloc_get_end */ + tmp=mmap(alloc_get_end, size, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, -1, 0); + if (tmp==MAP_FAILED) + { + /* OK we can't map free pages @ alloc_get_end so try free position */ + tmp=mmap(0, size, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + if (tmp==MAP_FAILED) + { + errno = ENOMEM; + return NULL; /* PANIC ! */ + } + alloc_get_end=tmp; + } + + alloc_get_end+=size; + + /* make a header */ + ah=(alloc_head*)tmp; + ah->ptr=ah; + ah->size=size; + + /* link new free maped pages in freelist */ + free(START_DATA(tmp)); + + return &base; +} + +void *malloc(size_t size) +{ + alloc_head *p, *prev; + size_t need; + + /* needed MEM_ALLOC_MIN */ + need=MIN_ALLOC(size); + + prev=&base; + for (p=prev->ptr;;prev=p,p=p->ptr) + { + if (p->size>=need) + { + if (p->size==need) + { /* fit PERFECT */ + prev->ptr=p->ptr; /* relink freelist */ + } + else + { + alloc_head *tmp=(alloc_head*)(((char*)p)+need); + + prev->ptr=tmp; + tmp->ptr=p->ptr; + tmp->size=p->size-need; /* remaining size */ + + p->size=need; /* set size */ + } + p->ptr=p; /* self-link */ + + return (void*)START_DATA(p); + } + else if (p==&base) + { + if ((p=alloc_get_mem(need))==NULL) return NULL; + } + } + return NULL; +} + +void *calloc(size_t nmemb,size_t size) +{ + size_t n=nmemb*size; + void *tmp=malloc(n); + if (tmp) memset(tmp,0,n); + return tmp; +} + +void *realloc(void *ptr,size_t size) +{ + alloc_head *tmp=0,*tf=0; + long need=0; + long diff=0; + + if (ptr) + { + if (size) + { + tmp=START_BLOCK(ptr); + need=MIN_ALLOC(size); /* only this size will survive */ + diff=tmp->size-need; + if (diff<0) + { + if ((tf=malloc(size))) + { + memcpy(tf,ptr,tmp->size-sizeof(alloc_head)); + free(ptr); + return tf; + } + return NULL; + } + if (diff>0) + { + tmp->size=need; + tf=END_OF_BLOCK(tmp); + tf->ptr=tf; + tf->size=diff; + free(START_DATA(tf)); + } + return ptr; + } + else + free(ptr); + } + else if (size>0) + return malloc(size); + return NULL; +} diff --git a/mdk-stage1/dietlibc/lib/assert_fail.c b/mdk-stage1/dietlibc/lib/assert_fail.c new file mode 100644 index 000000000..caa70ef5b --- /dev/null +++ b/mdk-stage1/dietlibc/lib/assert_fail.c @@ -0,0 +1,27 @@ +#include +#include +#include + +extern int __ltostr(char *s, int size, unsigned long i, int base, char UpCase); + +void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) +{ + int alen=strlen(assertion); + int flen=strlen(file); + int fulen=strlen(function); + char *buf=(char*)alloca(alen+flen+fulen+50); + if (buf) { + char *tmp; + *buf=0; + if (file) strcat(strcat(buf,file),":"); + tmp=buf+strlen(buf); + __ltostr(tmp,10,line,10,0); + strcat(buf,": "); + if (function) strcat(strcat(buf,function),": "); + strcat(buf,"Assertion `"); + strcat(buf,assertion); + strcat(buf,"' failed.\n"); + write(2,buf,strlen(buf)); + } + abort(); +} diff --git a/mdk-stage1/dietlibc/lib/atexit.c b/mdk-stage1/dietlibc/lib/atexit.c new file mode 100644 index 000000000..2b644bf49 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/atexit.c @@ -0,0 +1,23 @@ +typedef void (*function)(void); + +static function __atexitlist[4]; + +int atexit(function t) { + int i; + for (i=0; i<4; i++) + if (__atexitlist[i]==0) { + __atexitlist[i]=t; + return 0; + } + return -1; +} + +extern void _exit(int code) __attribute__((noreturn)); + +void exit(int code) { + if (__atexitlist[0]) __atexitlist[0](); + if (__atexitlist[1]) __atexitlist[1](); + if (__atexitlist[2]) __atexitlist[2](); + if (__atexitlist[3]) __atexitlist[3](); + _exit(code); +} diff --git a/mdk-stage1/dietlibc/lib/atof.c b/mdk-stage1/dietlibc/lib/atof.c new file mode 100644 index 000000000..4839e5152 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/atof.c @@ -0,0 +1,5 @@ +#include + +double atof(const char *nptr) { + return strtod(nptr,0); +} diff --git a/mdk-stage1/dietlibc/lib/atoi.c b/mdk-stage1/dietlibc/lib/atoi.c new file mode 100644 index 000000000..fe952b8c4 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/atoi.c @@ -0,0 +1,8 @@ +int atoi(const char* s) { + int v=0; + int sign=1; + if (*s=='-') { sign=-1; ++s; } else if (*s=='+') ++s; + while (*s && (*s>='0') && (*s<='9')) + v=v*10+*s++-'0'; + return v*sign; +} diff --git a/mdk-stage1/dietlibc/lib/atol.c b/mdk-stage1/dietlibc/lib/atol.c new file mode 100644 index 000000000..558a004b9 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/atol.c @@ -0,0 +1,8 @@ +long int atol(const char* s) { + long int v=0; + int sign=1; + if (*s=='-') { sign=-1; ++s; } else if (*s=='+') ++s; + while (*s && (*s>='0') && (*s<='9')) + v=v*10+*s++-'0'; + return v*sign; +} diff --git a/mdk-stage1/dietlibc/lib/bind.c b/mdk-stage1/dietlibc/lib/bind.c new file mode 100644 index 000000000..ec1c93e1b --- /dev/null +++ b/mdk-stage1/dietlibc/lib/bind.c @@ -0,0 +1,12 @@ +#include + +extern int socketcall(int callno,long* args); + +int bind(int a, void * b, int c) { +#ifdef __i386__ + return socketcall(SYS_BIND, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c }; + return socketcall(SYS_BIND, args); +#endif +} diff --git a/mdk-stage1/dietlibc/lib/cfgetospeed.c b/mdk-stage1/dietlibc/lib/cfgetospeed.c new file mode 100644 index 000000000..4e392a239 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/cfgetospeed.c @@ -0,0 +1,6 @@ +#include +#include + +speed_t cfgetospeed(struct termios *termios_p) { + return termios_p->c_ospeed; +} diff --git a/mdk-stage1/dietlibc/lib/closedir.c b/mdk-stage1/dietlibc/lib/closedir.c new file mode 100644 index 000000000..c8d834f3b --- /dev/null +++ b/mdk-stage1/dietlibc/lib/closedir.c @@ -0,0 +1,28 @@ +#include +#include +#include +#undef _POSIX_PTHREADS +#include "dirstream.h" + +#undef closedir +int closedir(DIR * dir) +{ + int fd; + + if (!dir) { + errno = EBADF; + return -1; + } + + /* We need to check dd_fd. */ + if (dir->dd_fd == -1) + { + errno = EBADF; + return -1; + } + fd = dir->dd_fd; + dir->dd_fd = -1; + free(dir->dd_buf); + free(dir); + return close(fd); +} diff --git a/mdk-stage1/dietlibc/lib/connect.c b/mdk-stage1/dietlibc/lib/connect.c new file mode 100644 index 000000000..f7f4f1ed7 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/connect.c @@ -0,0 +1,14 @@ +#include + +extern int socketcall(int callno,long* args); + +int connect(int a, void * b, int c) { +#ifdef __i386__ + return socketcall(SYS_CONNECT, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c }; + return socketcall(SYS_CONNECT, args); +#endif +} + +int __libc_connect(int a, void * b, int c) __attribute__((weak,alias("connect"))); diff --git a/mdk-stage1/dietlibc/lib/creat64.c b/mdk-stage1/dietlibc/lib/creat64.c new file mode 100644 index 000000000..923c1baaa --- /dev/null +++ b/mdk-stage1/dietlibc/lib/creat64.c @@ -0,0 +1,5 @@ +#include + +int creat64(const char *file,mode_t mode) { + return open64(file,O_WRONLY|O_CREAT|O_TRUNC,mode); +} diff --git a/mdk-stage1/dietlibc/lib/errlist.c b/mdk-stage1/dietlibc/lib/errlist.c new file mode 100644 index 000000000..d0e712190 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/errlist.c @@ -0,0 +1,132 @@ + +const char *const sys_errlist[] = { + "Success", /* 0 */ + "Operation not permitted", /* EPERM */ + "No such file or directory", /* ENOENT */ + "No such process", /* ESRCH */ + "Interrupted system call", /* EINTR */ + "I/O error", /* EIO */ + "No such device or address", /* ENXIO */ + "Arg list too long", /* E2BIG */ + "Exec format error", /* ENOEXEC */ + "Bad file number", /* EBADF */ + "No child processes", /* ECHILD */ + "Try again", /* EAGAIN */ + "Out of memory", /* ENOMEM */ + "Permission denied", /* EACCES */ + "Bad address", /* EFAULT */ + "Block device required", /* ENOTBLK */ + "Device or resource busy", /* EBUSY */ + "File exists", /* EEXIST */ + "Cross-device link", /* EXDEV */ + "No such device", /* ENODEV */ + "Not a directory", /* ENOTDIR */ + "Is a directory", /* EISDIR */ + "Invalid argument", /* EINVAL */ + "File table overflow", /* ENFILE */ + "Too many open files", /* EMFILE */ + "Not a typewriter", /* ENOTTY */ + "Text file busy", /* ETXTBSY */ + "File too large", /* EFBIG */ + "No space left on device", /* ENOSPC */ + "Illegal seek", /* ESPIPE */ + "Read-only file system", /* EROFS */ + "Too many links", /* EMLINK */ + "Broken pipe", /* EPIPE */ + "Math argument out of domain of func", /* EDOM */ + "Math result not representable", /* ERANGE */ + "Resource deadlock would occur", /* EDEADLK */ + "File name too long", /* ENAMETOOLONG */ + "No record locks available", /* ENOLCK */ + "Function not implemented", /* ENOSYS */ + "Directory not empty", /* ENOTEMPTY */ + "Too many symbolic links encountered", /* ELOOP */ + "Operation would block", /* EWOULDBLOCK */ + "No message of desired type", /* ENOMSG */ + "Identifier removed", /* EIDRM */ + "Channel number out of range", /* ECHRNG */ + "Level 2 not synchronized", /* EL2NSYNC */ + "Level 3 halted", /* EL3HLT */ + "Level 3 reset", /* EL3RST */ + "Link number out of range", /* ELNRNG */ + "Protocol driver not attached", /* EUNATCH */ + "No CSI structure available", /* ENOCSI */ + "Level 2 halted", /* EL2HLT */ + "Invalid exchange", /* EBADE */ + "Invalid request descriptor", /* EBADR */ + "Exchange full", /* EXFULL */ + "No anode", /* ENOANO */ + "Invalid request code", /* EBADRQC */ + "Invalid slot", /* EBADSLT */ + "File locking deadlock error", /* EDEADLOCK */ + "Bad font file format", /* EBFONT */ + "Device not a stream", /* ENOSTR */ + "No data available", /* ENODATA */ + "Timer expired", /* ETIME */ + "Out of streams resources", /* ENOSR */ + "Machine is not on the network", /* ENONET */ + "Package not installed", /* ENOPKG */ + "Object is remote", /* EREMOTE */ + "Link has been severed", /* ENOLINK */ + "Advertise error", /* EADV */ + "Srmount error", /* ESRMNT */ + "Communication error on send", /* ECOMM */ + "Protocol error", /* EPROTO */ + "Multihop attempted", /* EMULTIHOP */ + "RFS specific error", /* EDOTDOT */ + "Not a data message", /* EBADMSG */ + "Value too large for defined data type", /* EOVERFLOW */ + "Name not unique on network", /* ENOTUNIQ */ + "File descriptor in bad state", /* EBADFD */ + "Remote address changed", /* EREMCHG */ + "Can not access a needed shared library", /* ELIBACC */ + "Accessing a corrupted shared library", /* ELIBBAD */ + ".lib section in a.out corrupted", /* ELIBSCN */ + "Attempting to link in too many shared libraries", /* ELIBMAX */ + "Cannot exec a shared library directly", /* ELIBEXEC */ + "Illegal byte sequence", /* EILSEQ */ + "Interrupted system call should be restarted", /* ERESTART */ + "Streams pipe error", /* ESTRPIPE */ + "Too many users", /* EUSERS */ + "Socket operation on non-socket", /* ENOTSOCK */ + "Destination address required", /* EDESTADDRREQ */ + "Message too long", /* EMSGSIZE */ + "Protocol wrong type for socket", /* EPROTOTYPE */ + "Protocol not available", /* ENOPROTOOPT */ + "Protocol not supported", /* EPROTONOSUPPORT */ + "Socket type not supported", /* ESOCKTNOSUPPORT */ + "Operation not supported on transport endpoint", /* EOPNOTSUPP */ + "Protocol family not supported", /* EPFNOSUPPORT */ + "Address family not supported by protocol", /* EAFNOSUPPORT */ + "Address already in use", /* EADDRINUSE */ + "Cannot assign requested address", /* EADDRNOTAVAIL */ + "Network is down", /* ENETDOWN */ + "Network is unreachable", /* ENETUNREACH */ + "Network dropped connection because of reset", /* ENETRESET */ + "Software caused connection abort", /* ECONNABORTED */ + "Connection reset by peer", /* ECONNRESET */ + "No buffer space available", /* ENOBUFS */ + "Transport endpoint is already connected", /* EISCONN */ + "Transport endpoint is not connected", /* ENOTCONN */ + "Cannot send after transport endpoint shutdown", /* ESHUTDOWN */ + "Too many references: cannot splice", /* ETOOMANYREFS */ + "Connection timed out", /* ETIMEDOUT */ + "Connection refused", /* ECONNREFUSED */ + "Host is down", /* EHOSTDOWN */ + "No route to host", /* EHOSTUNREACH */ + "Operation already in progress", /* EALREADY */ + "Operation now in progress", /* EINPROGRESS */ + "Stale NFS file handle", /* ESTALE */ + "Structure needs cleaning", /* EUCLEAN */ + "Not a XENIX named type file", /* ENOTNAM */ + "No XENIX semaphores available", /* ENAVAIL */ + "Is a named type file", /* EISNAM */ + "Remote I/O error", /* EREMOTEIO */ + "Quota exceeded", /* EDQUOT */ + "No medium found", /* ENOMEDIUM */ + "Wrong medium type", /* EMEDIUMTYPE */ + 0 +}; + + +const int sys_nerr = ((sizeof (sys_errlist))/(sizeof(char *))-1); diff --git a/mdk-stage1/dietlibc/lib/errno_location.c b/mdk-stage1/dietlibc/lib/errno_location.c new file mode 100644 index 000000000..286f833c9 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/errno_location.c @@ -0,0 +1,5 @@ +extern int errno; + +int *__errno_location() { return &errno; } + +int *errno_location() __attribute__((weak,alias("__errno_location"))); diff --git a/mdk-stage1/dietlibc/lib/execl.c b/mdk-stage1/dietlibc/lib/execl.c new file mode 100644 index 000000000..ae28fb850 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/execl.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int execl( const char *path, ...) { + va_list ap; + int n,i; + char **argv,*tmp; + va_start(ap, path); + n=1; + while ((tmp=va_arg(ap,char *))) + ++n; + va_end (ap); + if ((argv=(char **)alloca(n*sizeof(char*)))) { + va_start(ap, path); + for (i=0; i +#include +#include +#include +#include +#include + +extern char **environ; + +static int exec_shell(const char *file, char *const argv[]) { + int i; + + for (i = 0; argv[i]; i++); + + if (1) { + char *shell_argv[i + 1]; + shell_argv[0] = _PATH_BSHELL; + shell_argv[1] = (char *) file; + for (; i > 1; i--) + shell_argv[i] = argv[i - 1]; + return execve(_PATH_BSHELL, shell_argv, environ); + } +} + +int execvp(const char *file, char *const argv[]) { + char *path=getenv("PATH"); + char *cur,*next; + char buf[PATH_MAX]; + if (strchr((char*)file,'/')) { + if (execve(file,argv,environ)==-1) { + if (errno==ENOEXEC) exec_shell(file,argv); + return -1; + } + } + if (!path) path=_PATH_DEFPATH; + for (cur=path; cur; cur=next) { + next=strchr(cur,':'); + if (!next) + next=cur+strlen(cur); + if (next==cur) { + buf[0]='.'; + cur--; + } else + memmove(buf,cur,next-cur); + buf[next-cur]='/'; + memmove(&buf[next-cur+1],file,strlen(file)+1); + if (execve(buf,argv,environ)==-1) { + if (errno==ENOEXEC) return exec_shell(buf,argv); + if ((errno!=EACCES) && (errno!=ENOENT)) return -1; + } + if (*next==0) break; + next++; + } + return -1; +} diff --git a/mdk-stage1/dietlibc/lib/ftw.c b/mdk-stage1/dietlibc/lib/ftw.c new file mode 100644 index 000000000..a3c04af9a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/ftw.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include + +int ftw(const char *dir,int (*fn)(const char *file, const struct stat *sb, int flag), int depth) { + char *cwd; + int cwdlen; + DIR *d; + struct dirent *de; + struct stat sb; + if (chdir(dir)) return -1; + cwd=alloca(PATH_MAX+1); + if (!getcwd(cwd,PATH_MAX)) return -1; + cwd[PATH_MAX]=0; + cwdlen=strlen(cwd); +/* write(1,"ftw in ",7); puts(cwd); */ + if (!(d=opendir("."))) return -1; + while ((de=readdir(d))) { + int res; + int flag; + int nlen; + char *filename; + if (de->d_name[0]=='.' && + (de->d_name[1]==0 || + (de->d_name[1]=='.' && de->d_name[2]==0))) continue; + nlen=strlen(de->d_name); + filename=alloca(nlen+cwdlen+3); + memmove(filename,cwd,cwdlen); + filename[cwdlen]='/'; + memmove(filename+cwdlen+1,de->d_name,nlen+1); + if (!lstat(de->d_name,&sb)) { + if (S_ISLNK(sb.st_mode)) flag=FTW_SL; else + if (S_ISDIR(sb.st_mode)) flag=FTW_D; else + flag=FTW_F; + } else + flag=FTW_NS; + res=fn(filename,&sb,flag); + if (res) return res; + if (flag==FTW_D && depth>0) { + res=ftw(filename,fn,depth-1); + chdir(dir); + if (res) return res; + } +/* puts(de->d_name); */ + } + closedir(d); + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/getdomainname.c b/mdk-stage1/dietlibc/lib/getdomainname.c new file mode 100644 index 000000000..2554fe4c3 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/getdomainname.c @@ -0,0 +1,17 @@ +#define _GNU_SOURCE + +#include +#include + +int getdomainname(char *name,size_t len) { + struct utsname u; + int res=uname(&u); + if (res==0) { + int i; + if (len>=_UTSNAME_DOMAIN_LENGTH) + len=_UTSNAME_DOMAIN_LENGTH; + for (i=0; i + +extern char **environ; + +extern char *getenv(const char *s) +{ + int i; + unsigned int len; + + if (!environ || !s) return 0; + len = strlen(s); + for (i = 0;environ[i];++i) + if ((memcmp(environ[i],s,len)==0) && (environ[i][len] == '=')) + return environ[i] + len + 1; + return 0; +} + diff --git a/mdk-stage1/dietlibc/lib/gethostname.c b/mdk-stage1/dietlibc/lib/gethostname.c new file mode 100644 index 000000000..ccc0fbc8e --- /dev/null +++ b/mdk-stage1/dietlibc/lib/gethostname.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include +#include + +int gethostname(char *name,size_t len) { + struct utsname u; + int res=uname(&u); + if (res==0) { + int i; + if (len>=_UTSNAME_NODENAME_LENGTH) + len=_UTSNAME_NODENAME_LENGTH; + for (i=0; i + +extern int socketcall(int callno,long* args); + +int getpeername(int a, void * b, int c) { +#ifdef __i386__ + return socketcall(SYS_GETPEERNAME, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c }; + return socketcall(SYS_GETPEERNAME, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/getservent.c b/mdk-stage1/dietlibc/lib/getservent.c new file mode 100644 index 000000000..ee6a77c21 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/getservent.c @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include +#include + +static int servicesfd=-1; +static char* servicesmap; +static unsigned int serviceslen; + +static char* aliases[10]; + +static char *cur; + +static inline int isalpha(char c) { + return (c>='a' && c<='z') || (c>='A' && c<='Z'); +} + +static inline int isdigit(char c) { + return (c>='0' && c<='9'); +} + +static inline int isalnum(char c) { + return isalpha(c) || isdigit(c); +} + +static inline int isblank(char c) { + return (c==' ' || c=='\t'); +} + +/* nameserver 42/tcp name # IEN 116 */ +struct servent *getservent(void) { + static struct servent se; + char *last; + int aliasidx; + if (servicesfd<0) { + servicesfd=open("/etc/services",O_RDONLY); + if (servicesfd<0) return 0; + serviceslen=lseek(servicesfd,0,SEEK_END); + servicesmap=mmap(0,serviceslen,PROT_READ|PROT_WRITE,MAP_PRIVATE,servicesfd,0); + if ((long)servicesmap==(-1)) goto error; + cur=servicesmap; + } + last=servicesmap+serviceslen; +again: + se.s_name=0; + se.s_aliases=aliases; aliases[0]=0; + se.s_port=0; + se.s_proto=0; + if (cur>=last) return 0; + if (*cur=='#' || *cur=='\n') goto parseerror; + /* first, the primary name */ + if (!isalpha(*cur)) goto parseerror; + se.s_name=cur; + se.s_aliases=aliases; + while (cur=last) return 0; + if (*cur=='\n') goto parseerror; + *cur=0; cur++; + /* second, the port */ + while (cur=last) return 0; + /* third, "/tcp" or "/udp" */ + if (*cur!='/') goto parseerror; + cur++; + se.s_proto=cur; + while (cur=last) return 0; + if (*cur=='\n') { *cur++=0; return &se; } + *cur=0; cur++; + /* now the aliases */ + for (aliasidx=0;aliasidx<10;aliasidx++) { + while (cur=last || !isblank(*cur)) break; + if (*cur=='\n') { *cur++=0; break; } + *cur++=0; + } + aliases[aliasidx]=0; + return &se; +parseerror: + while (curs_name,strlen(s->s_name)); + write(1,"/",1); + write(1,s->s_proto,strlen(s->s_proto)); + write(1,"\n",1); +#endif + if (!strcmp(name,s->s_name) && !strcmp(proto,s->s_proto)) + return s; + tmp=s->s_aliases; + while (*tmp) + if (!strcmp(name,*tmp++)) return s; + } + return 0; +} + +struct servent *getservbyport(int port, const char *proto) { + struct servent *s; + for (s=getservent(); s; s=getservent()) { + if (port==s->s_port && !strcmp(proto,s->s_proto)) + return s; + } + return 0; +} + +void setservent(int stayopen) { + cur=servicesmap; +} + +void endservent(void) { + if (servicesmap!=(char*)-1) munmap(servicesmap,serviceslen); + if (servicesfd!=-1) close(servicesfd); + servicesmap=(char*)-1; + servicesfd=-1; +} + diff --git a/mdk-stage1/dietlibc/lib/getsockname.c b/mdk-stage1/dietlibc/lib/getsockname.c new file mode 100644 index 000000000..61a3ea24a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/getsockname.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int getsockname(int a, void * b, int c) { +#ifdef __i386__ + return socketcall(SYS_GETSOCKNAME, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c }; + return socketcall(SYS_GETSOCKNAME, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/getsockopt.c b/mdk-stage1/dietlibc/lib/getsockopt.c new file mode 100644 index 000000000..8c0a57557 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/getsockopt.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int getsockopt(int a, int b, int c, void *d, int e) { +#ifdef __i386__ + return socketcall(SYS_GETSOCKOPT, (long*)&a); +#else + unsigned long args[] = { a, b, c, (long)d, e }; + return socketcall(SYS_GETSOCKOPT, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/htons.c b/mdk-stage1/dietlibc/lib/htons.c new file mode 100644 index 000000000..92a43f937 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/htons.c @@ -0,0 +1,12 @@ +#include + +#undef htons +#ifdef __i386__ +unsigned short int htons(unsigned short int netshort) { + return ___arch__swab16(netshort); +} +#else +unsigned short int htons(unsigned short int netshort) { + return netshort; +} +#endif diff --git a/mdk-stage1/dietlibc/lib/if_indextoname.c b/mdk-stage1/dietlibc/lib/if_indextoname.c new file mode 100644 index 000000000..e683755f6 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/if_indextoname.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +#ifndef SOCK_DGRAM +#define SOCK_DGRAM 2 +#endif + +char* if_indextoname(unsigned int interface,char* blub) { + struct ifreq ifr; + int fd; + + fd=socket(AF_INET6,SOCK_DGRAM,0); + if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); + ifr.ifr_ifindex=interface; + if (ioctl(fd,SIOCGIFNAME,&ifr)==0) { + int i; + close(fd); + for (i=0; i +#include +#include +#include +#include + +#ifndef SOCK_DGRAM +#define SOCK_DGRAM 2 +#endif + +int if_nametoindex(char* blub) { + struct ifreq ifr; + int fd; + char *tmp; + int len=sizeof(ifr.ifr_name); + fd=socket(AF_INET6,SOCK_DGRAM,0); + if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); + for (tmp=ifr.ifr_name; len>0; --len) { + if ((*tmp++=*blub++)==0) break; + } + if (ioctl(fd,SIOCGIFINDEX,&ifr)==0) { + close(fd); + return ifr.ifr_ifindex; + } + close(fd); + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/isalnum.c b/mdk-stage1/dietlibc/lib/isalnum.c new file mode 100644 index 000000000..19e5151d5 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isalnum.c @@ -0,0 +1,6 @@ +#include + +int isalnum(int c) { + return isalpha(c) || isdigit(c); +} + diff --git a/mdk-stage1/dietlibc/lib/isalpha.c b/mdk-stage1/dietlibc/lib/isalpha.c new file mode 100644 index 000000000..db04c3fae --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isalpha.c @@ -0,0 +1,6 @@ +#include + +inline int isalpha(int c) { + return (c>='a' && c<='z') || (c>='A' && c<='Z'); +} + diff --git a/mdk-stage1/dietlibc/lib/isascii.c b/mdk-stage1/dietlibc/lib/isascii.c new file mode 100644 index 000000000..e627efb41 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isascii.c @@ -0,0 +1,6 @@ +#include + +inline int isascii(int c) { + return (c & 0x80) == 0; +} + diff --git a/mdk-stage1/dietlibc/lib/isatty.c b/mdk-stage1/dietlibc/lib/isatty.c new file mode 100644 index 000000000..b31609720 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isatty.c @@ -0,0 +1,20 @@ +#define ioctl libc_ioctl +#include +#undef ioctl +#include + +extern int errno; + +int isatty(int fd) +{ + int save; + int is_tty; + struct termios term; + + save = errno; + is_tty = ioctl(fd, TCGETS, &term) == 0; + errno = save; + + return is_tty; +} + diff --git a/mdk-stage1/dietlibc/lib/isblank.c b/mdk-stage1/dietlibc/lib/isblank.c new file mode 100644 index 000000000..034e543b1 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isblank.c @@ -0,0 +1,6 @@ +#include + +int isblank(int ch) +{ + return ((ch==' ')||(ch=='\t')); +} diff --git a/mdk-stage1/dietlibc/lib/isdigit.c b/mdk-stage1/dietlibc/lib/isdigit.c new file mode 100644 index 000000000..734eb5197 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isdigit.c @@ -0,0 +1,6 @@ +#include + +inline int isdigit(int c) { + return (c>='0' && c<='9'); +} + diff --git a/mdk-stage1/dietlibc/lib/isspace.c b/mdk-stage1/dietlibc/lib/isspace.c new file mode 100644 index 000000000..ab39e81bc --- /dev/null +++ b/mdk-stage1/dietlibc/lib/isspace.c @@ -0,0 +1,6 @@ +#include + +int isspace(int ch) +{ + return ((ch==' ')||(ch=='\f')||(ch=='\t')||(ch=='\v')||(ch=='\r')||(ch=='\n')); +} diff --git a/mdk-stage1/dietlibc/lib/listen.c b/mdk-stage1/dietlibc/lib/listen.c new file mode 100644 index 000000000..56a51be06 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/listen.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int listen(int a, int b) { +#ifdef __i386__ + return socketcall(SYS_LISTEN, (long*)&a); +#else + unsigned long args[] = { a, b, 0 }; + return socketcall(SYS_LISTEN, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/lockf.c b/mdk-stage1/dietlibc/lib/lockf.c new file mode 100644 index 000000000..2b1d004ef --- /dev/null +++ b/mdk-stage1/dietlibc/lib/lockf.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +int lockf(int fd, int cmd, off_t len) { + struct flock fl; + fl.l_whence=SEEK_CUR; + fl.l_start=0; + fl.l_len=len; + fl.l_pid=0; + switch (cmd) { + case F_TEST: + if (fcntl(fd,F_GETLK,&fl)<0) + return -1; + if (fl.l_type == F_UNLCK || fl.l_pid == getpid ()) + return 0; + errno=EACCES; + return -1; + case F_ULOCK: + fl.l_type=F_UNLCK; + cmd=F_SETLK; + break; + case F_LOCK: + fl.l_type = F_WRLCK; + cmd = F_SETLKW; + break; + case F_TLOCK: + fl.l_type = F_WRLCK; + cmd = F_SETLK; + break; + default: + errno=EINVAL; + return -1; + } + return fcntl(fd,cmd,&fl); +} diff --git a/mdk-stage1/dietlibc/lib/longjmp.c b/mdk-stage1/dietlibc/lib/longjmp.c new file mode 100644 index 000000000..d0a5719c1 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/longjmp.c @@ -0,0 +1,51 @@ +/* Copyright (C) 1991, 92, 94, 95, 97, 98 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* #include */ +#include +#include + +extern int __sigprocmask(int how,void* set,void* oldset); +extern void __longjmp(void* env, int val); + +/* +extern void _longjmp_unwind (jmp_buf env, int val); +*/ +/* Set the signal mask to the one specified in ENV, and jump + to the position specified in ENV, causing the setjmp + call there to return VAL, or 1 if VAL is 0. */ +void __siglongjmp (sigjmp_buf env, int val) +{ + /* Perform any cleanups needed by the frames being unwound. */ + /* + _longjmp_unwind (env, val); + */ + + if (env[0].__mask_was_saved) + /* Restore the saved signal mask. */ + (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask, + (sigset_t *) NULL); + + /* Call the machine-dependent function to restore machine state. */ + __longjmp (env[0].__jmpbuf, val ?: 1); +} + +void siglongjmp (sigjmp_buf env, int val) __attribute__((weak,alias("__siglongjmp"))); +void longjmp (sigjmp_buf env, int val) __attribute__((weak,alias("__siglongjmp"))); +void _longjmp (sigjmp_buf env, int val) __attribute__((weak,alias("__siglongjmp"))); +void __libc_longjmp (sigjmp_buf env, int val) __attribute__((weak,alias("__siglongjmp"))); diff --git a/mdk-stage1/dietlibc/lib/memccmp.c b/mdk-stage1/dietlibc/lib/memccmp.c new file mode 100644 index 000000000..3a8c14f60 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memccmp.c @@ -0,0 +1,17 @@ +#define _POSIX_SOURCE +#define _XOPEN_SOURCE +#include + +int memccmp(const void *dst, const void *src, int c, size_t count) +{ + register const char *a = dst; + register const char *b = src; + while (count--) + { + register int res=(*a - *b); + if (res) return res; + if (*a==c) return 0; + ++a; ++b; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/memccpy.c b/mdk-stage1/dietlibc/lib/memccpy.c new file mode 100644 index 000000000..6d6ac98ab --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memccpy.c @@ -0,0 +1,19 @@ +#define _POSIX_SOURCE +#define _XOPEN_SOURCE +#include + +void *memccpy(void *dst, const void *src, int c, size_t count) +{ + char *a = dst; + const char *b = src; + while (count--) + { + *a++ = *b; + if (*b==c) + { + return (void *)a; + } + b++; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/memchr.c b/mdk-stage1/dietlibc/lib/memchr.c new file mode 100644 index 000000000..93d81328a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memchr.c @@ -0,0 +1,9 @@ +#include + +char *memchr(const char *s, int c, size_t n) { + int i; + for (i=n; i; --i) + if (*s++==c) + return (char*)s; + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/memcmp.c b/mdk-stage1/dietlibc/lib/memcmp.c new file mode 100644 index 000000000..8bce6c975 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memcmp.c @@ -0,0 +1,14 @@ +#include + +int memcmp(const void *dst, const void *src, size_t count) { + register int r; + register const char *d=dst; + register const char *s=src; + while (count--) { + if ((r=(*d - *s))) + return r; + ++d; + ++s; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/memcpy.c b/mdk-stage1/dietlibc/lib/memcpy.c new file mode 100644 index 000000000..0c688b509 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memcpy.c @@ -0,0 +1,12 @@ +#include + +void* memcpy(void* dst, const void* src, size_t count) { + register char *d=dst; + register const char *s=src; + ++count; /* this actually produces better code than using count-- */ + while (--count) { + *d = *s; + ++d; ++s; + } + return dst; +} diff --git a/mdk-stage1/dietlibc/lib/memmove.c b/mdk-stage1/dietlibc/lib/memmove.c new file mode 100644 index 000000000..7adb2be91 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memmove.c @@ -0,0 +1,23 @@ +#define _POSIX_SOURCE +#define _XOPEN_SOURCE +#include + +void *memmove(void *dst, const void *src, size_t count) +{ + char *a = dst; + const char *b = src; + if (src!=dst) + { + if (src>dst) + { + while (count--) *a++ = *b++; + } + else + { + a+=count-1; + b+=count-1; + while (count--) *a-- = *b--; + } + } + return dst; +} diff --git a/mdk-stage1/dietlibc/lib/memset.c b/mdk-stage1/dietlibc/lib/memset.c new file mode 100644 index 000000000..5f9ae49ee --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memset.c @@ -0,0 +1,9 @@ +#include + +void * memset(void * dst, int s, size_t count) { + register char * a = dst; + count++; /* this actually creates smaller code than using count-- */ + while (--count) + *a++ = s; + return dst; +} diff --git a/mdk-stage1/dietlibc/lib/mkfifo.c b/mdk-stage1/dietlibc/lib/mkfifo.c new file mode 100644 index 000000000..97659490c --- /dev/null +++ b/mdk-stage1/dietlibc/lib/mkfifo.c @@ -0,0 +1,6 @@ +#include +#include + +int mkfifo(char *fn,int mode) { + return mknod(fn,S_IFIFO|mode,0); +} diff --git a/mdk-stage1/dietlibc/lib/nop.c b/mdk-stage1/dietlibc/lib/nop.c new file mode 100644 index 000000000..623278dee --- /dev/null +++ b/mdk-stage1/dietlibc/lib/nop.c @@ -0,0 +1,7 @@ + +int __fflush_stdin() __attribute__((weak,alias("__nop"))); +int __fflush_stdout() __attribute__((weak,alias("__nop"))); +int __fflush_stderr() __attribute__((weak,alias("__nop"))); + +/* used for weak aliases */ +int __nop() { return 0; } diff --git a/mdk-stage1/dietlibc/lib/open64.c b/mdk-stage1/dietlibc/lib/open64.c new file mode 100644 index 000000000..cab7e992e --- /dev/null +++ b/mdk-stage1/dietlibc/lib/open64.c @@ -0,0 +1,11 @@ +#include +#include +#include + +#ifdef O_LARGEFILE +int open64(const char* file,int oflag,int mode) { + return open(file,oflag|O_LARGEFILE,mode); +} + +int __libc_open64(const char* file,int oflag,int mode) __attribute__((weak,alias("open64"))); +#endif diff --git a/mdk-stage1/dietlibc/lib/opendir.c b/mdk-stage1/dietlibc/lib/opendir.c new file mode 100644 index 000000000..05c0b9bc8 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/opendir.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#undef _POSIX_PTHREADS +#include + +#include "dirstream.h" + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0200000 /* must be a directory */ +#endif + +/* + * opendir just makes an open() call - it return NULL if it fails + * (open sets errno), otherwise it returns a DIR * pointer. + */ +#undef opendir +DIR * +opendir(const char * name) +{ + int fd; + struct stat statbuf; + struct dirent *buf; + DIR *ptr; + + /* + if (stat(name,&statbuf)) return NULL; + if (!S_ISDIR(statbuf.st_mode)) { + errno = ENOTDIR; + return NULL; + } + */ + if ((fd = open(name,O_RDONLY|O_DIRECTORY)) < 0) + return NULL; + /* According to POSIX, directory streams should be closed when + * exec. From "Anna Pluzhnikov" . + */ + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) + return NULL; + if (!(ptr=malloc(sizeof(*ptr)))) { + close(fd); + errno = ENOMEM; + return NULL; + } + + ptr->dd_max = statbuf.st_blksize; + if (ptr->dd_max < 512) + ptr->dd_max = 512; + + if (!(buf=malloc(ptr->dd_max))) { + close(fd); + free(ptr); + errno = ENOMEM; + return NULL; + } + ptr->dd_fd = fd; + ptr->dd_nextoff = ptr->dd_nextloc = ptr->dd_size = 0; + ptr->dd_buf = buf; + ptr->dd_getdents = unknown; + return ptr; +} diff --git a/mdk-stage1/dietlibc/lib/perror.c b/mdk-stage1/dietlibc/lib/perror.c new file mode 100644 index 000000000..5476d76a1 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/perror.c @@ -0,0 +1,16 @@ +#include +#include + +extern char *sys_errlist[]; +extern int sys_nerr; +extern int errno; + +void perror(const char *s) { + register char *message="[unknown error]"; + write(2,s,strlen(s)); + write(2,": ",2); + if (errno>=0 && errno +#include + +extern size_t __pread(int fd, void *buf, size_t count, off_t a,off_t b); + +size_t __libc_pread(int fd, void *buf, size_t count, off_t offset) { + return __pread(fd,buf,count,offset,0); +} + +int pread(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pread"))); diff --git a/mdk-stage1/dietlibc/lib/pread64.c b/mdk-stage1/dietlibc/lib/pread64.c new file mode 100644 index 000000000..e6ba4d103 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/pread64.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#ifndef __NO_STAT64 +extern size_t __pread(int fd, void *buf, size_t count, off_t a,off_t b); + +size_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset) { + return __pread(fd,buf,count,__LONG_LONG_PAIR (offset&0xffffffff,offset>>32)); +} + +int pread64(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pread64"))); +#endif diff --git a/mdk-stage1/dietlibc/lib/putenv.c b/mdk-stage1/dietlibc/lib/putenv.c new file mode 100644 index 000000000..274b16b0e --- /dev/null +++ b/mdk-stage1/dietlibc/lib/putenv.c @@ -0,0 +1,37 @@ +#include +#include + +int putenv(const char *string) { + int len; + int envc; + char *tmp; + const char **ep; + char **newenv; + static char **origenv=0; + if (!origenv) origenv=environ; + if (!(tmp=strchr(string,'='))) + len=strlen(string); + else + len=tmp-string+1; + for (envc=0, ep=(const char**)environ; *ep; ++ep) { + if (!memcmp(string,*ep,len)) { /* found */ + if (!tmp) { + for (; ep[1]; ++ep) ep[0]=ep[1]; + ep[0]=0; + return 0; + } + *ep=string; + return 0; + } + ++envc; + } + if (tmp) { + newenv=(char**)malloc((envc+2)*sizeof(char*)); + if (!newenv) return -1; + newenv[0]=(char*)string; + memcpy(newenv+1,environ,(envc+1)*sizeof(char*)); + if (environ!=origenv) free(environ); + environ=newenv; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/puts.c b/mdk-stage1/dietlibc/lib/puts.c new file mode 100644 index 000000000..01f6e50c4 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/puts.c @@ -0,0 +1,6 @@ +#include +#include + +int puts(const char *s) { + return write(1,s,strlen(s)) && write(1,"\n",1); +} diff --git a/mdk-stage1/dietlibc/lib/raise.c b/mdk-stage1/dietlibc/lib/raise.c new file mode 100644 index 000000000..606546034 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/raise.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include "syscalls.h" + +int raise(int sig) { + return kill(getpid(),sig); +} diff --git a/mdk-stage1/dietlibc/lib/readdir.c b/mdk-stage1/dietlibc/lib/readdir.c new file mode 100644 index 000000000..5accd32a1 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/readdir.c @@ -0,0 +1,83 @@ +#if 0 + +Sorry, currently broken + +#include +#include +#include +#include +#include + +#include "dirstream.h" + +#ifdef __ELF__ +#pragma weak readdir = __libc_readdir +#endif + +struct dirent * +__libc_readdir(DIR * dir) +{ + int result; + struct dirent *de; + + if (!dir) { + errno = EBADF; + return NULL; + } + + /* Are we running an old kernel? */ + if (dir->dd_getdents == no_getdents) + { + abort(); + } + + if (dir->dd_size <= dir->dd_nextloc) + { + /* read dir->dd_max bytes of directory entries. */ + result=getdents(dir->dd_fd,dir->dd_buf,dir->dd_max); + + /* We assume we have getdents (). */ + dir->dd_getdents = have_getdents; + if (result <= 0) + { + result = -result; + if (result > 0) + { + /* Are we right? */ + if (result == ENOSYS) + { + dir->dd_getdents = no_getdents; + abort(); + } + errno = result; + } + + return NULL; + } + + dir->dd_size = result; + dir->dd_nextloc = 0; + } + + de = (struct dirent *) (((char *)dir->dd_buf) + dir->dd_nextloc); + + /* Am I right? H.J. */ + dir->dd_nextloc += de->d_reclen; + + /* We have to save the next offset here. */ + dir->dd_nextoff = de->d_off; + + /* convert */ + dir->convbuf.d_ino=de->d_ino; + dir->convbuf.d_off=de->d_off; + dir->convbuf.d_reclen=de->d_reclen; + dir->convbuf.d_type=0; + if (strlen((char*)&de->d_type)>10) + de->d_name[10]=0; + strcpy(dir->convbuf.d_name,(char*)&de->d_type); + errno=0; + + return &dir->convbuf; +} + +#endif diff --git a/mdk-stage1/dietlibc/lib/recv.c b/mdk-stage1/dietlibc/lib/recv.c new file mode 100644 index 000000000..cc778712c --- /dev/null +++ b/mdk-stage1/dietlibc/lib/recv.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int recv(int a, const void * b, size_t c, int flags) { +#ifdef __i386__ + return socketcall(SYS_RECV,(long*)&a); +#else + unsigned long args[] = { a, (long) b, c, flags }; + return socketcall(SYS_RECV, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/recvfrom.c b/mdk-stage1/dietlibc/lib/recvfrom.c new file mode 100644 index 000000000..a07afe7ad --- /dev/null +++ b/mdk-stage1/dietlibc/lib/recvfrom.c @@ -0,0 +1,12 @@ +#include + +extern int socketcall(int callno,long* args); + +int recvfrom(int a, const void * b, size_t c, int flags, void *to, void *tolen) { +#ifdef __i386__ + return socketcall(SYS_RECVFROM, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c, flags, (long) to, (long) tolen }; + return socketcall(SYS_RECVFROM, args); +#endif +} diff --git a/mdk-stage1/dietlibc/lib/rewind.c b/mdk-stage1/dietlibc/lib/rewind.c new file mode 100644 index 000000000..48434a316 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/rewind.c @@ -0,0 +1,6 @@ +#include +#include + +void rewind( FILE *stream) { + fseek(stream, 0L, SEEK_SET); +} diff --git a/mdk-stage1/dietlibc/lib/rewinddir.c b/mdk-stage1/dietlibc/lib/rewinddir.c new file mode 100644 index 000000000..138936527 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/rewinddir.c @@ -0,0 +1,17 @@ +#include +#include + +#include "dirstream.h" + +/* + * rewinddir() just does an lseek(fd,0,0) - see close for comments + */ +void rewinddir(DIR * dir) +{ + if (!dir) { + errno = EBADF; + return; + } + lseek(dir->dd_fd,0,SEEK_SET); + dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0; +} diff --git a/mdk-stage1/dietlibc/lib/sbrk.c b/mdk-stage1/dietlibc/lib/sbrk.c new file mode 100644 index 000000000..945ad5a16 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sbrk.c @@ -0,0 +1,20 @@ +#include + +extern int __brk(void *end_data_segment); + +extern void* __curbrk; + +void* __sbrk(ptrdiff_t increment) { + void* oldbrk; + if (__curbrk==0) + if (__brk(0) < 0) + return (void*)-1; + if (increment==0) + return __curbrk; + oldbrk=__curbrk; + if (__brk(oldbrk+increment)<0) + return (void*)-1; + return oldbrk; +} + +void* sbrk (ptrdiff_t increment) __attribute__((weak,alias("__sbrk"))); diff --git a/mdk-stage1/dietlibc/lib/seekdir.c b/mdk-stage1/dietlibc/lib/seekdir.c new file mode 100644 index 000000000..f83052250 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/seekdir.c @@ -0,0 +1,15 @@ +#include +#include + +#include "dirstream.h" + +#undef seekdir +void seekdir(DIR * dir, off_t offset) +{ + if (!dir) { + errno = EBADF; + return; + } + dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET); + dir->dd_size = dir->dd_nextloc = 0; +} diff --git a/mdk-stage1/dietlibc/lib/send.c b/mdk-stage1/dietlibc/lib/send.c new file mode 100644 index 000000000..be43b4e63 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/send.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int send(int a, const void * b, size_t c, int flags) { +#ifdef __i386__ + return socketcall(SYS_SEND, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c, flags }; + return socketcall(SYS_SEND, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/sendto.c b/mdk-stage1/dietlibc/lib/sendto.c new file mode 100644 index 000000000..e6c2560f3 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sendto.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int sendto(int a, const void * b, size_t c, int flags, void *to, int tolen) { +#ifdef __i386__ + return socketcall(SYS_SENDTO, (long*)&a); +#else + unsigned long args[] = { a, (long) b, c, flags, (long) to, tolen }; + return socketcall(SYS_SENDTO, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/set_errno.c b/mdk-stage1/dietlibc/lib/set_errno.c new file mode 100644 index 000000000..6553bc496 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/set_errno.c @@ -0,0 +1,9 @@ +extern int errno; + +void __set_errno(int error) __attribute__ ((weak)); + +void __set_errno(int error) +{ + errno=error; +} + diff --git a/mdk-stage1/dietlibc/lib/setsockopt.c b/mdk-stage1/dietlibc/lib/setsockopt.c new file mode 100644 index 000000000..781e9c31c --- /dev/null +++ b/mdk-stage1/dietlibc/lib/setsockopt.c @@ -0,0 +1,13 @@ +#include + +extern int socketcall(int callno,long* args); + +int setsockopt(int a, int b, int c, void *d, void *e) { +#ifdef __i386__ + return socketcall(SYS_SETSOCKOPT, (long*)&a); +#else + unsigned long args[] = { a, b, c, (long)d, (long) e }; + return socketcall(SYS_SETSOCKOPT, args); +#endif +} + diff --git a/mdk-stage1/dietlibc/lib/sigaddset.c b/mdk-stage1/dietlibc/lib/sigaddset.c new file mode 100644 index 000000000..0c9d95c28 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigaddset.c @@ -0,0 +1,21 @@ +#define __USE_EXTERN_INLINES 1 +#include + +# define __sigmask(sig) \ + (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int)))) + +# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int))) + +# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) +typedef struct + { + unsigned long int __val[_SIGSET_NWORDS]; + } __sigset_t; + +int __sigaddset(__sigset_t *set, int signo) { + unsigned long int __mask = __sigmask (signo); + unsigned long int __word = __sigword (signo); + return ((set->__val[__word] |= __mask), 0); +} + +int sigaddset (sigset_t *env, int signo) __attribute__((weak,alias("__sigaddset"))); diff --git a/mdk-stage1/dietlibc/lib/sigemptyset.c b/mdk-stage1/dietlibc/lib/sigemptyset.c new file mode 100644 index 000000000..f4532f96e --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigemptyset.c @@ -0,0 +1,14 @@ +#define __USE_EXTERN_INLINES 1 +#include +#include +#include + +int sigemptyset(sigset_t *set) { + if (set==NULL) { + __set_errno(EINVAL); + return -1; + } + memset(set,0,sizeof(*set)); + return 0; +} + diff --git a/mdk-stage1/dietlibc/lib/sigjmp.c b/mdk-stage1/dietlibc/lib/sigjmp.c new file mode 100644 index 000000000..d7db58fd2 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigjmp.c @@ -0,0 +1,36 @@ +/* Copyright (C) 1992, 1994, 1997 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include + +/* This function is called by the `sigsetjmp' macro + before doing a `__setjmp' on ENV[0].__jmpbuf. + Always return zero. */ + +int +__sigjmp_save (sigjmp_buf env, int savemask) +{ + env[0].__mask_was_saved = (savemask && + sigprocmask (SIG_BLOCK, (sigset_t *) NULL, + (sigset_t*)&env[0].__saved_mask) == 0); + + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/sleep.c b/mdk-stage1/dietlibc/lib/sleep.c new file mode 100644 index 000000000..ec5b99533 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sleep.c @@ -0,0 +1,11 @@ +#include +#include + +unsigned int sleep(unsigned int secs) { + struct timespec t; + t.tv_sec=secs; + t.tv_nsec=0; + nanosleep(&t,&t); + return secs-t.tv_sec; +} + diff --git a/mdk-stage1/dietlibc/lib/snprintf.c b/mdk-stage1/dietlibc/lib/snprintf.c new file mode 100644 index 000000000..096c06115 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/snprintf.c @@ -0,0 +1,14 @@ +#include +#include + +int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); + +int snprintf(char *str,size_t size,const char *format,...) +{ + int n; + va_list arg_ptr; + va_start(arg_ptr, format); + n=vsnprintf(str,size,format,arg_ptr); + va_end (arg_ptr); + return n; +} diff --git a/mdk-stage1/dietlibc/lib/socket.c b/mdk-stage1/dietlibc/lib/socket.c new file mode 100644 index 000000000..1684a6a2b --- /dev/null +++ b/mdk-stage1/dietlibc/lib/socket.c @@ -0,0 +1,12 @@ +#include + +extern int socketcall(int callno,long* args); + +int socket(int a, int b, int c) { +#ifdef __i386__ + return socketcall(SYS_SOCKET, (long*)&a); +#else + unsigned long args[] = { a, b, c }; + return socketcall(SYS_SOCKET, args); +#endif +} diff --git a/mdk-stage1/dietlibc/lib/sprintf.c b/mdk-stage1/dietlibc/lib/sprintf.c new file mode 100644 index 000000000..f1b554ce2 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sprintf.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); + +int sprintf(char *dest,const char *format,...) +{ + int n; + va_list arg_ptr; + va_start(arg_ptr, format); + n=vsnprintf(dest,1000000,format,arg_ptr); + va_end (arg_ptr); + return n; +} diff --git a/mdk-stage1/dietlibc/lib/sscanf.c b/mdk-stage1/dietlibc/lib/sscanf.c new file mode 100644 index 000000000..341e74bba --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sscanf.c @@ -0,0 +1,13 @@ +#include + +int vsscanf(const char *str, const char *format, va_list arg_ptr); + +int sscanf(const char *str, const char *format, ...) +{ + int n; + va_list arg_ptr; + va_start(arg_ptr, format); + n=vsscanf(str,format,arg_ptr); + va_end (arg_ptr); + return n; +} diff --git a/mdk-stage1/dietlibc/lib/strcat.c b/mdk-stage1/dietlibc/lib/strcat.c new file mode 100644 index 000000000..8a755afea --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strcat.c @@ -0,0 +1,18 @@ +#include "dietfeatures.h" +#include + +char* strcat(register char* s,register const char* t) +{ + char *dest=s; + s+=strlen(s); + for (;;) { + if (!(*s = *t)) break; ++s; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + if (!(*s = *t)) break; ++s; ++t; + if (!(*s = *t)) break; ++s; ++t; + if (!(*s = *t)) break; ++s; ++t; +#endif + } + return dest; +} + diff --git a/mdk-stage1/dietlibc/lib/strchr.c b/mdk-stage1/dietlibc/lib/strchr.c new file mode 100644 index 000000000..b908853f8 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strchr.c @@ -0,0 +1,16 @@ +#include "dietfeatures.h" + +char *strchr(register const char *t, int c) { + register char ch; + + ch = c; + for (;;) { + if (*t == ch) break; if (!*t) return 0; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + if (*t == ch) break; if (!*t) return 0; ++t; + if (*t == ch) break; if (!*t) return 0; ++t; + if (*t == ch) break; if (!*t) return 0; ++t; +#endif + } + return (char*)t; +} diff --git a/mdk-stage1/dietlibc/lib/strcmp.c b/mdk-stage1/dietlibc/lib/strcmp.c new file mode 100644 index 000000000..0db324e66 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strcmp.c @@ -0,0 +1,16 @@ +#include "dietfeatures.h" + +int strcmp(register const char *s,register const char *t) { + register char x; + + for (;;) { + x = *s; if (x != *t) break; if (!x) break; ++s; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + x = *s; if (x != *t) break; if (!x) break; ++s; ++t; + x = *s; if (x != *t) break; if (!x) break; ++s; ++t; + x = *s; if (x != *t) break; if (!x) break; ++s; ++t; +#endif + } + return ((int)(unsigned int)(unsigned char) x) + - ((int)(unsigned int)(unsigned char) *t); +} diff --git a/mdk-stage1/dietlibc/lib/strcpy.c b/mdk-stage1/dietlibc/lib/strcpy.c new file mode 100644 index 000000000..49693c30d --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strcpy.c @@ -0,0 +1,15 @@ +#include "dietfeatures.h" + +char* strcpy(register char* s,register const char* t) +{ + char *dest=s; + for (;;) { + if (!(*s = *t)) return dest; ++s; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + if (!(*s = *t)) return dest; ++s; ++t; + if (!(*s = *t)) return dest; ++s; ++t; + if (!(*s = *t)) return dest; ++s; ++t; +#endif + } +} + diff --git a/mdk-stage1/dietlibc/lib/strcspn.c b/mdk-stage1/dietlibc/lib/strcspn.c new file mode 100644 index 000000000..37053c72c --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strcspn.c @@ -0,0 +1,17 @@ +#include +#include + +size_t strcspn(const char *s, const char *reject) +{ + size_t l=0; + int a=1,i,al=strlen(reject); + + while((a)&&(*s)) + { + for(i=0;(a)&&(i +#include + +char *strdup(const char *s) { + char *tmp=(char *)malloc(strlen(s)+1); + if (!tmp) return 0; + strcpy(tmp,s); + return tmp; +} diff --git a/mdk-stage1/dietlibc/lib/strerror.c b/mdk-stage1/dietlibc/lib/strerror.c new file mode 100644 index 000000000..f15b86aae --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strerror.c @@ -0,0 +1,10 @@ +#include + +extern char *sys_errlist[]; +extern int sys_nerr; + +char *strerror(int errnum) { + if (errnum>=0 && errnum + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(initial dst) + strlen(src); if retval >= siz, + * truncation occurred. + */ +size_t strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/mdk-stage1/dietlibc/lib/strlcpy.c b/mdk-stage1/dietlibc/lib/strlcpy.c new file mode 100644 index 000000000..b935b9527 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strlcpy.c @@ -0,0 +1,68 @@ +/* $OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/mdk-stage1/dietlibc/lib/strlen.c b/mdk-stage1/dietlibc/lib/strlen.c new file mode 100644 index 000000000..56c085dac --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strlen.c @@ -0,0 +1,47 @@ +#include +#include "dietfeatures.h" +#include + +#ifdef WANT_SMALL_STRING_ROUTINES +size_t strlen(const char *s) { + register int i; + if (!s) return 0; + for (i=0; *s; ++s) ++i; + return i; +} +#else +static const unsigned long magic = 0x01010101; + +size_t strlen(const char *s) +{ + const char *t = s; + unsigned long word; + + if (!s) return 0; + + /* Byte compare up until word boundary */ + for (; ((unsigned long) t & 3); t++) + if (!*t) return t - s; + + /* Word compare */ + do { + word = *((unsigned long *) t); t += 4; + word = (word - magic) &~ word; + word &= (magic << 7); + } while (word == 0); + +#if BYTE_ORDER == LITTLE_ENDIAN + /* word & 0x80808080 == word */ + word = (word - 1) & (magic << 10); + word += (word << 8) + (word << 16); + t += word >> 26; +#else + if ((word & 0x80800000) == 0) { + word <<= 16; + t += 2; + } + if ((word & 0x80000000) == 0) t += 1; +#endif + return ((const char *) t) - 4 - s; +} +#endif diff --git a/mdk-stage1/dietlibc/lib/strncat.c b/mdk-stage1/dietlibc/lib/strncat.c new file mode 100644 index 000000000..1d3b94ca5 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strncat.c @@ -0,0 +1,19 @@ +#include "dietfeatures.h" +#include + +char *strncat(char *s, const char *t, size_t n) { + char *dest=s; + register char *max=s+n-1; + s+=strlen(s); + for (;;) { + if (!(*s = *t)) break; if (++s==max) break; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + if (!(*s = *t)) break; if (++s==max) break; ++t; + if (!(*s = *t)) break; if (++s==max) break; ++t; + if (!(*s = *t)) break; if (++s==max) break; ++t; +#endif + } + *s=0; + return dest; +} + diff --git a/mdk-stage1/dietlibc/lib/strncmp.c b/mdk-stage1/dietlibc/lib/strncmp.c new file mode 100644 index 000000000..7c08c0fa7 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strncmp.c @@ -0,0 +1,6 @@ +#include +#include + +int strncmp(const char *s1, const char *s2, size_t n) { + return memccmp(s1,s2,0,n); +} diff --git a/mdk-stage1/dietlibc/lib/strncpy.c b/mdk-stage1/dietlibc/lib/strncpy.c new file mode 100644 index 000000000..531387b7f --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strncpy.c @@ -0,0 +1,10 @@ +#define _POSIX_SOURCE +#define _XOPEN_SOURCE +#include +#include + +char *strncpy(char *dest, const char *src, size_t n) +{ + memccpy(dest,src,0,n); + return dest; +} diff --git a/mdk-stage1/dietlibc/lib/strpbrk.c b/mdk-stage1/dietlibc/lib/strpbrk.c new file mode 100644 index 000000000..e18fd2a2d --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strpbrk.c @@ -0,0 +1,11 @@ +#include +#include + +char *strpbrk(const char *s, const char *accept) { + register int i,l=strlen(accept); + for (; *s; s++) + for (i=0; i +#include "dietfeatures.h" + +char *strrchr(const char *t, int c) { + register char ch; + register const char *l=0; + + ch = c; + for (;;) { + if (*t == ch) l=t; if (!*t) return (char*)l; ++t; +#ifndef WANT_SMALL_STRING_ROUTINES + if (*t == ch) l=t; if (!*t) return (char*)l; ++t; + if (*t == ch) l=t; if (!*t) return (char*)l; ++t; + if (*t == ch) l=t; if (!*t) return (char*)l; ++t; +#endif + } + return (char*)l; +} diff --git a/mdk-stage1/dietlibc/lib/strspn.c b/mdk-stage1/dietlibc/lib/strspn.c new file mode 100644 index 000000000..2b3a4c116 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strspn.c @@ -0,0 +1,17 @@ +#include +#include + +size_t strspn(const char *s, const char *accept) +{ + size_t l=0; + int a=1,i,al=strlen(accept); + + while((a)&&(*s)) + { + for(a=i=0;(!a)&&(i +#include + +char *strstr(const char *haystack, const char *needle) { + int nl=strlen(needle); + int hl=strlen(haystack); + int i; + if (nl>hl) return 0; + for (i=hl-nl+1; i; --i) { + if (!memcmp(haystack,needle,nl)) + return (char*)haystack; + ++haystack; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/strtod.c b/mdk-stage1/dietlibc/lib/strtod.c new file mode 100644 index 000000000..767be679f --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtod.c @@ -0,0 +1,52 @@ +#include + +extern char isspace(char c); + +#ifdef __GNUC__ +static inline char isdigit(char c) { return (c>='0' && c<='9'); } +#endif + +double strtod(const char *nptr, char **endptr) { + double d=0; + register const char *c=nptr; + char neg=0; + while (*c && isspace(*c)) ++c; + switch (*c) { + case '-': neg=1; + case '+': c++; break; + default: break; + } + while (isdigit(*c)) { + d=d*10+(*c-'0'); + ++c; + } + if (*c=='.') { + double factor=.1; + while (isdigit(*++c)) { + d=d+(factor*(*c-'0')); + factor/=10; + } + } + if ((*c|32)=='e') { + int exp=0; + char neg=0; + if (c[1]<'0') { + switch (*c) { + case '-': neg=1; + case '+': c++; break; + default: + d=0; + c=nptr; + goto done; + } + } + while (isdigit(*++c)) + exp=exp*10+(*c-'0'); + while (exp) { /* XXX: this introduces rounding errors */ + d*=10; --exp; + } + } +done: + if (endptr) *endptr=(char*)c; + return d; +} diff --git a/mdk-stage1/dietlibc/lib/strtok.c b/mdk-stage1/dietlibc/lib/strtok.c new file mode 100644 index 000000000..525665e59 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtok.c @@ -0,0 +1,6 @@ +char *strtok_r(char *s, const char *delim, char **ptrptr); +static char *strtok_pos; +char *strtok(char *s, const char *delim) +{ + return strtok_r(s,delim,&strtok_pos); +} diff --git a/mdk-stage1/dietlibc/lib/strtok_r.c b/mdk-stage1/dietlibc/lib/strtok_r.c new file mode 100644 index 000000000..93f9401de --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtok_r.c @@ -0,0 +1,21 @@ +#include + +char *strtok_r(char *s, const char *delim, char **ptrptr) +{ + int i; + char *tmp=0; + + if (s) (*ptrptr)=s; + + if (**ptrptr) + { + while(!(i=strcspn(*ptrptr,delim))) (*ptrptr)++; + if (**ptrptr) + { + tmp=(*ptrptr); + (*ptrptr)+=i; + if (**ptrptr) *(*ptrptr)++=0; + } + } + return tmp; +} diff --git a/mdk-stage1/dietlibc/lib/strtol.c b/mdk-stage1/dietlibc/lib/strtol.c new file mode 100644 index 000000000..ead89f408 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtol.c @@ -0,0 +1,15 @@ +#include + +extern unsigned long int strtoul(const char *nptr, char **endptr, int base); + +long int strtol(const char *nptr, char **endptr, int base) +{ + int neg=0; + unsigned long int v; + + while(isspace(*nptr)) nptr++; + + if (*nptr == '-' && isdigit(nptr[1])) { neg=-1; nptr++; } + v=strtoul(nptr,endptr,base); + return (neg?-v:v); +} diff --git a/mdk-stage1/dietlibc/lib/strtoll.c b/mdk-stage1/dietlibc/lib/strtoll.c new file mode 100644 index 000000000..7b8e28a1d --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtoll.c @@ -0,0 +1,15 @@ +#include + +extern unsigned long int strtoull(const char *nptr, char **endptr, int base); + +long int strtoll(const char *nptr, char **endptr, int base) +{ + int neg=0; + unsigned long long int v; + + while(isspace(*nptr)) nptr++; + + if (*nptr == '-' && isdigit(nptr[1])) { neg=-1; nptr++; } + v=strtoull(nptr,endptr,base); + return (neg?-v:v); +} diff --git a/mdk-stage1/dietlibc/lib/strtoul.c b/mdk-stage1/dietlibc/lib/strtoul.c new file mode 100644 index 000000000..bee849685 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtoul.c @@ -0,0 +1,39 @@ +#include + +static char *num="0123456789abcdefghijklmnopqrstuvwxyz"; + +unsigned long int strtoul(const char *nptr, char **endptr, int base) +{ + long int v=0; + int a=1,i; + + while(isspace(*nptr)) nptr++; + + if (*nptr == '+') { nptr++; } + if (!base) + { + if (*nptr=='0') + { + base=8; + if ((*(nptr+1)=='x')||(*(nptr+1)=='X')) base=16; + } + else + base=10; + } + while((a)&&(*nptr)) + { + a=0; + for (i=0;(!a)&&(i + +static char *num="0123456789abcdefghijklmnopqrstuvwxyz"; + +unsigned long long int strtoull(const char *nptr, char **endptr, int base) +{ + long long int v=0; + int a=1,i; + + while(isspace(*nptr)) nptr++; + + if (*nptr == '+') { nptr++; } + if (!base) + { + if (*nptr=='0') + { + base=8; + if ((*(nptr+1)=='x')||(*(nptr+1)=='X')) base=16; + } + else + base=10; + } + while((a)&&(*nptr)) + { + a=0; + for (i=0;(!a)&&(i +#include + +int tcgetattr(int fildes, struct termios *termios_p) +{ + return ioctl(fildes, TCGETS, termios_p); +} diff --git a/mdk-stage1/dietlibc/lib/tcsetattr.c b/mdk-stage1/dietlibc/lib/tcsetattr.c new file mode 100644 index 000000000..642588d47 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/tcsetattr.c @@ -0,0 +1,23 @@ +#define tcsetattr libc_tcsetattr +#include +#include +#undef tcsetattr + +#include + +extern int errno; + +int tcsetattr(int fildes, int optional_actions, struct termios *termios_p) +{ + switch (optional_actions) { + case TCSANOW: + return ioctl(fildes, TCSETS, termios_p); + case TCSADRAIN: + return ioctl(fildes, TCSETSW, termios_p); + case TCSAFLUSH: + return ioctl(fildes, TCSETSF, termios_p); + default: + errno = EINVAL; + return -1; + } +} diff --git a/mdk-stage1/dietlibc/lib/telldir.c b/mdk-stage1/dietlibc/lib/telldir.c new file mode 100644 index 000000000..eca175381 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/telldir.c @@ -0,0 +1,38 @@ +#include +#include + +#include "dirstream.h" + +#undef telldir +off_t +telldir(DIR * dir) +{ + off_t offset; + + if (!dir) { + errno = EBADF; + return -1; + } + + switch (dir->dd_getdents) + { + case no_getdents: + /* We are running the old kernel. This is the starting offset + of the next readdir(). */ + offset = lseek(dir->dd_fd, 0, SEEK_CUR); + break; + + case unknown: + /* readdir () is not called yet. but seekdir () may be called. */ + case have_getdents: + /* The next entry. */ + offset = dir->dd_nextoff; + break; + + default: + errno = EBADF; + offset = -1; + } + + return offset; +} diff --git a/mdk-stage1/dietlibc/lib/ttyname.c b/mdk-stage1/dietlibc/lib/ttyname.c new file mode 100644 index 000000000..a6b479088 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/ttyname.c @@ -0,0 +1,59 @@ +#include "dietfeatures.h" +#include +#include + +#ifdef __linux__ + +extern int __ltostr(char *s, int size, unsigned long i, int base, char UpCase); + +char *ttyname(int fd) { +#ifdef SLASH_PROC_OK + char ibuf[20]; + static char obuf[20]; + strcpy(ibuf,"/proc/self/fd/"); + ibuf[__ltostr(ibuf+14,6,fd,10,0)+14]=0; + if (readlink(ibuf,obuf,sizeof(obuf)-1)<0) return 0; + return obuf; +#else + static char buf[20]="/dev/tty"; + struct stat s; + char *c=buf+8; + int n; + if (fstat(fd,&s)) return 0; + if (S_ISCHR(s.st_mode)) { + n=minor(s.st_rdev); + switch (major(s.st_rdev)) { + case 4: + buf[5]='t'; buf[7]='y'; + if (n>63) { + n-=64; + *c='S'; + ++c; + } +num: + c[__ltostr(c,6,n,10,0)]=0; + break; + case 2: + buf[5]='p'; buf[7]='y'; + buf[8]='p'-(n>>4); + buf[9]=n%4+'0'; + if (buf[9]>'9') *c+='a'-'0'; + buf[10]=0; + case 136: + case 137: + case 138: + case 139: + buf[5]='p'; buf[7]='s'; + n+=(major(s.st_rdev)-136)<<8; + *c='/'; ++c; + goto num; + default: + return 0; + } + return buf; + } + return 0; +#endif +} + +#endif diff --git a/mdk-stage1/dietlibc/lib/vfork.c b/mdk-stage1/dietlibc/lib/vfork.c new file mode 100644 index 000000000..795cddb05 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vfork.c @@ -0,0 +1,6 @@ +#include +#include + +pid_t vfork(void) { + return fork(); +} diff --git a/mdk-stage1/dietlibc/lib/vfprintf.c b/mdk-stage1/dietlibc/lib/vfprintf.c new file mode 100644 index 000000000..0ebfd1561 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vfprintf.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int vfprintf(FILE *fstream, const char *format, va_list ap) +{ + char *tmp; + size_t n=vsnprintf(0, 1000000, format, ap); + tmp=alloca(n+2); + if (tmp) { + vsnprintf(tmp, n+1, format, ap); + fwrite(tmp, n,1, fstream); + } + return n; +} diff --git a/mdk-stage1/dietlibc/lib/vprintf.c b/mdk-stage1/dietlibc/lib/vprintf.c new file mode 100644 index 000000000..bba98419f --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vprintf.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); + +int vprintf(const char *format, va_list ap) +{ + int n; + char *printf_buf; +/* char printf_buf[1024]; */ + va_list temp = ap; + n=vsnprintf(0,1000000,format,temp); +/* write(1,printf_buf,strlen(printf_buf)); */ + printf_buf=alloca(n+2); + n=vsnprintf(printf_buf,n+1,format,ap); + write(1,printf_buf,n); + return n; +} diff --git a/mdk-stage1/dietlibc/lib/vsnprintf.c b/mdk-stage1/dietlibc/lib/vsnprintf.c new file mode 100644 index 000000000..5bbc51620 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vsnprintf.c @@ -0,0 +1,239 @@ +#include "dietfeatures.h" +#include +#include +#include +#include + +extern int __ltostr(char *s, int size, unsigned long i, int base, char UpCase); +extern int __dtostr(double d,char *buf,int maxlen,int prec); + +#include +void print_int(int fd, int i) +{ + char buf[10]; + char * chptr = buf + 9; + int j = 0; + + if (i < 0) + { + write(1, "-", 1); + i = -1 * i; + } + + while (i) + { + *chptr-- = '0' + (i % 10); + j++; + i = i / 10; + } + + write(fd, chptr + 1, j); +} + +int vsnprintf (char *str, size_t size, const char *format, va_list arg_ptr) +{ + size_t apos,i; + char ch,buf[1024]; + char *pb; + char flag_in_sign; + char flag_hash,flag_zero,flag_left,flag_space,flag_sign,flag_dot,flag_long; + long number,width,preci,buf_len,pad; + char padwith; + + size--; + + apos=0; + while (apos=size) continue; /* ARGL !!! */ + + ch=*format++; + switch (ch) + { +/* Format end ?!? */ + case 0: + return -1; + break; + +/* Format flag chars */ + case '#': + flag_hash=1; + goto inn_vsnprintf; + + case 'l': + flag_long=1; + goto inn_vsnprintf; + + case '0': + padwith='0'; + goto inn_vsnprintf; + + case '-': + flag_left=1; + goto inn_vsnprintf; + + case ' ': + flag_space=1; + goto inn_vsnprintf; + + case '+': + flag_sign=1; + goto inn_vsnprintf; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if(flag_dot) return -1; + width=strtol(--format,&pb,10); + format=pb; + goto inn_vsnprintf; + + case '.': + flag_dot=1; + preci=strtol(format,&pb,10); + format=pb; + goto inn_vsnprintf; + +/* Format conversion chars */ + case 'c': + ch=(char)va_arg(arg_ptr,int); + case '%': + if (str) str[apos]=ch; ++apos; + break; + + case 's': + pb=va_arg(arg_ptr,char *); +#ifdef WANT_NULL_PRINTF + if (!pb) pb="(null)"; +#endif + buf_len=strlen(pb); + +print_out: + if (str) { + if (width && (!flag_left)) + { + for (pad=width-buf_len; pad>0; --pad) str[apos++]=padwith; + } + for(i=0;(pb[i])&&(apos0; --pad) str[apos++]=padwith; + } + } else { + if (width) + apos+=width; + else { + int a=strlen(pb); + if (a>size) apos+=size; else apos+=a; + } + } + + break; + + /* Numbers */ + case 'b': + i=2; + goto num_vsnprintf; + case 'p': + flag_hash=1; + width=sizeof(void *)<<1; + padwith='0'; + ch='x'; + case 'X': + case 'x': + i=16; + if (flag_hash) + { + if (str) { + str[apos++]='0'; + str[apos++]=ch; + } else + apos+=2; + } + goto num_vsnprintf; + case 'd': + case 'i': + flag_in_sign=1; + case 'u': + i=10; + goto num_vsnprintf; + case 'o': + i=8; + if (flag_hash) { if (str) str[apos]='0'; ++apos; } + +num_vsnprintf: + if (apos>=size) continue; /* ARGL !!! */ + + if (flag_long) + number=va_arg(arg_ptr,long); + else + number=va_arg(arg_ptr,int); + + if (flag_in_sign && (number<0)) + { + number*=-1; + flag_in_sign=2; + } + + buf_len=__ltostr(buf+1,sizeof(buf)-1,(unsigned long) number,i,0); + pb=buf+1; + + if (flag_in_sign==2) + { + *(--pb)='-'; + buf_len++; + } + else if ((flag_in_sign)&&(flag_sign || flag_space)) + { + *(--pb)=(flag_sign)?'+':' '; + buf_len++; + } + goto print_out; + +#ifdef WANT_FLOATING_POINT_IN_PRINTF + case 'g': + { + double d=va_arg(arg_ptr,double); + buf_len=__dtostr(d,buf,sizeof(buf),6); + pb=buf; + goto print_out; + } +#endif + default: + break; + } + break; + case 0: + if (str) str[apos]=0; + return apos; + default: + if (str) str[apos]=ch; apos++; + break; + } + } + if (str) str[apos]=0; + return apos; +} diff --git a/mdk-stage1/dietlibc/lib/vsprintf.c b/mdk-stage1/dietlibc/lib/vsprintf.c new file mode 100644 index 000000000..af4eea852 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vsprintf.c @@ -0,0 +1,11 @@ +#include +#include +#include +#include + +int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); + +int vsprintf(char *str, const char *format, va_list ap) +{ + return vsnprintf(str, 1000000, format, ap); +} diff --git a/mdk-stage1/dietlibc/lib/vsscanf.c b/mdk-stage1/dietlibc/lib/vsscanf.c new file mode 100644 index 000000000..e370062e7 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/vsscanf.c @@ -0,0 +1,241 @@ +#include "dietfeatures.h" +#include +#include +#include +#include + +const char *skip_ws(const char *str) +{ + while ((*str)&&(isspace(*str))) str++; + return str; +} + +extern double strtod(const char *s,char **f); + +int vsscanf(const char *str, const char *format, va_list arg_ptr) +{ + int n=0,div; + char ch; + + char flag_discard, flag_malloc, flag_half, flag_long, flag_longlong; + char flag_width; + + unsigned long width; + + /* arg_ptr tmps */ + double d,*pd; + float *pf; + + long l=0,*pl; + short *ph; + int *pi; + char *s; + + while ((*str)&&(*format)) + { + const char *prevfmt=format; + format=skip_ws(format); + ch=*format++; + if (!ch) continue; + + switch (ch) + { + case '%': + div=0; + flag_discard=0; + flag_malloc=0; + flag_half=0; + flag_long=0; + flag_longlong=0; + + flag_width=0; + width=-1; + +inn_vsscanf: + ch=*format++; + + switch (ch) + { + case 0: + return 0; + + case '%': + if (*(str++)!=ch) return n; + break; + + /* flags */ + case '*': + flag_discard=1; + goto inn_vsscanf; + + case 'a': + flag_malloc=1; + goto inn_vsscanf; + + case 'h': + flag_half=1; + goto inn_vsscanf; + + case 'l': + if (flag_long) flag_longlong=1; + flag_long=1; + goto inn_vsscanf; + + /* longlong ? NOT YET ! */ + case 'q': + case 'L': + flag_longlong=1; + goto inn_vsscanf; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + width=strtol(format-1,&s,10); + format=s; + flag_width=1; + goto inn_vsscanf; + + /* conversion */ + + case 'n': + while (width && *str) + { + *(s++)=*(str++); + --width; + l++; + } + if (!flag_discard) + { + pl=(long *)va_arg(arg_ptr,long*); + *pl=l; + ++n; + } + break; + + case 'p': + case 'X': + case 'x': + div+=6; + case 'd': + div+=2; + case 'o': + div+=8; + case 'u': + case 'i': + if (*(str=skip_ws(str))) + { + l=strtol(str,&s,div); + if (str!=s) + { + if (!flag_discard) + { + if (flag_long) + { + pl=(long *)va_arg(arg_ptr,long*); + *pl=l; + } + else if (flag_half) + { + ph=(short *)va_arg(arg_ptr,short*); + *ph=l; + } + else + { + pi=(int *)va_arg(arg_ptr,int*); + *pi=l; + } + ++n; + } + str=s; + } + else + return n; + } + break; + +#ifdef WANT_FLOATING_POINT_IN_SCANF + case 'e': + case 'E': + case 'f': + case 'g': + if (*(str=skip_ws(str))) + { + d=strtod(str,&s); + if (str!=s) + { + if (!flag_discard) + { + if (flag_long) + { + pd=(double *)va_arg(arg_ptr,double*); + *pd=d; + } + else + { + pf=(float *)va_arg(arg_ptr,float*); + *pf=d; + } + ++n; + } + str=s; + } + else + return n; + } + break; +#endif + + case 'c': + if (!flag_discard) + { + s=(char *)va_arg(arg_ptr,char*); + ++n; + } + if (!flag_width) width=1; + while (width && *str) + { + if (!flag_discard) *(s++)=*(str); + ++str; + --width; + } + break; + + case 's': + if (!flag_discard) + { + s=(char *)va_arg(arg_ptr,char*); + ++n; + } + if (*(str=skip_ws(str))) + { + while (width && *str && (!isspace(*str))) + { + if (!flag_discard) *(s++)=*(str); + ++str; + --width; + } + *s = '\0'; + } + break; + } + break; + + default: + if (prevfmt +#include + +pid_t wait(int *status) { + return waitpid(-1,status,0); +} diff --git a/mdk-stage1/dietlibc/lib/wait3.c b/mdk-stage1/dietlibc/lib/wait3.c new file mode 100644 index 000000000..19e90740c --- /dev/null +++ b/mdk-stage1/dietlibc/lib/wait3.c @@ -0,0 +1,5 @@ +#include + +int wait3(int* status,int opts,struct rusage* rusage) { + return wait4(-1,status,opts,rusage); +} -- cgit v1.2.1