From 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwenol=C3=A9=20Beauchesne?= Date: Wed, 4 Jun 2003 18:44:09 +0000 Subject: Import dietlibc 0.22 + other fixes for AMD64 --- mdk-stage1/dietlibc/lib/__ftruncate64.c | 23 ++ mdk-stage1/dietlibc/lib/__isinf.c | 15 ++ mdk-stage1/dietlibc/lib/__ptrace.c | 27 +++ mdk-stage1/dietlibc/lib/__stime.c | 14 ++ mdk-stage1/dietlibc/lib/__truncate64.c | 23 ++ mdk-stage1/dietlibc/lib/__v_printf.c | 300 ++++++++++++++++++++++++ mdk-stage1/dietlibc/lib/__v_scanf.c | 391 ++++++++++++++++++++++++++++++++ mdk-stage1/dietlibc/lib/adjtime.c | 18 ++ mdk-stage1/dietlibc/lib/atoll.c | 19 ++ mdk-stage1/dietlibc/lib/bcd.c | 185 +++++++++++++++ mdk-stage1/dietlibc/lib/binshstr.c | 5 + mdk-stage1/dietlibc/lib/cfgetospeed.c | 8 + mdk-stage1/dietlibc/lib/cfsetispeed.c | 22 ++ mdk-stage1/dietlibc/lib/cfsetospeed.c | 14 ++ mdk-stage1/dietlibc/lib/errlistu.c | 6 + mdk-stage1/dietlibc/lib/execle.c | 26 +++ mdk-stage1/dietlibc/lib/if_nameindex.c | 40 ++++ mdk-stage1/dietlibc/lib/ipv6constants.c | 4 + mdk-stage1/dietlibc/lib/labs.c | 6 + mdk-stage1/dietlibc/lib/llabs.c | 6 + mdk-stage1/dietlibc/lib/memmem.c | 14 ++ mdk-stage1/dietlibc/lib/memrchr.c | 15 ++ mdk-stage1/dietlibc/lib/pwrite.c | 11 + mdk-stage1/dietlibc/lib/pwrite64.c | 14 ++ mdk-stage1/dietlibc/lib/rand48.c | 89 ++++++++ mdk-stage1/dietlibc/lib/rand_r.c | 30 +++ mdk-stage1/dietlibc/lib/readdir64.c | 62 +++++ mdk-stage1/dietlibc/lib/setlinebuf.c | 12 + mdk-stage1/dietlibc/lib/sigaction.c | 11 + mdk-stage1/dietlibc/lib/siginterrupt.c | 17 ++ mdk-stage1/dietlibc/lib/signal.c | 12 + mdk-stage1/dietlibc/lib/sigpending.c | 7 + mdk-stage1/dietlibc/lib/sigprocmask.c | 7 + mdk-stage1/dietlibc/lib/sigqueueinfo.c | 7 + mdk-stage1/dietlibc/lib/sigsuspend.c | 10 + mdk-stage1/dietlibc/lib/sigtimedwait.c | 7 + mdk-stage1/dietlibc/lib/socketpair.c | 12 + mdk-stage1/dietlibc/lib/strtof.c | 66 ++++++ mdk-stage1/dietlibc/lib/strtold.c | 66 ++++++ mdk-stage1/dietlibc/lib/strxfrm.c | 12 + mdk-stage1/dietlibc/lib/tcflow.c | 35 +++ mdk-stage1/dietlibc/lib/tcsendbreak.c | 11 + mdk-stage1/dietlibc/lib/write12.c | 11 + 43 files changed, 1690 insertions(+) create mode 100644 mdk-stage1/dietlibc/lib/__ftruncate64.c create mode 100644 mdk-stage1/dietlibc/lib/__isinf.c create mode 100644 mdk-stage1/dietlibc/lib/__ptrace.c create mode 100644 mdk-stage1/dietlibc/lib/__stime.c create mode 100644 mdk-stage1/dietlibc/lib/__truncate64.c create mode 100644 mdk-stage1/dietlibc/lib/__v_printf.c create mode 100644 mdk-stage1/dietlibc/lib/__v_scanf.c create mode 100644 mdk-stage1/dietlibc/lib/adjtime.c create mode 100644 mdk-stage1/dietlibc/lib/atoll.c create mode 100644 mdk-stage1/dietlibc/lib/bcd.c create mode 100644 mdk-stage1/dietlibc/lib/binshstr.c create mode 100644 mdk-stage1/dietlibc/lib/cfgetospeed.c create mode 100644 mdk-stage1/dietlibc/lib/cfsetispeed.c create mode 100644 mdk-stage1/dietlibc/lib/cfsetospeed.c create mode 100644 mdk-stage1/dietlibc/lib/errlistu.c create mode 100644 mdk-stage1/dietlibc/lib/execle.c create mode 100644 mdk-stage1/dietlibc/lib/if_nameindex.c create mode 100644 mdk-stage1/dietlibc/lib/ipv6constants.c create mode 100644 mdk-stage1/dietlibc/lib/labs.c create mode 100644 mdk-stage1/dietlibc/lib/llabs.c create mode 100644 mdk-stage1/dietlibc/lib/memmem.c create mode 100644 mdk-stage1/dietlibc/lib/memrchr.c create mode 100644 mdk-stage1/dietlibc/lib/pwrite.c create mode 100644 mdk-stage1/dietlibc/lib/pwrite64.c create mode 100644 mdk-stage1/dietlibc/lib/rand48.c create mode 100644 mdk-stage1/dietlibc/lib/rand_r.c create mode 100644 mdk-stage1/dietlibc/lib/readdir64.c create mode 100644 mdk-stage1/dietlibc/lib/setlinebuf.c create mode 100644 mdk-stage1/dietlibc/lib/sigaction.c create mode 100644 mdk-stage1/dietlibc/lib/siginterrupt.c create mode 100644 mdk-stage1/dietlibc/lib/signal.c create mode 100644 mdk-stage1/dietlibc/lib/sigpending.c create mode 100644 mdk-stage1/dietlibc/lib/sigprocmask.c create mode 100644 mdk-stage1/dietlibc/lib/sigqueueinfo.c create mode 100644 mdk-stage1/dietlibc/lib/sigsuspend.c create mode 100644 mdk-stage1/dietlibc/lib/sigtimedwait.c create mode 100644 mdk-stage1/dietlibc/lib/socketpair.c create mode 100644 mdk-stage1/dietlibc/lib/strtof.c create mode 100644 mdk-stage1/dietlibc/lib/strtold.c create mode 100644 mdk-stage1/dietlibc/lib/strxfrm.c create mode 100644 mdk-stage1/dietlibc/lib/tcflow.c create mode 100644 mdk-stage1/dietlibc/lib/tcsendbreak.c create mode 100644 mdk-stage1/dietlibc/lib/write12.c (limited to 'mdk-stage1/dietlibc/lib') diff --git a/mdk-stage1/dietlibc/lib/__ftruncate64.c b/mdk-stage1/dietlibc/lib/__ftruncate64.c new file mode 100644 index 000000000..e0ea8c98a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__ftruncate64.c @@ -0,0 +1,23 @@ +#include +#include "dietfeatures.h" +#ifdef WANT_LARGEFILE_BACKCOMPAT +#include +#include "syscalls.h" +#include +#ifndef __NO_STAT64 +#ifdef __NR_ftruncate64 + +extern int __dietlibc_ftruncate64(int fd, loff_t o); + +int ftruncate64(int fd, loff_t o) { + int tmp; + if ((tmp=__dietlibc_ftruncate64(fd,o))==-1) { + if (errno!=ENOSYS) return -1; + if (o>0x7fffffff) { errno=EOVERFLOW; return -1; } + return ftruncate(fd,o); + } + return tmp; +} +#endif +#endif +#endif diff --git a/mdk-stage1/dietlibc/lib/__isinf.c b/mdk-stage1/dietlibc/lib/__isinf.c new file mode 100644 index 000000000..359bd2709 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__isinf.c @@ -0,0 +1,15 @@ +#include + +int isinf(double d) { + unsigned long long *x=(unsigned long long *)&d; + return (*x==0x7FF0000000000000ll?1:*x==0xFFF0000000000000?-1:0); +} +int __isinf(double d) __attribute__((alias("isinf"))); + +#if 0 +TestFromIeeeExtended("7FFF0000000000000000"); /* +infinity */ +TestFromIeeeExtended("FFFF0000000000000000"); /* -infinity */ +TestFromIeeeExtended("7FFF8001000000000000"); /* Quiet NaN(1) */ +TestFromIeeeExtended("7FFF0001000000000000"); /* Signalling NaN(1) */ +TestFromIeeeExtended("3FFFFEDCBA9876543210"); /* accuracy test */ +#endif diff --git a/mdk-stage1/dietlibc/lib/__ptrace.c b/mdk-stage1/dietlibc/lib/__ptrace.c new file mode 100644 index 000000000..bd14a0351 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__ptrace.c @@ -0,0 +1,27 @@ +/* we need this because we need to use the glibc prototype which uses + * varargs :-( */ +#define ptrace fnord +#include +#undef ptrace +#include +#include + +extern int __diet_ptrace(int request, pid_t pid, void *addr, void *data); +int ptrace(int request, pid_t pid, void *addr, void *data); + +int ptrace(int request, pid_t pid, void *addr, void *data) { + switch (request) { + case PTRACE_TRACEME: case PTRACE_KILL: case PTRACE_ATTACH: + case PTRACE_DETACH: + return (__diet_ptrace (request, pid, NULL, NULL)); + case PTRACE_PEEKDATA: case PTRACE_PEEKUSER: case PTRACE_PEEKTEXT: + { + long result; + if (__diet_ptrace (request, pid, addr, &result) == -1) + return (-1); + return (result); + } + default: + return (__diet_ptrace (request, pid, addr, data)); + } +} diff --git a/mdk-stage1/dietlibc/lib/__stime.c b/mdk-stage1/dietlibc/lib/__stime.c new file mode 100644 index 000000000..7b2c77729 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__stime.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +#ifndef __NR_stime +int stime(time_t *when) +{ + struct timeval tv; + tv.tv_sec = *when; + tv.tv_usec = 0; + return settimeofday(&tv, (struct timezone *)0); +} +#endif diff --git a/mdk-stage1/dietlibc/lib/__truncate64.c b/mdk-stage1/dietlibc/lib/__truncate64.c new file mode 100644 index 000000000..ccb3e7f64 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__truncate64.c @@ -0,0 +1,23 @@ +#include "dietfeatures.h" +#include +#ifdef WANT_LARGEFILE_BACKCOMPAT +#include +#include "syscalls.h" +#include +#ifndef __NO_STAT64 +#ifdef __NR_truncate64 + +extern int __dietlibc_truncate64(const char* f, loff_t o); + +int truncate64(const char* f, loff_t o) { + int tmp; + if ((tmp=__dietlibc_truncate64(f,o))==-1) { + if (errno!=ENOSYS) return -1; + if (o>0x7fffffff) { errno=EOVERFLOW; return -1; } + return truncate(f,o); + } + return tmp; +} +#endif +#endif +#endif diff --git a/mdk-stage1/dietlibc/lib/__v_printf.c b/mdk-stage1/dietlibc/lib/__v_printf.c new file mode 100644 index 000000000..15011cdd8 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__v_printf.c @@ -0,0 +1,300 @@ +#include "dietfeatures.h" +#include +#include +#include +#include +#include "dietstdio.h" +#include "dietwarning.h" + +static inline unsigned int skip_to(const unsigned char *format) { + unsigned int nr; + for (nr=0; format[nr] && (format[nr]!='%'); ++nr); + return nr; +} + +#define A_WRITE(fn,buf,sz) ((fn)->put((void*)(buf),(sz),(fn)->data)) + +static const char pad_line[2][16]= { " ", "0000000000000000", }; +static inline int write_pad(struct arg_printf* fn, int len, int padwith) { + int nr=0; + for (;len>15;len-=16,nr+=16) { + A_WRITE(fn,pad_line[(padwith=='0')?1:0],16); + } + if (len>0) { + A_WRITE(fn,pad_line[(padwith=='0')?1:0],(unsigned int)len); nr+=len; + } + return nr; +} + +int __v_printf(struct arg_printf* fn, const unsigned char *format, va_list arg_ptr) +{ + int len=0; + + while (*format) { + unsigned int sz = skip_to(format); + if (sz) { + A_WRITE(fn,format,sz); len+=sz; + format+=sz; + } + if (*format=='%') { + char buf[128]; + + unsigned char ch, *s, padwith=' '; + + char flag_in_sign=0; + char flag_upcase=0; + char flag_hash=0; + char flag_left=0; + char flag_space=0; + char flag_sign=0; + char flag_dot=0; + signed char flag_long=0; + + unsigned int base; + unsigned int width=0, preci=0; + + long number=0; +#ifdef WANT_LONGLONG_PRINTF + long long llnumber=0; +#endif + + ++format; +inn_printf: + switch(ch=*format++) { + case 0: + return -1; + break; + + /* FLAGS */ + case '#': + flag_hash=-1; + case 'z': + goto inn_printf; + + case 'h': + --flag_long; + goto inn_printf; + case 'L': + ++flag_long; /* fall through */ + case 'l': + ++flag_long; + goto inn_printf; + + case '0': + padwith='0'; + goto inn_printf; + + case '-': + flag_left=1; + goto inn_printf; + + case ' ': + flag_space=1; + goto inn_printf; + + case '+': + flag_sign=1; + goto inn_printf; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if(flag_dot) return -1; + width=strtoul(format-1,(char**)&s,10); + format=s; + goto inn_printf; + + case '*': + width=va_arg(arg_ptr,int); + goto inn_printf; + + case '.': + flag_dot=1; + if (*format=='*') { + preci=va_arg(arg_ptr,int); + ++format; + } else { + long int tmp=strtol(format,(char**)&s,10); + preci=tmp<0?0:tmp; + format=s; + } + goto inn_printf; + + /* print a char or % */ + case 'c': + ch=(char)va_arg(arg_ptr,int); + case '%': + A_WRITE(fn,&ch,1); ++len; + break; + + /* print a string */ + case 's': + s=va_arg(arg_ptr,char *); +#ifdef WANT_NULL_PRINTF + if (!s) s="(null)"; +#endif + sz = strlen(s); + if (flag_dot && sz>preci) sz=preci; + flag_dot^=flag_dot; + +print_out: + if (width && (!flag_left)) { + if (flag_in_sign) { + A_WRITE(fn,s,1); ++len; + ++s; --sz; + --width; + } + if (flag_hash>0) { + A_WRITE(fn,s,flag_hash); len+=flag_hash; + s+=flag_hash; sz-=flag_hash; + width-=flag_hash; + } +// len+=write_pad(fn,(signed int)width-(signed int)sz,padwith); + if (flag_dot) { + len+=write_pad(fn,(signed int)width-(signed int)preci,padwith); + len+=write_pad(fn,(signed int)preci-(signed int)sz,'0'); + } else + len+=write_pad(fn,(signed int)width-(signed int)sz,padwith); + } + A_WRITE(fn,s,sz); len+=sz; + if (width && (flag_left)) { + len+=write_pad(fn,(signed int)width-(signed int)sz,' '); + } + break; + + /* print an integer value */ + case 'b': + base=2; + sz=0; + goto num_printf; + case 'p': + flag_hash=2; + flag_long=1; + ch='x'; + case 'X': + flag_upcase=(ch=='X'); + case 'x': + base=16; + sz=0; + if (flag_dot) width=preci; + if (flag_hash) { + buf[1]='0'; + buf[2]=ch; + flag_hash=2; + sz=2; + } + goto num_printf; + case 'd': + case 'i': + flag_in_sign=1; + case 'u': + base=10; + sz=0; + goto num_printf; + case 'o': + base=8; + sz=0; + if (flag_hash) { + buf[1]='0'; + flag_hash=1; + ++sz; + } + +num_printf: + s=buf+1; + + if (flag_long>0) { +#ifdef WANT_LONGLONG_PRINTF + if (flag_long>1) + llnumber=va_arg(arg_ptr,long long); + else +#endif + number=va_arg(arg_ptr,long); + } + else + number=va_arg(arg_ptr,int); + + if (flag_in_sign) { +#ifdef WANT_LONGLONG_PRINTF + if ((flag_long>1)&&(llnumber<0)) { + llnumber=-llnumber; + flag_in_sign=2; + } else +#endif + if (number<0) { + number=-number; + flag_in_sign=2; + } + } + if (flag_long<0) number&=0xffff; + if (flag_long<-1) number&=0xff; +#ifdef WANT_LONGLONG_PRINTF + if (flag_long>1) + sz += __lltostr(s+sz,sizeof(buf)-5,(unsigned long long) llnumber,base,flag_upcase); + else +#endif + sz += __ltostr(s+sz,sizeof(buf)-5,(unsigned long) number,base,flag_upcase); + + if (flag_in_sign==2) { + *(--s)='-'; + ++sz; + } else if ((flag_in_sign)&&(flag_sign || flag_space)) { + *(--s)=(flag_sign)?'+':' '; + ++sz; + } else flag_in_sign=0; + + goto print_out; + +#ifdef WANT_FLOATING_POINT_IN_PRINTF + /* print a floating point value */ + case 'f': + case 'g': + { + int g=(ch=='g'); + double d=va_arg(arg_ptr,double); + if (width==0) width=1; + if (!flag_dot) preci=6; + sz=__dtostr(d,buf,sizeof(buf),width,preci); + if (flag_dot) { + char *tmp; + if ((tmp=strchr(buf,'.'))) { + ++tmp; + while (preci>0 && *++tmp) --preci; + *tmp=0; + } + } + if (g) { + char *tmp,*tmp1; /* boy, is _this_ ugly! */ + if ((tmp=strchr(buf,'.'))) { + tmp1=strchr(tmp,'e'); + while (*tmp) ++tmp; + if (tmp1) tmp=tmp1; + while (*--tmp=='0') ; + if (*tmp!='.') ++tmp; + *tmp=0; + if (tmp1) strcpy(tmp,tmp1); + } + } + preci=strlen(buf); + s=buf; + + goto print_out; + } +#endif + + default: + break; + } + } + } + return len; +} + +link_warning("__v_printf","warning: the printf functions add several kilobytes of bloat.") + diff --git a/mdk-stage1/dietlibc/lib/__v_scanf.c b/mdk-stage1/dietlibc/lib/__v_scanf.c new file mode 100644 index 000000000..6db51db59 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/__v_scanf.c @@ -0,0 +1,391 @@ +#include "dietfeatures.h" +#include +#include +#include +#include +#include +#include + +#include "dietstdio.h" +#include "dietwarning.h" + +#define A_GETC(fn) (++consumed,(fn)->getch((fn)->data)) +#define A_PUTC(c,fn) (--consumed,(fn)->putch((c),(fn)->data)) + +int __v_scanf(struct arg_scanf* fn, const unsigned char *format, va_list arg_ptr) +{ + unsigned int ch; /* format act. char */ + int n=0; + + /* arg_ptr tmps */ +#ifdef WANT_FLOATING_POINT_IN_SCANF + double *pd; + float *pf; +#endif +#ifdef WANT_LONGLONG_SCANF + long long *pll; +#endif + long *pl; + short *ph; + int *pi; + char *s; + + unsigned int consumed=0; + + /* get one char */ + int tpch= A_GETC(fn); + + //while ((tpch!=-1)&&(*format)) + while (*format) + { +// const unsigned char *prev_fmt=format; + ch=*format++; + switch (ch) { + /* end of format string ?!? */ + case 0: return 0; + + /* skip spaces ... */ + case ' ': + case '\f': + case '\t': + case '\v': + case '\n': + case '\r': + while((*format)&&(isspace(*format))) ++format; + while(isspace(tpch)) tpch=A_GETC(fn); + break; + + /* format string ... */ + case '%': + { + unsigned int _div=0; + int width=-1; + char flag_width=0; + char flag_discard=0; + char flag_half=0; + char flag_long=0; + char flag_longlong=0; + +in_scan: + ch=*format++; + if(ch!='n' && tpch==-1) goto err_out; + switch (ch) { + /* end of format string ?!? */ + case 0: return 0; + + /* check for % */ + case '%': + if ((unsigned char)tpch != ch) goto err_out; + tpch=A_GETC(fn); + break; + + /* FLAGS */ + case '*': + flag_discard=1; + goto in_scan; + case 'h': + flag_half=1; + goto in_scan; + case 'l': + if (flag_long) flag_longlong=1; + flag_long=1; + goto in_scan; + case 'q': + case 'L': + flag_longlong=1; + goto in_scan; + + /* WIDTH */ + case '0': + 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 in_scan; + + /* scan for integer / strtol reimplementation ... */ + case 'p': + case 'X': + case 'x': + _div+=6; + case 'd': + _div+=2; + case 'o': + _div+=8; + case 'u': + case 'i': + { +#ifdef WANT_LONGLONG_SCANF + unsigned long long v=0; +#else + unsigned long v=0; +#endif + unsigned int consumedsofar=consumed; + int neg=0; + while(isspace(tpch)) tpch=A_GETC(fn); + if (tpch=='-') { + tpch=A_GETC(fn); + neg=1; + } + + if (tpch=='+') tpch=A_GETC(fn); + + if (!flag_width) { + if ((_div==16) && (tpch=='0')) goto scan_hex; + if (!_div) { + _div=10; + if (tpch=='0') { + _div=8; +scan_hex: + tpch=A_GETC(fn); + if ((tpch|32)=='x') { + tpch=A_GETC(fn); + _div=16; + } + } + } + } + while ((width)&&(tpch!=-1)) { + register unsigned long c=tpch&0xff; +#ifdef WANT_LONGLONG_SCANF + register unsigned long long d=c|0x20; +#else + register unsigned long d=c|0x20; +#endif + c=(d>='a'?d-'a'+10:c<='9'?c-'0':0xff); + if (c>=_div) break; + d=v*_div; +#ifdef WANT_LONGLONG_SCANF + v=(d=-((unsigned long long)LLONG_MIN)) { + l=(neg)?LLONG_MIN:LLONG_MAX; + } + else { + if (neg) v*=-1; + } +#else + register long l=v; + if (v>=-((unsigned long)LONG_MIN)) { + l=(neg)?LONG_MIN:LONG_MAX; + } + else { + if (neg) v*=-1; + } +#endif + } + if (!flag_discard) { +#ifdef WANT_LONGLONG_SCANF + if (flag_longlong) { + pll=(long long *)va_arg(arg_ptr,long long*); + *pll=v; + } else +#endif + if (flag_long) { + pl=(long *)va_arg(arg_ptr,long*); + *pl=v; + } else if (flag_half) { + ph=(short*)va_arg(arg_ptr,short*); + *ph=v; + } else { + pi=(int *)va_arg(arg_ptr,int*); + *pi=v; + } + if(consumedsofar=0) && (cset[tpch]^flag_not)) { + if (!flag_discard) *s=tpch; + if (tpch) ++s; else break; + --width; + tpch=A_GETC(fn); + } + if (!flag_discard) *s=0; + ++format; + } + break; +#endif + default: + goto err_out; + } + } + break; + + /* check if equal format string... */ + default: + if ((unsigned char)tpch != ch) goto err_out; + tpch=A_GETC(fn); + break; + } + } +err_out: + if (tpch<0 && n==0) return EOF; + A_PUTC(tpch,fn); + return n; +} + +link_warning("__v_scanf","warning: the scanf functions add several kilobytes of bloat."); diff --git a/mdk-stage1/dietlibc/lib/adjtime.c b/mdk-stage1/dietlibc/lib/adjtime.c new file mode 100644 index 000000000..b8986be57 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/adjtime.c @@ -0,0 +1,18 @@ +#include +#include + +int adjtime (const struct timeval *itv, struct timeval *otv) { + struct timex tmp; + if (itv) { + tmp.offset = (itv->tv_usec % 1000000L) + (itv->tv_sec + itv->tv_usec / 1000000L) * 1000000L; + tmp.modes = ADJ_OFFSET_SINGLESHOT; + } else + tmp.modes = 0; + if (adjtimex(&tmp)==-1) + return -1; + if (otv) { + otv->tv_usec = tmp.offset % 1000000; + otv->tv_sec = tmp.offset / 1000000; + } + return 0; +} diff --git a/mdk-stage1/dietlibc/lib/atoll.c b/mdk-stage1/dietlibc/lib/atoll.c new file mode 100644 index 000000000..7bf2b2fd6 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/atoll.c @@ -0,0 +1,19 @@ +#include +#include +#include + +#if __WORDSIZE != 64 +long long int atoll(const char* s) { + long long int v=0; + int sign=1; + while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s; + switch (*s) { + case '-': sign=-1; + case '+': ++s; + } + while ((unsigned int) (*s - '0') < 10u) { + v=v*10+*s-'0'; ++s; + } + return sign==-1?-v:v; +} +#endif diff --git a/mdk-stage1/dietlibc/lib/bcd.c b/mdk-stage1/dietlibc/lib/bcd.c new file mode 100644 index 000000000..1936b82f6 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/bcd.c @@ -0,0 +1,185 @@ + +static long double powers [] = { + 1.e+1, 1.e+2, 1.e+4, 1.e+8, 1.e+16, 1.e+32, 1.e+64, 1.e+128, 1.e+256 +}; + +/* + * So, die ist zum Zerlegen von Gleitkommazahlen am besten geeignet. + * + * Die nichtnegative übergebende Gleitkommazahl number wird in einen + * Exponenten e und eine Mantisse m zerlegt mit: + * + * 1 <= m < 10 + * number = m * 10^e + * + * Die Mantisse wird in precision Dezimalstellen zerlegt, die nach digits + * geschrieben werden. digits[0] ist die Vorkommastelle, digits [1 ... + * precision-1] die Nachkommastellen der Mantisse Zurückgeliefert wird der + * Exponent. + * + * Für precision ist ein Wert von 0 erlaubt, Sinn machen allerdings erst + * Werte ab 1. + */ + +int __decompose_floatp ( long double number, + unsigned char* digits, unsigned int precision ); + +int __decompose_floatp ( long double number, + unsigned char* digits, unsigned int precision ) +{ + int ret = 0; + int i; + double tmp; + + if ( number > 0.L ) { + + // Exponent abtrennen + if ( number >= 10.L ) { + for ( i = sizeof(powers)/sizeof(*powers)-1; i >= 0; i--) + if ( number >= powers [i] ) { + number /= powers [i]; + ret += 1 << i; + } + } else if ( number < 1.L ) + for ( i = sizeof(powers)/sizeof(*powers)-1; i >= 0; i--) + if ( number * powers [i] < 10.L ) { + number *= powers [i]; + ret -= 1 << i; + } + + // Runden (ohne Geradezahlregel => Bug) + tmp = 5.; + { + unsigned int j; + for ( j = 0; j < precision; j++ ) + tmp *= 0.1; + } + + number += tmp; + + // Dabei kann die Zahl in die nächste Dekade reinrutschen ... + if ( number >= 10.L ) { + number = 1.L; + ret++; + } + } + + // Mantisse in ASCII konvertieren + while ( precision-- ) { + i = (int) number; + number = (number - i) * 10.L; + *digits++ = '0' + i; + } + + // Exponent zurück + return ret; +} + + +/* + * So, die ist zum Zerlegen von Festkommazahlen am besten geeignet. + * + * Die nichtnegative übergebende Festkomma wird in einen Integeranteil und + * einen Bruchanteil zerlegt. + * + * Der Bruchanteil wird in digits_frac[0...precision_frac-1] gespeichert, + * falls precision_frac != 0 ist. + * + * Der Integeranteil wird ab digits_int + precision_int - 1 rückwrts + * geschrieben. Zurückgeliefert wird ein Zeiger auf das erste Zeichen, das + * bei der Konvertierung != '0' ist (Ausnahme ist die 0.0 selbst). Zeichen + * zwischen digits_int und diesem Zeiger (exklusive des Zeichens unter dem + * Zeiger) sind unbestimmt. Wünscht man dort Nullen oder Leerzeichen, + * sollte man mittels memset() dieses vorher initialsieren. + */ + +char* __decompose_fixp ( long double number, + unsigned char* digits_int , unsigned int precision_int, + unsigned char* digits_frac, unsigned int precision_frac ); + +char* __decompose_fixp ( long double number, + unsigned char* digits_int , unsigned int precision_int, + unsigned char* digits_frac, unsigned int precision_frac ) +{ + long long int integer; + double tmp; + int i; + + // Runden (ohne Geradezahlregel => Bug) + tmp = 0.5; + { + unsigned int j; + for ( j = 0; j < precision_frac; j++ ) + tmp *= 0.1; + } + + number += tmp; + + integer = number; + number -= integer; + + // Nachkommastellen + while ( precision_frac-- ) { + number *= 10.L; + i = (int) number; + number -= i; + *digits_frac++ + = '0' + i; + } + + // Vorkommastellen + while ( precision_int ) { + i = (int) (integer % 10); + integer /= 10; + digits_int [--precision_int] + = '0' + i; + if ( integer == 0 ) + break; + } + + return digits_int + precision_int; +} + + +#if 0 + +#include +#include + +long double test [] = { + 1, M_PI, 123, 123456789, 12345678901234567, 1e300, 0.00123456789, 1.234567890123456e-300, 0 +}; + +int main ( void ) +{ + int i; + int j; + int k; + char buff1 [32]; + char buff2 [32]; + char* retp; + int ret; + + for ( i = 0; i < sizeof(test)/sizeof(*test); i++ ) { + printf ("\n*** %30.20Lf ***\n\n", test[i] ); + + for ( j = 0; j <= 20; j++ ) { + memset ( buff1, 0, sizeof(buff1) ); + ret = __decompose_floatp ( test[i], buff1, j ); + printf ( "floatp(%2u) = <%sE%+d>\n", j, buff1, ret ); + } + for ( j = 0; j <= 20; j++ ) { + for ( k = 0; k <= 20; k++ ) { + memset ( buff1, 0, sizeof(buff1) ); + memset ( buff2, 0, sizeof(buff2) ); + retp = __decompose_fixp ( test[i], buff1, j, buff2, k ); + printf ( "fixp(%2u,%2u) = <%s.%s>\n", j, k, retp, buff2 ); + } + } + + } + + return 0; +} + +#endif diff --git a/mdk-stage1/dietlibc/lib/binshstr.c b/mdk-stage1/dietlibc/lib/binshstr.c new file mode 100644 index 000000000..814297e3d --- /dev/null +++ b/mdk-stage1/dietlibc/lib/binshstr.c @@ -0,0 +1,5 @@ +#include "binshstr.h" + +const char __binsh [] = "/bin/sh"; + +/* end of binshstr.c */ diff --git a/mdk-stage1/dietlibc/lib/cfgetospeed.c b/mdk-stage1/dietlibc/lib/cfgetospeed.c new file mode 100644 index 000000000..c330352b2 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/cfgetospeed.c @@ -0,0 +1,8 @@ +#include +#include + +speed_t cfgetospeed(struct termios *termios_p) { + return ((termios_p->c_cflag & (CBAUD|CBAUDEX))); +} + +speed_t cfgetispeed(struct termios *termios_p) __attribute__((weak,alias("cfgetospeed"))); diff --git a/mdk-stage1/dietlibc/lib/cfsetispeed.c b/mdk-stage1/dietlibc/lib/cfsetispeed.c new file mode 100644 index 000000000..ab0333853 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/cfsetispeed.c @@ -0,0 +1,22 @@ +#include +#include +#include "dietfeatures.h" + +#define IBAUD0 020000000000 + +int cfsetispeed(struct termios *termios_p, speed_t speed) +{ + if ((speed & (speed_t)~CBAUD) != 0 && (speed < B57600 || speed > B460800)) { + errno=EINVAL; + return -1; + } + if (speed == 0) + termios_p->c_iflag |= IBAUD0; + else { + termios_p->c_iflag &= ~IBAUD0; + termios_p->c_cflag &= ~(CBAUD | CBAUDEX); + termios_p->c_cflag |= speed; + } + return 0; +} + diff --git a/mdk-stage1/dietlibc/lib/cfsetospeed.c b/mdk-stage1/dietlibc/lib/cfsetospeed.c new file mode 100644 index 000000000..d1aee3595 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/cfsetospeed.c @@ -0,0 +1,14 @@ +#include +#include +#include "dietfeatures.h" + +int cfsetospeed(struct termios *termios_p, speed_t speed) { + if ((speed & (speed_t)~CBAUD) != 0 && (speed < B57600 || speed > B460800)) { + errno=EINVAL; + return -1; + } + termios_p->c_cflag &= ~(CBAUD | CBAUDEX); + termios_p->c_cflag |= speed; + return 0; +} + diff --git a/mdk-stage1/dietlibc/lib/errlistu.c b/mdk-stage1/dietlibc/lib/errlistu.c new file mode 100644 index 000000000..15e38807b --- /dev/null +++ b/mdk-stage1/dietlibc/lib/errlistu.c @@ -0,0 +1,6 @@ +/* + * used by perror() and strerror() + */ + +const char __sys_err_unknown [] = "[unknown error]"; + diff --git a/mdk-stage1/dietlibc/lib/execle.c b/mdk-stage1/dietlibc/lib/execle.c new file mode 100644 index 000000000..6d05c48a0 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/execle.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include "dietfeatures.h" + +int execle( const char *path,...) { + va_list ap; + int n,i; + char **argv,*tmp, **env; + 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 + +struct if_nameindex* if_nameindex(void) { + struct ifconf ic; + int fd,len,i; + struct if_nameindex* x,* y; + char *dest; + fd=socket(AF_INET6,SOCK_DGRAM,0); + if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); + ic.ifc_buf=0; + ic.ifc_len=0; + if (ioctl(fd,SIOCGIFCONF,&ic)<0) { +b0rken: + close(fd); + return 0; + } + ic.ifc_buf=alloca((size_t)ic.ifc_len); + if (ioctl(fd,SIOCGIFCONF,&ic)<0) goto b0rken; + len=(ic.ifc_len/sizeof(struct ifreq)); + x=(struct if_nameindex*)malloc((len+1)*sizeof(struct if_nameindex)+len*IFNAMSIZ); + if (!x) goto b0rken; + dest=(char*)(x+len+1); + y=x; + for (i=0; iif_name=dest; + memcpy(dest,ir->ifr_name,IFNAMSIZ); + if (ioctl(fd,SIOCGIFINDEX,ir)==-1) continue; + y->if_index=ir->ifr_ifindex; + dest+=IFNAMSIZ; + ++y; + } + y->if_name=0; y->if_index=0; + return x; +} diff --git a/mdk-stage1/dietlibc/lib/ipv6constants.c b/mdk-stage1/dietlibc/lib/ipv6constants.c new file mode 100644 index 000000000..1d5cb1f08 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/ipv6constants.c @@ -0,0 +1,4 @@ +#include "netinet/in.h" + +const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; +const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; diff --git a/mdk-stage1/dietlibc/lib/labs.c b/mdk-stage1/dietlibc/lib/labs.c new file mode 100644 index 000000000..364557f40 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/labs.c @@ -0,0 +1,6 @@ +#include + +#if __WORDSIZE == 64 +long int labs(long int i) { return i>=0?i:-i; } +long long int llabs(long long int i) __attribute__((alias("labs"))); +#endif diff --git a/mdk-stage1/dietlibc/lib/llabs.c b/mdk-stage1/dietlibc/lib/llabs.c new file mode 100644 index 000000000..bcbd3dc78 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/llabs.c @@ -0,0 +1,6 @@ +#include +#include + +#if __WORDSIZE != 64 +long long int llabs(long long int i) { if (i<0) i=-i; return i; } +#endif diff --git a/mdk-stage1/dietlibc/lib/memmem.c b/mdk-stage1/dietlibc/lib/memmem.c new file mode 100644 index 000000000..5c88a29e7 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memmem.c @@ -0,0 +1,14 @@ +#define _GNU_SOURCE 23 +#include +#include + +void *memmem(const void* haystack, size_t hl, const void* needle, size_t nl) { + 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/memrchr.c b/mdk-stage1/dietlibc/lib/memrchr.c new file mode 100644 index 000000000..f7750d2d7 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/memrchr.c @@ -0,0 +1,15 @@ +#define _GNU_SOURCE +#include +#include + +void* memrchr(const void *s, int c, size_t n) { + register const char* t=s; + register const char* last=0; + int i; + for (i=n; i; --i) { + if (*t==c) + last=t; + ++t; + } + return (void*)last; /* man, what an utterly b0rken prototype */ +} diff --git a/mdk-stage1/dietlibc/lib/pwrite.c b/mdk-stage1/dietlibc/lib/pwrite.c new file mode 100644 index 000000000..1e9fde545 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/pwrite.c @@ -0,0 +1,11 @@ +#include +#include + +extern size_t __pwrite(int fd, void *buf, size_t count, off_t a,off_t b); + +size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset); +size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset) { + return __pwrite(fd,buf,count,offset,0); +} + +int pwrite(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pwrite"))); diff --git a/mdk-stage1/dietlibc/lib/pwrite64.c b/mdk-stage1/dietlibc/lib/pwrite64.c new file mode 100644 index 000000000..cac46024a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/pwrite64.c @@ -0,0 +1,14 @@ +#include +#include +#include + +#ifndef __NO_STAT64 +extern size_t __pwrite(int fd, void *buf, size_t count, off_t a,off_t b); + +size_t __libc_pwrite64(int fd, void *buf, size_t count, off64_t offset); +size_t __libc_pwrite64(int fd, void *buf, size_t count, off64_t offset) { + return __pwrite(fd,buf,count,__LONG_LONG_PAIR ((off_t)(offset&0xffffffff),(off_t)(offset>>32))); +} + +int pwrite64(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pwrite64"))); +#endif diff --git a/mdk-stage1/dietlibc/lib/rand48.c b/mdk-stage1/dietlibc/lib/rand48.c new file mode 100644 index 000000000..9c6cfcda2 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/rand48.c @@ -0,0 +1,89 @@ +#include + +static randbuf rand48buf; +#define A_0 0xE66D +#define A_1 0xDEEC +#define A_2 0x5 +#define C 0xB +static randbuf a = { A_0, A_1, A_2 }; +static unsigned short c = C; + +static void calc_next(randbuf buf) { + randbuf tmp; + long t; + t = buf[0] * a[0] + c; + tmp[0] = t & 0xffff; + tmp[1] = (t >> 16) & 0xffff; + t = buf[1] * a[0] + buf[0] * a[1] + tmp[1]; + tmp[1] = t & 0xffff; + tmp[2] = (t >> 16) & 0xffff; + t = buf[2] * a[0] + buf[1] * a[1] + buf[0] * a[2] + tmp[2]; + tmp[2] = t & 0xffff; + buf[0] = tmp[0]; + buf[1] = tmp[1]; + buf[2] = tmp[2]; +} + +double drand48(void) { + return erand48(rand48buf); +} + +long lrand48(void) { + return nrand48(rand48buf); +} + +long mrand48(void) { + return jrand48(rand48buf); +} + +void srand48(long seed) { + rand48buf[1] = (seed >> 16) & 0xffff; + rand48buf[2] = seed & 0xffff; + rand48buf[0] = 0x330e; + a[0] = A_0; + a[1] = A_1; + a[2] = A_2; + c = C; +} + +unsigned short *seed48(randbuf buf) { + static randbuf oldx; + int i; + for (i = 0; i < 3; i++) { + oldx[i] = rand48buf[i]; + rand48buf[i] = buf[i]; + } + a[0] = A_0; + a[1] = A_1; + a[2] = A_2; + c = C; + return (unsigned short *)&oldx; +} + +void lcong48(unsigned short param[7]) { + int i; + for (i = 0; i < 3; i++) { + rand48buf[i] = param[i]; + a[i] = param[i + 3]; + } + c = param[6]; +} + +long jrand48(randbuf buf) { + long ret; + ret = buf[2] << 16 | buf[1]; + calc_next(buf); + return ret; +} + +long nrand48(randbuf buf) { + return jrand48(buf) & 0x7FFFFFFFL; +} + +double erand48(randbuf buf) { + double ret; + ret = ((buf[0] / 65536.0 + buf[1]) / 65536.0 + buf[2]) / 65536.0; + calc_next(buf); + return ret; +} + diff --git a/mdk-stage1/dietlibc/lib/rand_r.c b/mdk-stage1/dietlibc/lib/rand_r.c new file mode 100644 index 000000000..55f8303bc --- /dev/null +++ b/mdk-stage1/dietlibc/lib/rand_r.c @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002 Luc Van Oostenryck + + This is free software. You can redistribute and + modify it under the terms of the GNU General Public + Public License. +*/ + +#include +#include + +/* Knuth's TAOCP section 3.6 */ +#define M ((1U<<31) -1) +#define A 48271 +#define Q 44488 // M/A +#define R 3399 // M%A; R < Q !!! + +// FIXME: ISO C/SuS want a longer period + +int rand_r(unsigned int* seed) +{ int32_t X; + + X = *seed; + X = A*(X%Q) - R * (int32_t) (X/Q); + if (X < 0) + X += M; + + *seed = X; + return X; +} diff --git a/mdk-stage1/dietlibc/lib/readdir64.c b/mdk-stage1/dietlibc/lib/readdir64.c new file mode 100644 index 000000000..b9b0aafcc --- /dev/null +++ b/mdk-stage1/dietlibc/lib/readdir64.c @@ -0,0 +1,62 @@ +#include "dietfeatures.h" +#include "dietdirent.h" +#include +#include +#include +#include +#include +#include "syscalls.h" + +#ifndef __NR_getdents64 +#define WANT_LARGEFILE_BACKCOMPAT +#endif + +#ifndef WANT_LARGEFILE_BACKCOMPAT +struct dirent64* readdir64(DIR *d) { + if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) { + int res=getdents64(d->fd,(struct dirent64*)d->buf, sizeof (d->buf)-1); + if (res<=0) return 0; + d->num=res; d->cur=0; + } + return (struct dirent64*)(d->buf+d->cur); +} +#else +struct dirent64* readdir64(DIR *d) { +#ifdef __NR_getdents64 + static int trygetdents64=1; +#endif + struct dirent* o; + static struct dirent64 d64; +again: +#ifdef __NR_getdents64 + if (!trygetdents64) { +#endif + if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) { + int res=getdents(d->fd,(struct dirent*)d->buf, sizeof (d->buf)-1); + if (res<=0) return 0; + d->num=res; d->cur=0; + } + o=(struct dirent*)(d->buf+d->cur); + d64.d_ino=o->d_ino; + d64.d_off=o->d_off; + d64.d_reclen=o->d_reclen; + strcpy(d64.d_name,o->d_name); + d64.d_type=0; /* is this correct? */ + return &d64; +#ifdef __NR_getdents64 + } + if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) { + int res=getdents64(d->fd,(struct dirent64*)d->buf,sizeof (d->buf)); + if (res<=0) { + if (errno==ENOSYS) { + trygetdents64=0; + goto again; + } + return 0; + } + d->num=res; d->cur=0; + } + return (struct dirent64*)(d->buf+d->cur); +#endif +} +#endif diff --git a/mdk-stage1/dietlibc/lib/setlinebuf.c b/mdk-stage1/dietlibc/lib/setlinebuf.c new file mode 100644 index 000000000..1f30e183a --- /dev/null +++ b/mdk-stage1/dietlibc/lib/setlinebuf.c @@ -0,0 +1,12 @@ +#include +#include "dietwarning.h" +#undef setlinebuf + +/* there is no previous prototype because it is a #define */ +void setlinebuf(FILE* stream); + +void setlinebuf(FILE* stream) { + setvbuf(stream,0,_IOLBF,BUFSIZ); +} + +link_warning("setlinebuf","warning: you used setlinebuf without including ") diff --git a/mdk-stage1/dietlibc/lib/sigaction.c b/mdk-stage1/dietlibc/lib/sigaction.c new file mode 100644 index 000000000..fe1351f0f --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigaction.c @@ -0,0 +1,11 @@ +#include + +int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr); + +int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); +int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { + return __rt_sigaction(signum, act, oldact, _NSIG/8); +} + +int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) +__attribute__((weak,alias("__libc_sigaction"))); diff --git a/mdk-stage1/dietlibc/lib/siginterrupt.c b/mdk-stage1/dietlibc/lib/siginterrupt.c new file mode 100644 index 000000000..8926f09ed --- /dev/null +++ b/mdk-stage1/dietlibc/lib/siginterrupt.c @@ -0,0 +1,17 @@ +#include + +int siginterrupt(int sig, int flag) { + int ret; + struct sigaction act; + + sigaction(sig, 0, &act); + + if (flag) + act.sa_flags &= ~SA_RESTART; + else + act.sa_flags |= SA_RESTART; + + ret = sigaction(sig, &act, 0); + + return ret; +} diff --git a/mdk-stage1/dietlibc/lib/signal.c b/mdk-stage1/dietlibc/lib/signal.c new file mode 100644 index 000000000..51441558e --- /dev/null +++ b/mdk-stage1/dietlibc/lib/signal.c @@ -0,0 +1,12 @@ +#include + +sighandler_t signal(int signum, sighandler_t action) { + struct sigaction sa,oa; + sa.sa_handler=action; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask,signum); + sa.sa_flags=SA_NODEFER; + if (sigaction(signum,&sa,&oa)) + return SIG_ERR; + return oa.sa_handler; +} diff --git a/mdk-stage1/dietlibc/lib/sigpending.c b/mdk-stage1/dietlibc/lib/sigpending.c new file mode 100644 index 000000000..62a4761c6 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigpending.c @@ -0,0 +1,7 @@ +#include + +int __rt_sigpending(sigset_t *set, long nr); + +int sigpending(sigset_t *set) { + return __rt_sigpending(set, _NSIG/8); +} diff --git a/mdk-stage1/dietlibc/lib/sigprocmask.c b/mdk-stage1/dietlibc/lib/sigprocmask.c new file mode 100644 index 000000000..6d770c3d3 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigprocmask.c @@ -0,0 +1,7 @@ +#include + +int __rt_sigprocmask(int how, const sigset_t *set, sigset_t *oldsetm, long nr); + +int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) { + return __rt_sigprocmask(how, set, oldset, _NSIG/8); +} diff --git a/mdk-stage1/dietlibc/lib/sigqueueinfo.c b/mdk-stage1/dietlibc/lib/sigqueueinfo.c new file mode 100644 index 000000000..adb7349f4 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigqueueinfo.c @@ -0,0 +1,7 @@ +#include + +int __rt_sigqueueinfo(int pid, int sig, siginfo_t *info); + +int sigqueueinfo(int pid, int sig, siginfo_t *info) { + return __rt_sigqueueinfo(pid, sig, info); +} diff --git a/mdk-stage1/dietlibc/lib/sigsuspend.c b/mdk-stage1/dietlibc/lib/sigsuspend.c new file mode 100644 index 000000000..a020789e9 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigsuspend.c @@ -0,0 +1,10 @@ +#include + +int __rt_sigsuspend(const sigset_t *mask, long nr); + +int __libc_sigsuspend(const sigset_t *mask); +int __libc_sigsuspend(const sigset_t *mask) { + return __rt_sigsuspend(mask, _NSIG/8); +} + +int sigsuspend(const sigset_t *mask) __attribute__((weak,alias("__libc_sigsuspend"))); diff --git a/mdk-stage1/dietlibc/lib/sigtimedwait.c b/mdk-stage1/dietlibc/lib/sigtimedwait.c new file mode 100644 index 000000000..864e433c3 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/sigtimedwait.c @@ -0,0 +1,7 @@ +#include + +int __rt_sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *ts, long nr); + +int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *ts) { + return __rt_sigtimedwait(set,info,ts,_NSIG/8); +} diff --git a/mdk-stage1/dietlibc/lib/socketpair.c b/mdk-stage1/dietlibc/lib/socketpair.c new file mode 100644 index 000000000..e6f1fd822 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/socketpair.c @@ -0,0 +1,12 @@ +#include + +extern int socketcall(int callno,long* args); + +int __libc_socketpair(int a, int type, int protocol, int sv[2]); +int __libc_socketpair(int a, int type, int protocol, int sv[2]) { + unsigned long args[] = { a, type, protocol, (long)sv }; + return socketcall(SYS_SOCKETPAIR, args); +} + +int socketpair(int d, int type, int protocol, int sv[2]) + __attribute__((weak,alias("__libc_socketpair"))); diff --git a/mdk-stage1/dietlibc/lib/strtof.c b/mdk-stage1/dietlibc/lib/strtof.c new file mode 100644 index 000000000..acb081e51 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtof.c @@ -0,0 +1,66 @@ +#include +#include +#include + +float strtof(const char* s, char** endptr) { + register const char* p = s; + register float value = 0.; + int sign = +1; + float factor; + unsigned int expo; + + while ( isspace(*p) ) + p++; + + switch (*p) { + case '-': sign = -1; + case '+': p++; + default : break; + } + + while ( (unsigned int)(*p - '0') < 10u ) + value = value*10 + (*p++ - '0'); + + if ( *p == '.' ) { + factor = 1.; + + p++; + while ( (unsigned int)(*p - '0') < 10u ) { + factor *= 0.1; + value += (*p++ - '0') * factor; + } + } + + if ( (*p | 32) == 'e' ) { + expo = 0; + factor = 10.L; + + switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' folgenden MUSS. + case '-': factor = 0.1; + case '+': p++; + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + break; + default : value = 0.L; + p = s; + goto done; + } + + while ( (unsigned int)(*p - '0') < 10u ) + expo = 10 * expo + (*p++ - '0'); + + while ( 1 ) { + if ( expo & 1 ) + value *= factor; + if ( (expo >>= 1) == 0 ) + break; + factor *= factor; + } + } + +done: + if ( endptr != NULL ) + *endptr = (char*)p; + + return value * sign; +} diff --git a/mdk-stage1/dietlibc/lib/strtold.c b/mdk-stage1/dietlibc/lib/strtold.c new file mode 100644 index 000000000..ae5f0fa48 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strtold.c @@ -0,0 +1,66 @@ +#include +#include +#include + +long double strtold(const char* s, char** endptr) { + register const char* p = s; + register long double value = 0.L; + int sign = +1; + long double factor; + unsigned int expo; + + while ( isspace(*p) ) + p++; + + switch (*p) { + case '-': sign = -1; + case '+': p++; + default : break; + } + + while ( (unsigned int)(*p - '0') < 10u ) + value = value*10 + (*p++ - '0'); + + if ( *p == '.' ) { + factor = 1.; + + p++; + while ( (unsigned int)(*p - '0') < 10u ) { + factor *= 0.1; + value += (*p++ - '0') * factor; + } + } + + if ( (*p | 32) == 'e' ) { + expo = 0; + factor = 10.L; + + switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' folgenden MUSS. + case '-': factor = 0.1; + case '+': p++; + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + break; + default : value = 0.L; + p = s; + goto done; + } + + while ( (unsigned int)(*p - '0') < 10u ) + expo = 10 * expo + (*p++ - '0'); + + while ( 1 ) { + if ( expo & 1 ) + value *= factor; + if ( (expo >>= 1) == 0 ) + break; + factor *= factor; + } + } + +done: + if ( endptr != NULL ) + *endptr = (char*)p; + + return value * sign; +} diff --git a/mdk-stage1/dietlibc/lib/strxfrm.c b/mdk-stage1/dietlibc/lib/strxfrm.c new file mode 100644 index 000000000..5075ff0b5 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/strxfrm.c @@ -0,0 +1,12 @@ +#include +#include +#include "dietfeatures.h" + +size_t strxfrm(char *dest, const char *src, size_t n) { +#ifdef WANT_FULL_POSIX_COMPAT + memset(dest,0,n); +#endif + memccpy(dest,src,0,n); + return strlen(dest); +} + diff --git a/mdk-stage1/dietlibc/lib/tcflow.c b/mdk-stage1/dietlibc/lib/tcflow.c new file mode 100644 index 000000000..ea460f362 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/tcflow.c @@ -0,0 +1,35 @@ +#include "dietfeatures.h" +#include +#include +#include + +int tcflow ( int fd, int action ) +{ +#if TCOOFF==0 && TCOON==1 && TCIOFF==2 && TCION==3 + + if ( (unsigned int)action < 4u ) + return ioctl ( fd, TCXONC, action ); + + errno = EINVAL; + return -1; + +#else + + int arg = 0; + + switch (action) { + case TCION: + arg++; + case TCIOFF: + arg++; + case TCOON: + arg++; + case TCOOFF: + return ioctl ( fd, TCXONC, arg ); + default: + errno = EINVAL; + return -1; + } + +#endif +} diff --git a/mdk-stage1/dietlibc/lib/tcsendbreak.c b/mdk-stage1/dietlibc/lib/tcsendbreak.c new file mode 100644 index 000000000..b026340cf --- /dev/null +++ b/mdk-stage1/dietlibc/lib/tcsendbreak.c @@ -0,0 +1,11 @@ +#include "dietfeatures.h" +#include +#include +#include + +int tcsendbreak (int fd,int duration) +{ + if (duration <= 0) return (ioctl (fd,TCSBRKP,0)); + errno = EINVAL; + return (-1); +} diff --git a/mdk-stage1/dietlibc/lib/write12.c b/mdk-stage1/dietlibc/lib/write12.c new file mode 100644 index 000000000..8e0130bfb --- /dev/null +++ b/mdk-stage1/dietlibc/lib/write12.c @@ -0,0 +1,11 @@ +#include +#include +#include + +int __write1 (const char* s) { + return write(1, s, strlen(s)); +} + +int __write2 (const char* s) { + return write(2, s, strlen(s)); +} -- cgit v1.2.1