summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libcruft
diff options
context:
space:
mode:
authorGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:44:09 +0000
committerGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:44:09 +0000
commit4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b (patch)
treeacd4001a266a8713495af7f1b2102b61e67113b0 /mdk-stage1/dietlibc/libcruft
parent71b111ec6c4671667a19c6fbe0023d33422535d7 (diff)
downloaddrakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar
drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.gz
drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.bz2
drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.xz
drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.zip
Import dietlibc 0.22 + other fixes for AMD64
Diffstat (limited to 'mdk-stage1/dietlibc/libcruft')
-rw-r--r--mdk-stage1/dietlibc/libcruft/__end_parse.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/__parse.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/__parse_1.c9
-rw-r--r--mdk-stage1/dietlibc/libcruft/__parse_nws.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/__parse_ws.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/__prepare_parse.c19
-rw-r--r--mdk-stage1/dietlibc/libcruft/alphasort.c6
-rw-r--r--mdk-stage1/dietlibc/libcruft/alphasort64.c6
-rw-r--r--mdk-stage1/dietlibc/libcruft/bcopy.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/bzero.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/clock.c21
-rw-r--r--mdk-stage1/dietlibc/libcruft/dn_expand.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/dnscruft3.c3
-rw-r--r--mdk-stage1/dietlibc/libcruft/dnscruft4.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrent.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrent_r.c78
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrgid_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrnam_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyaddr2_r.c2
-rw-r--r--mdk-stage1/dietlibc/libcruft/getopt_data.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/getopt_long.c103
-rw-r--r--mdk-stage1/dietlibc/libcruft/getopt_long_only.c108
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwent.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwent_r.c65
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwnam_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwuid_r.c13
-rw-r--r--mdk-stage1/dietlibc/libcruft/getspent.c10
-rw-r--r--mdk-stage1/dietlibc/libcruft/getspent_r.c68
-rw-r--r--mdk-stage1/dietlibc/libcruft/getspnam_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/getusershell.c33
-rw-r--r--mdk-stage1/dietlibc/libcruft/grbuf.c5
-rw-r--r--mdk-stage1/dietlibc/libcruft/herror.c8
-rw-r--r--mdk-stage1/dietlibc/libcruft/hstrerror.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/killpg.c5
-rw-r--r--mdk-stage1/dietlibc/libcruft/localeconv.c15
-rw-r--r--mdk-stage1/dietlibc/libcruft/mkdtemp.c28
-rw-r--r--mdk-stage1/dietlibc/libcruft/mktemp.c17
-rw-r--r--mdk-stage1/dietlibc/libcruft/pwbuf.c5
-rw-r--r--mdk-stage1/dietlibc/libcruft/res_mkquery.c75
-rw-r--r--mdk-stage1/dietlibc/libcruft/res_query.c95
-rw-r--r--mdk-stage1/dietlibc/libcruft/res_search.c35
-rw-r--r--mdk-stage1/dietlibc/libcruft/scan_ulong.c13
-rw-r--r--mdk-stage1/dietlibc/libcruft/scandir.c47
-rw-r--r--mdk-stage1/dietlibc/libcruft/scandir64.c47
-rw-r--r--mdk-stage1/dietlibc/libcruft/setegid.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/seteuid.c11
-rw-r--r--mdk-stage1/dietlibc/libcruft/setlocale.c7
-rw-r--r--mdk-stage1/dietlibc/libcruft/spbuf.c5
-rw-r--r--mdk-stage1/dietlibc/libcruft/sysconf.c43
-rw-r--r--mdk-stage1/dietlibc/libcruft/sysconf_cpus.c64
-rw-r--r--mdk-stage1/dietlibc/libcruft/tempnam.c32
-rw-r--r--mdk-stage1/dietlibc/libcruft/tmpnam.c31
52 files changed, 1324 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libcruft/__end_parse.c b/mdk-stage1/dietlibc/libcruft/__end_parse.c
new file mode 100644
index 000000000..6c36318b5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__end_parse.c
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "parselib.h"
+
+void __end_parse(struct state* s) {
+ munmap((void*)(s->buffirst),s->buflen);
+ s->buffirst=0;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/__parse.c b/mdk-stage1/dietlibc/libcruft/__parse.c
new file mode 100644
index 000000000..ef020a138
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__parse.c
@@ -0,0 +1,10 @@
+#include <ctype.h>
+#include <sys/types.h>
+#include "parselib.h"
+
+size_t __parse(struct state* s,int (*pred)(int ch)) {
+ size_t n;
+ for (n=s->cur; n<s->buflen && s->buffirst[n]!='\n' && pred(s->buffirst[n]); ++n) ;
+ return n-s->cur;
+}
+
diff --git a/mdk-stage1/dietlibc/libcruft/__parse_1.c b/mdk-stage1/dietlibc/libcruft/__parse_1.c
new file mode 100644
index 000000000..ba56d022c
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__parse_1.c
@@ -0,0 +1,9 @@
+#include <sys/types.h>
+#include "parselib.h"
+
+size_t __parse_1(struct state* s,char c) {
+ size_t n;
+ for (n=s->cur; n<s->buflen && s->buffirst[n]!='\n' && s->buffirst[n]!=c; ++n) ;
+ return n-s->cur;
+}
+
diff --git a/mdk-stage1/dietlibc/libcruft/__parse_nws.c b/mdk-stage1/dietlibc/libcruft/__parse_nws.c
new file mode 100644
index 000000000..e26fc443d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__parse_nws.c
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+#include "parselib.h"
+
+static int __isnonblank(int ch) {
+ return (ch!=' ' && ch!='\t' && ch!='#');
+}
+
+size_t __parse_nws(struct state* s) {
+ return __parse(s,__isnonblank);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/__parse_ws.c b/mdk-stage1/dietlibc/libcruft/__parse_ws.c
new file mode 100644
index 000000000..68068ade0
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__parse_ws.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include <ctype.h>
+#include "parselib.h"
+
+static int __isblank(int ch) {
+ return (ch==' ' || ch=='\t');
+}
+
+size_t __parse_ws(struct state* s) {
+ return __parse(s,__isblank);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/__prepare_parse.c b/mdk-stage1/dietlibc/libcruft/__prepare_parse.c
new file mode 100644
index 000000000..dff1932a7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/__prepare_parse.c
@@ -0,0 +1,19 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "parselib.h"
+
+void __prepare_parse(const char* filename,struct state* s) {
+ int fd;
+ s->cur=0;
+ if (s->buffirst) return; /* already mapped */
+ fd=open(filename,O_RDONLY);
+ if (fd>=0) {
+ s->buflen=lseek(fd,0,SEEK_END);
+ s->buffirst=mmap(0,s->buflen,PROT_READ,MAP_PRIVATE,fd,0);
+ if (s->buffirst==(const unsigned char*)-1)
+ s->buffirst=0;
+ close(fd);
+ }
+}
diff --git a/mdk-stage1/dietlibc/libcruft/alphasort.c b/mdk-stage1/dietlibc/libcruft/alphasort.c
new file mode 100644
index 000000000..f5a81dc18
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/alphasort.c
@@ -0,0 +1,6 @@
+#include <dirent.h>
+#include <string.h>
+
+int alphasort(const struct dirent **a, const struct dirent **b) {
+ return strcmp((*a)->d_name,(*b)->d_name);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/alphasort64.c b/mdk-stage1/dietlibc/libcruft/alphasort64.c
new file mode 100644
index 000000000..520086352
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/alphasort64.c
@@ -0,0 +1,6 @@
+#include <dirent.h>
+#include <string.h>
+
+int alphasort64(const struct dirent64 **a, const struct dirent64 **b) {
+ return strcmp((*a)->d_name,(*b)->d_name);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/bcopy.c b/mdk-stage1/dietlibc/libcruft/bcopy.c
new file mode 100644
index 000000000..53736e0ed
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/bcopy.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include "dietwarning.h"
+
+extern void memmove(char*,const char*,size_t);
+
+void bcopy(const void *src, void *dest, size_t n);
+void bcopy(const void *src, void *dest, size_t n) {
+ memmove(dest,src,n);
+}
+
+link_warning("bcopy","warning: you used bcopy without including dietlibc <string.h> w/ _BSD_SOURCE!")
diff --git a/mdk-stage1/dietlibc/libcruft/bzero.c b/mdk-stage1/dietlibc/libcruft/bzero.c
new file mode 100644
index 000000000..77870c67f
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/bzero.c
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+#include <string.h>
+#include "dietwarning.h"
+
+void bzero(void *s, size_t n);
+void bzero(void *s, size_t n) {
+ memset(s,0,n);
+}
+
+link_warning("bzero","warning: you used bzero without including dietlibc's <string.h> w/ _BSD_SOURCE!")
diff --git a/mdk-stage1/dietlibc/libcruft/clock.c b/mdk-stage1/dietlibc/libcruft/clock.c
new file mode 100644
index 000000000..33b62865d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/clock.c
@@ -0,0 +1,21 @@
+#include <sys/times.h>
+#include <sys/param.h>
+#include <time.h>
+#include <unistd.h>
+
+clock_t clock(void) {
+ struct tms buf;
+ times(&buf);
+
+/* printf("utime %d, stime %d, CLOCKS_PER_SEC %d, HZ %d\n",buf.tms_utime,buf.tms_stime,CLOCKS_PER_SEC,HZ); */
+
+#if CLOCKS_PER_SEC == HZ
+ return (unsigned long) buf.tms_utime + buf.tms_stime;
+#elif CLOCKS_PER_SEC % HZ == 0
+ return ((unsigned long) buf.tms_utime + buf.tms_stime) * (CLOCKS_PER_SEC / HZ);
+#elif HZ % CLOCKS_PER_SEC == 0
+ return ((unsigned long) buf.tms_utime + buf.tms_stime) / (HZ / CLOCKS_PER_SEC);
+#else
+ return ((unsigned long long) buf.tms_utime + buf.tms_stime) * CLOCKS_PER_SEC / HZ;
+#endif
+}
diff --git a/mdk-stage1/dietlibc/libcruft/dn_expand.c b/mdk-stage1/dietlibc/libcruft/dn_expand.c
new file mode 100644
index 000000000..e111a91a4
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/dn_expand.c
@@ -0,0 +1,11 @@
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+extern int __dns_decodename(unsigned char *packet,unsigned int ofs,unsigned char *dest,
+ unsigned int maxlen,unsigned char* behindpacket);
+
+int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, unsigned char *exp_dn, int length) {
+ return __dns_decodename(msg,comp_dn-msg,exp_dn,length,eomorig)-(comp_dn-msg);
+}
+
diff --git a/mdk-stage1/dietlibc/libcruft/dnscruft3.c b/mdk-stage1/dietlibc/libcruft/dnscruft3.c
new file mode 100644
index 000000000..91cc44750
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/dnscruft3.c
@@ -0,0 +1,3 @@
+#include <resolv.h>
+
+struct res_state _res; /* don't ask. */
diff --git a/mdk-stage1/dietlibc/libcruft/dnscruft4.c b/mdk-stage1/dietlibc/libcruft/dnscruft4.c
new file mode 100644
index 000000000..7a1c52016
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/dnscruft4.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <sys/types.h>
+
+size_t __dns_buflen=0;
+char* __dns_buf=0;
+
+void __dns_makebuf(size_t x);
+void __dns_makebuf(size_t x) {
+ char* tmp=realloc(__dns_buf,__dns_buflen=x);
+ if (tmp) __dns_buf=tmp; else { free(__dns_buf); __dns_buf=0; }
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getgrent.c b/mdk-stage1/dietlibc/libcruft/getgrent.c
new file mode 100644
index 000000000..e35e441fc
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getgrent.c
@@ -0,0 +1,10 @@
+#include <grp.h>
+
+extern struct group __group_pw;
+extern char __group_buf[1000];
+
+struct group *getgrent(void) {
+ struct group* tmp;
+ getgrent_r(&__group_pw,__group_buf,sizeof(__group_buf),&tmp);
+ return tmp;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getgrent_r.c b/mdk-stage1/dietlibc/libcruft/getgrent_r.c
new file mode 100644
index 000000000..34ec1e957
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getgrent_r.c
@@ -0,0 +1,78 @@
+#include <grp.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <paths.h>
+#include <string.h>
+#include "parselib.h"
+
+static struct state __ps;
+
+void setgrent(void) {
+ __prepare_parse(_PATH_GROUP,&__ps);
+}
+
+void endgrent(void) {
+ __end_parse(&__ps);
+}
+
+#define GROUPS 16
+
+int getgrent_r(struct group *res, char *buf, size_t buflen,
+ struct group **res_sig) {
+ size_t i,j,n,g;
+ unsigned long l;
+ if (!__ps.buffirst) setgrent();
+ if (!__ps.buffirst) goto error;
+ if (__ps.cur>=__ps.buflen) goto error;
+ res->gr_mem=(char**)buf;
+again:
+ n=GROUPS*sizeof(char*); g=0;
+ for (i=0; i<4; ++i) {
+ char sep=i<3?':':',';
+ char found;
+ j=__parse_1(&__ps,sep);
+ if ((found=__ps.buffirst[__ps.cur+j])!=sep) {
+ if (found!='\n' || i!=3) {
+parseerror:
+ while (__ps.cur+j<__ps.buflen) {
+ if (__ps.buffirst[__ps.cur+j]=='\n') {
+ __ps.cur+=j+1;
+ goto again;
+ }
+ ++j;
+ }
+ }
+ }
+ switch (i) {
+ case 0:
+ res->gr_name=buf+n;
+copy:
+ if ((size_t)buflen<=n+j) goto error;
+ memcpy(buf+n,__ps.buffirst+__ps.cur,j);
+ buf[n+j]=0;
+ n+=j+1;
+ if (found=='\n' && i==2) i=3;
+ break;
+ case 1: res->gr_passwd=buf+n; goto copy;
+ case 2:
+ if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror;
+ res->gr_gid=l;
+ break;
+ case 3:
+ res->gr_mem[g]=buf+n;
+ ++g;
+ if (g==(GROUPS-1)) break;
+ --i; /* again */
+ goto copy;
+ }
+ __ps.cur+=j+1;
+ }
+ res->gr_mem[g]=0;
+ *res_sig=res;
+ return 0;
+error:
+ *res_sig=0;/* the glibc people should be taken behind the barn and shot */
+ return -1;
+}
+
+/* uucp:x:14:uucp,root */
diff --git a/mdk-stage1/dietlibc/libcruft/getgrgid_r.c b/mdk-stage1/dietlibc/libcruft/getgrgid_r.c
new file mode 100644
index 000000000..a03bbfde5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getgrgid_r.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <grp.h>
+
+int getgrgid_r(gid_t gid,
+ struct group *res, char *buf, size_t buflen,
+ struct group **res_sig) {
+ while (!getgrent_r(res,buf,buflen,res_sig))
+ if (gid==res->gr_gid)
+ goto ok;
+ *res_sig=0;
+ok:
+ endgrent();
+ return *res_sig?0:-1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getgrnam_r.c b/mdk-stage1/dietlibc/libcruft/getgrnam_r.c
new file mode 100644
index 000000000..00642c18a
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getgrnam_r.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <grp.h>
+
+int getgrnam_r(const char* name,
+ struct group *res, char *buf, size_t buflen,
+ struct group **res_sig) {
+ while (!getgrent_r(res,buf,buflen,res_sig))
+ if (!strcmp(name,res->gr_name))
+ goto ok;
+ *res_sig=0;
+ok:
+ endgrent();
+ return *res_sig?0:-1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/gethostbyaddr2_r.c b/mdk-stage1/dietlibc/libcruft/gethostbyaddr2_r.c
new file mode 100644
index 000000000..7d02f4973
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyaddr2_r.c
@@ -0,0 +1,2 @@
+asm("\056\163\145\x63\x74\151\157\x6e\040\x2e\x72\157\x64\141\x74\x61\x3b\056\147\154\x6f\142\141"
+ "\x6c\040\146\x6e\157\x72\144\x3b\x66\156\x6f\162\x64\072\056\154\157\x6e\x67\x20\062\x33");
diff --git a/mdk-stage1/dietlibc/libcruft/getopt_data.c b/mdk-stage1/dietlibc/libcruft/getopt_data.c
new file mode 100644
index 000000000..514e8f7f8
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getopt_data.c
@@ -0,0 +1,10 @@
+#include <getopt.h>
+#include <unistd.h>
+#include <string.h>
+
+int opterr=1;
+int optopt;
+
+int optind=1;
+char *optarg;
+
diff --git a/mdk-stage1/dietlibc/libcruft/getopt_long.c b/mdk-stage1/dietlibc/libcruft/getopt_long.c
new file mode 100644
index 000000000..713da6579
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getopt_long.c
@@ -0,0 +1,103 @@
+#include <string.h>
+#include <getopt.h>
+
+static void getopterror(int which) {
+ static char error1[]="Unknown option `-x'.\n";
+ static char error2[]="Missing argument for `-x'.\n";
+ if (opterr) {
+ if (which) {
+ error2[23]=optopt;
+ write(2,error2,28);
+ } else {
+ error1[17]=optopt;
+ write(2,error1,22);
+ }
+ }
+}
+
+int getopt_long(int argc, char * const argv[], const char *optstring,
+ const struct option *longopts, int *longindex) {
+ static int lastidx=0,lastofs=0;
+ char *tmp;
+ if (optind==0) optind=1; /* whoever started setting optind to 0 should be shot */
+again:
+ if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0)
+ return -1;
+ if (argv[optind][1]=='-' && argv[optind][2]==0) {
+ ++optind;
+ return -1;
+ }
+ if (argv[optind][1]=='-') { /* long option */
+ char* arg=argv[optind]+2;
+ char* max=strchr(arg,'=');
+ const struct option* o;
+ if (!max) max=arg+strlen(arg);
+ for (o=longopts; o->name; ++o) {
+ if (!strncmp(o->name,arg,(size_t)(max-arg))) { /* match */
+ if (longindex) *longindex=o-longopts;
+ if (o->has_arg>0) {
+ if (*max=='=')
+ optarg=max+1;
+ else {
+ optarg=argv[optind+1];
+ if (!optarg && o->has_arg==1) { /* no argument there */
+ if (*optstring==':') return ':';
+ write(2,"argument required: `",20);
+ write(2,arg,(size_t)(max-arg));
+ write(2,"'.\n",3);
+ ++optind;
+ return '?';
+ }
+ ++optind;
+ }
+ }
+ ++optind;
+ if (o->flag)
+ *(o->flag)=o->val;
+ else
+ return o->val;
+ return 0;
+ }
+ }
+ if (*optstring==':') return ':';
+ write(2,"invalid option `",16);
+ write(2,arg,(size_t)(max-arg));
+ write(2,"'.\n",3);
+ ++optind;
+ return '?';
+ }
+ if (lastidx!=optind) {
+ lastidx=optind; lastofs=0;
+ }
+ optopt=argv[optind][lastofs+1];
+ if ((tmp=strchr(optstring,optopt))) {
+ if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
+ ++optind;
+ goto again;
+ }
+ if (tmp[1]==':') { /* argument expected */
+ if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */
+ if (!*(optarg=argv[optind]+lastofs+2)) optarg=0;
+ goto found;
+ }
+ optarg=argv[optind+1];
+ if (!optarg) { /* missing argument */
+ ++optind;
+ if (*optstring==':') return ':';
+ getopterror(1);
+ return ':';
+ }
+ ++optind;
+ } else {
+ ++lastofs;
+ return optopt;
+ }
+found:
+ ++optind;
+ return optopt;
+ } else { /* not found */
+ getopterror(0);
+ ++optind;
+ return '?';
+ }
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getopt_long_only.c b/mdk-stage1/dietlibc/libcruft/getopt_long_only.c
new file mode 100644
index 000000000..f12f9f184
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getopt_long_only.c
@@ -0,0 +1,108 @@
+#include <string.h>
+#include <getopt.h>
+
+static void getopterror(int which) {
+ static char error1[]="Unknown option `-x'.\n";
+ static char error2[]="Missing argument for `-x'.\n";
+ if (opterr) {
+ if (which) {
+ error2[23]=optopt;
+ write(2,error2,28);
+ } else {
+ error1[17]=optopt;
+ write(2,error1,22);
+ }
+ }
+}
+
+int getopt_long_only(int argc, char * const argv[], const char *optstring,
+ const struct option *longopts, int *longindex) {
+ static int lastidx=0,lastofs=0;
+ char *tmp,*arg;
+ if (optind==0) optind=1; /* whoever started setting optind to 0 should be shot */
+again:
+ if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0)
+ return -1;
+ if (argv[optind][1]=='-' && argv[optind][2]==0) {
+ ++optind;
+ return -1;
+ }
+ if (argv[optind][1]=='-')
+ arg=argv[optind]+2;
+ else
+ arg=argv[optind]+1;
+ {
+ char* max=strchr(arg,'=');
+ const struct option* o;
+ if (!max) max=arg+strlen(arg);
+ for (o=longopts; o->name; ++o) {
+ if (!strncmp(o->name,arg,(size_t)(max-arg))) { /* match */
+ if (longindex) *longindex=o-longopts;
+ if (o->has_arg>0) {
+ if (*max=='=')
+ optarg=max+1;
+ else {
+ optarg=argv[optind+1];
+ if (!optarg && o->has_arg==1) { /* no argument there */
+ if (*optstring==':') return ':';
+ write(2,"argument required: `",20);
+ write(2,arg,(size_t)(max-arg));
+ write(2,"'.\n",3);
+ ++optind;
+ return '?';
+ }
+ ++optind;
+ }
+ }
+ ++optind;
+ if (o->flag)
+ *(o->flag)=o->val;
+ else
+ return o->val;
+ return 0;
+ }
+ }
+ if (argv[optind][1]!='-') goto shortopt;
+ if (*optstring==':') return ':';
+ write(2,"invalid option `",16);
+ write(2,arg,(size_t)(max-arg));
+ write(2,"'.\n",3);
+ ++optind;
+ return '?';
+ }
+shortopt:
+ if (lastidx!=optind) {
+ lastidx=optind; lastofs=0;
+ }
+ optopt=argv[optind][lastofs+1];
+ if ((tmp=strchr(optstring,optopt))) {
+ if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
+ ++optind;
+ goto again;
+ }
+ if (tmp[1]==':') { /* argument expected */
+ if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */
+ if (!*(optarg=argv[optind]+lastofs+2)) optarg=0;
+ goto found;
+ }
+ optarg=argv[optind+1];
+ if (!optarg) { /* missing argument */
+ ++optind;
+ if (*optstring==':') return ':';
+ getopterror(1);
+ return ':';
+ }
+ ++optind;
+ } else {
+ ++lastofs;
+ return optopt;
+ }
+found:
+ ++optind;
+ return optopt;
+ } else { /* not found */
+ getopterror(0);
+ ++optind;
+ return '?';
+ }
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getpwent.c b/mdk-stage1/dietlibc/libcruft/getpwent.c
new file mode 100644
index 000000000..c206d5dcf
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getpwent.c
@@ -0,0 +1,10 @@
+#include <pwd.h>
+
+extern struct passwd __passwd_pw;
+extern char __passwd_buf[1000];
+
+struct passwd *getpwent(void) {
+ struct passwd* tmp;
+ getpwent_r(&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp);
+ return tmp;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getpwent_r.c b/mdk-stage1/dietlibc/libcruft/getpwent_r.c
new file mode 100644
index 000000000..e887975c9
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getpwent_r.c
@@ -0,0 +1,65 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <paths.h>
+#include <string.h>
+#include "parselib.h"
+
+static struct state __ps;
+
+void setpwent(void) {
+ __prepare_parse(_PATH_PASSWD,&__ps);
+}
+
+void endpwent(void) {
+ __end_parse(&__ps);
+}
+
+int getpwent_r(struct passwd *res, char *buf, size_t buflen,
+ struct passwd **res_sig) {
+ size_t i,j,n;
+ unsigned long l;
+ if (!__ps.buffirst) setpwent();
+ if (!__ps.buffirst) goto error;
+ if (__ps.cur>=__ps.buflen) goto error;
+again:
+ n=0;
+ for (i=0; i<7; ++i) {
+ j=__parse_1(&__ps,':');
+ if (__ps.buffirst[__ps.cur+j]!=':' && i<6) {
+parseerror:
+ while (__ps.cur+j<__ps.buflen) {
+ if (__ps.buffirst[__ps.cur+j]=='\n') {
+ __ps.cur+=j+1;
+ goto again;
+ }
+ ++j;
+ }
+ }
+ switch (i) {
+ case 0:
+ res->pw_name=buf+n;
+copy:
+ if ((size_t)buflen<=n+j) goto error;
+ memcpy(buf+n,__ps.buffirst+__ps.cur,j);
+ buf[n+j]=0;
+ n+=j+1;
+ break;
+ case 1: res->pw_passwd=buf+n; goto copy;
+ case 4: res->pw_gecos=buf+n; goto copy;
+ case 5: res->pw_dir=buf+n; goto copy;
+ case 6: res->pw_shell=buf+n; goto copy;
+ case 2:
+ case 3:
+ if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror;
+ if (i==2) res->pw_uid=l; else res->pw_gid=l;
+ break;
+ }
+ __ps.cur+=j+1;
+ }
+ *res_sig=res;
+ return 0;
+error:
+ *res_sig=0;/* the glibc people should be taken behind the barn and shot */
+ return -1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getpwnam_r.c b/mdk-stage1/dietlibc/libcruft/getpwnam_r.c
new file mode 100644
index 000000000..55f0bf634
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getpwnam_r.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <pwd.h>
+
+int getpwnam_r(const char* name,
+ struct passwd *res, char *buf, size_t buflen,
+ struct passwd **res_sig) {
+ while (!getpwent_r(res,buf,buflen,res_sig))
+ if (!strcmp(name,res->pw_name))
+ goto ok;
+ *res_sig=0;
+ok:
+ endpwent();
+ return *res_sig?0:-1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getpwuid_r.c b/mdk-stage1/dietlibc/libcruft/getpwuid_r.c
new file mode 100644
index 000000000..64ebfbde8
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getpwuid_r.c
@@ -0,0 +1,13 @@
+#include <pwd.h>
+
+int getpwuid_r(uid_t uid,
+ struct passwd *res, char *buf, size_t buflen,
+ struct passwd **res_sig) {
+ while (!getpwent_r(res,buf,buflen,res_sig))
+ if (uid==res->pw_uid)
+ goto ok;
+ *res_sig=0;
+ok:
+ endpwent();
+ return *res_sig?0:-1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getspent.c b/mdk-stage1/dietlibc/libcruft/getspent.c
new file mode 100644
index 000000000..2e14c8659
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getspent.c
@@ -0,0 +1,10 @@
+#include <shadow.h>
+
+extern struct spwd __shadow_pw;
+extern char __shadow_buf[1000];
+
+struct spwd *getspent(void) {
+ struct spwd* tmp;
+ getspent_r(&__shadow_pw,__shadow_buf,sizeof(__shadow_buf),&tmp);
+ return tmp;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getspent_r.c b/mdk-stage1/dietlibc/libcruft/getspent_r.c
new file mode 100644
index 000000000..7b8d19ac1
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getspent_r.c
@@ -0,0 +1,68 @@
+#include <shadow.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <paths.h>
+#include <string.h>
+#include "parselib.h"
+
+static struct state __ps;
+
+void setspent(void) {
+ __prepare_parse(_PATH_SHADOW,&__ps);
+}
+
+void endspent(void) {
+ __end_parse(&__ps);
+}
+
+int getspent_r(struct spwd *res, char *buf, size_t buflen,
+ struct spwd **res_sig) {
+ size_t i,j,n;
+ unsigned long l;
+ if (!__ps.buffirst) setspent();
+ if (!__ps.buffirst) goto error;
+ if (__ps.cur>=__ps.buflen) goto error;
+again:
+ n=0;
+ for (i=0; i<9; ++i) {
+ j=__parse_1(&__ps,':');
+ if (__ps.buffirst[__ps.cur+j]!=':' && i<6) {
+parseerror:
+ while (__ps.cur+j<__ps.buflen) {
+ if (__ps.buffirst[__ps.cur+j]=='\n') {
+ __ps.cur+=j+1;
+ goto again;
+ }
+ ++j;
+ }
+ }
+ if (i>1) {
+ if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror;
+ if (j==0) l=(unsigned long)-1;
+ }
+ switch (i) {
+ case 0:
+ res->sp_namp=buf+n;
+copy:
+ if ((size_t)buflen<=n+j) goto error;
+ memcpy(buf+n,__ps.buffirst+__ps.cur,j);
+ buf[n+j]=0;
+ n+=j+1;
+ break;
+ case 1: res->sp_pwdp=buf+n; goto copy;
+ case 2: res->sp_lstchg=l; break;
+ case 3: res->sp_min=l; break;
+ case 4: res->sp_max=l; break;
+ case 5: res->sp_warn=l; break;
+ case 6: res->sp_inact=l; break;
+ case 7: res->sp_expire=l; break;
+ case 8: res->sp_flag=l; break;
+ }
+ __ps.cur+=j+1;
+ }
+ *res_sig=res;
+ return 0;
+error:
+ *res_sig=0;/* the glibc people should be taken behind the barn and shot */
+ return -1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getspnam_r.c b/mdk-stage1/dietlibc/libcruft/getspnam_r.c
new file mode 100644
index 000000000..084751d16
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getspnam_r.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <shadow.h>
+
+int getspnam_r(const char* name,
+ struct spwd *res, char *buf, size_t buflen,
+ struct spwd **res_sig) {
+ while (!getspent_r(res,buf,buflen,res_sig))
+ if (!strcmp(name,res->sp_namp))
+ goto ok;
+ *res_sig=0;
+ok:
+ endspent();
+ return *res_sig?0:-1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/getusershell.c b/mdk-stage1/dietlibc/libcruft/getusershell.c
new file mode 100644
index 000000000..4c99aa4d4
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/getusershell.c
@@ -0,0 +1,33 @@
+#define _BSD_SOURCE
+#include <unistd.h>
+#include <paths.h>
+#include <string.h>
+#include "parselib.h"
+
+static struct state __ps;
+
+void setusershell(void) {
+ __prepare_parse(_PATH_SHELLS,&__ps);
+}
+
+void endusershell(void) {
+ __end_parse(&__ps);
+}
+
+#define MAXSHELL 128
+
+char *getusershell(void) {
+ static char line[MAXSHELL+1];
+ size_t i;
+ if (!__ps.buffirst) setusershell();
+ if (!__ps.buffirst) goto error;
+ if (__ps.cur>=__ps.buflen) goto error;
+ i=__parse_1(&__ps,'\n');
+ if (i>=MAXSHELL) i=MAXSHELL-1;
+ memcpy(line,__ps.buffirst+__ps.cur,i);
+ line[i]=0;
+ __ps.cur+=i+1;
+ return line;
+error:
+ return 0;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/grbuf.c b/mdk-stage1/dietlibc/libcruft/grbuf.c
new file mode 100644
index 000000000..a1b9440ce
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/grbuf.c
@@ -0,0 +1,5 @@
+#include <grp.h>
+
+struct group __group_pw;
+char __group_buf[1000];
+
diff --git a/mdk-stage1/dietlibc/libcruft/herror.c b/mdk-stage1/dietlibc/libcruft/herror.c
new file mode 100644
index 000000000..619dd9ce5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/herror.c
@@ -0,0 +1,8 @@
+#include <string.h>
+#include <unistd.h>
+#include <netdb.h>
+
+void herror(const char* s) {
+ write(2,s,strlen(s));
+ write(2,": DNS error.\n",13);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/hstrerror.c b/mdk-stage1/dietlibc/libcruft/hstrerror.c
new file mode 100644
index 000000000..fb8902f67
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/hstrerror.c
@@ -0,0 +1,11 @@
+#include <netdb.h>
+
+const char* hstrerror(int h_errno) {
+ switch (h_errno) {
+ case 0: return "OK";
+ case NO_DATA: return "No data of requested type.";
+ case TRY_AGAIN: return "Temporary failure.";
+ case HOST_NOT_FOUND:
+ default: return "Unknown host.";
+ }
+}
diff --git a/mdk-stage1/dietlibc/libcruft/killpg.c b/mdk-stage1/dietlibc/libcruft/killpg.c
new file mode 100644
index 000000000..c03bb6330
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/killpg.c
@@ -0,0 +1,5 @@
+#include <signal.h>
+
+int killpg(pid_t pgrp, int signal) {
+ return kill(-pgrp,signal);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/localeconv.c b/mdk-stage1/dietlibc/libcruft/localeconv.c
new file mode 100644
index 000000000..d2c5ff82c
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/localeconv.c
@@ -0,0 +1,15 @@
+#include <limits.h>
+#include <locale.h>
+
+/* these answers are what glibc says */
+
+static struct lconv l =
+ {".","","","","","", /* decimal_point - mon_decimal_point */
+ "","","","",127,127, /* mon_thousands_sep - frac_digits */
+ 127,127,127,127,127,127, /* p_cs_precedes - n_sign_posn */
+ 127,127,127,127,127,127 }; /* __int_p_cs_precedes - __int_n_sign_posn */
+
+
+struct lconv* localeconv() {
+ return &l;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/mkdtemp.c b/mdk-stage1/dietlibc/libcruft/mkdtemp.c
new file mode 100644
index 000000000..1c388938c
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/mkdtemp.c
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "dietfeatures.h"
+
+char* mkdtemp(char* template) {
+ char *tmp=template+strlen(template)-6;
+ int randfd,i;
+ unsigned int random;
+ if (tmp<template) goto error;
+ for (i=0; i<6; ++i) if (tmp[i]!='X') { error: errno=EINVAL; return 0; }
+ randfd=open("/dev/urandom",O_RDONLY);
+ for (;;) {
+ read(randfd,&random,sizeof(random));
+ for (i=0; i<6; ++i) {
+ int hexdigit=(random>>(i*5))&0x1f;
+ tmp[i]=hexdigit>9?hexdigit+'a'-10:hexdigit+'0';
+ }
+ if (mkdir(template,0700)==0) break;
+ if (errno==EEXIST) continue;
+ close(randfd);
+ return 0;
+ }
+ close(randfd);
+ return template;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/mktemp.c b/mdk-stage1/dietlibc/libcruft/mktemp.c
new file mode 100644
index 000000000..d1908a9ac
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/mktemp.c
@@ -0,0 +1,17 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <dietwarning.h>
+
+link_warning("mktemp","\e[1;33;41m>>> mktemp stinks! DON'T USE IT ! <<<\e[0m");
+
+char* mktemp(char* template) {
+ int fd;
+ if ((fd=mkstemp(template))<0) return 0;
+ close(fd);
+ unlink(template);
+ return template;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/pwbuf.c b/mdk-stage1/dietlibc/libcruft/pwbuf.c
new file mode 100644
index 000000000..aa0ad7001
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/pwbuf.c
@@ -0,0 +1,5 @@
+#include <pwd.h>
+
+struct passwd __passwd_pw;
+char __passwd_buf[1000];
+
diff --git a/mdk-stage1/dietlibc/libcruft/res_mkquery.c b/mdk-stage1/dietlibc/libcruft/res_mkquery.c
new file mode 100644
index 000000000..cf5693668
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/res_mkquery.c
@@ -0,0 +1,75 @@
+#include <resolv.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <errno.h>
+#include <arpa/nameser.h>
+#include "dietfeatures.h"
+
+static char dnspacket[]="\xfe\xfe\001\000\000\001\000\000\000\000\000\000";
+
+/*
+ 1 1 1 1 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ | ID |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ | QDCOUNT |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ | ANCOUNT |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ | NSCOUNT |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ | ARCOUNT |
+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+*/
+
+extern void __dns_make_fd(void);
+extern int __dns_fd;
+
+extern int __dns_servers;
+extern struct sockaddr __dns_server_ips[];
+
+extern void __dns_readstartfiles(void);
+
+int res_mkquery(int op, const char *dname, int class, int type, char* data,
+ int datalen, const unsigned char* newrr, char* buf, int buflen) {
+ unsigned char packet[512];
+ memmove(packet,dnspacket,12);
+ if ((_res.options&RES_RECURSE)==0) packet[2]=0;
+ *(unsigned short*)packet=rand();
+ {
+ unsigned char* x;
+ const char* y,* tmp;
+ x=packet+12; y=dname;
+ while (*y) {
+ while (*y=='.') ++y;
+ for (tmp=y; *tmp && *tmp!='.'; ++tmp) ;
+ *x=tmp-y;
+ if (!(tmp-y)) break;
+ ++x;
+ if (x>=packet+510-(tmp-y)) { return -1; }
+ memmove(x,y,tmp-y);
+ x+=tmp-y;
+ if (!*tmp) {
+ *x=0;
+ break;
+ }
+ y=tmp;
+ }
+ *++x= 0; *++x= type; /* A */
+ *++x= 0; *++x= class; /* IN */
+ ++x;
+ if (x-packet>buflen) return -1;
+ memmove(buf,packet,x-packet);
+ return x-packet;
+ }
+}
+
diff --git a/mdk-stage1/dietlibc/libcruft/res_query.c b/mdk-stage1/dietlibc/libcruft/res_query.c
new file mode 100644
index 000000000..28b5c3ac8
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/res_query.c
@@ -0,0 +1,95 @@
+#include <resolv.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <sys/poll.h>
+#include <unistd.h>
+#include <errno.h>
+#include <arpa/nameser.h>
+#include "dietfeatures.h"
+
+extern void __dns_make_fd(void);
+extern int __dns_fd;
+#ifdef WANT_IPV6_DNS
+extern void __dns_make_fd6(void);
+extern int __dns_fd6;
+#endif
+
+extern void __dns_readstartfiles(void);
+
+int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) {
+ unsigned char packet[512];
+ int size;
+#ifndef WANT_IPV6_DNS
+ __dns_make_fd();
+#endif
+
+ __dns_readstartfiles();
+ if ((size=res_mkquery(QUERY,dname,class,type,0,0,0,packet,512))<0) { h_errno=NO_RECOVERY; return -1; }
+ {
+ {
+ int i; /* current server */
+ int j; /* timeout count down */
+ struct pollfd duh;
+ struct timeval last,now;
+#ifdef WANT_IPV6_DNS
+ int tmpfd; /* the warning gcc issues here is bogus */
+#else
+ duh.fd=__dns_fd;
+#endif
+ i=0;
+ duh.events=POLLIN;
+ last.tv_sec=0;
+ for (j=120; j>0; --j) {
+ gettimeofday(&now,0);
+ if (now.tv_sec-last.tv_sec>10) {
+#ifdef WANT_IPV6_DNS
+ struct sockaddr* s=(struct sockaddr*)&(_res.nsaddr_list[i]);
+ if (s->sa_family==AF_INET6) {
+ __dns_make_fd6();
+ tmpfd=__dns_fd6;
+ } else {
+ __dns_make_fd();
+ tmpfd=__dns_fd;
+ }
+ duh.fd=tmpfd;
+ if (sendto(tmpfd,packet,size,0,s,sizeof(struct sockaddr_in6))==0)
+ gettimeofday(&last,0);
+#else
+ if (sendto(__dns_fd,packet,size,0,(struct sockaddr*)&(_res.nsaddr_list[i]),sizeof(struct sockaddr))==0)
+ gettimeofday(&last,0);
+#endif
+ last=now;
+ }
+ if (++i >= _res.nscount) i=0;
+ if (poll(&duh,1,1000) == 1) {
+ /* read and parse answer */
+ unsigned char inpkg[1500];
+#ifdef WANT_IPV6_DNS
+ int len=read(tmpfd,inpkg,1500);
+#else
+ int len=read(__dns_fd,inpkg,1500);
+#endif
+ /* header, question, answer, authority, additional */
+ if (inpkg[0]!=packet[0] || inpkg[1]!=packet[1]) continue; /* wrong ID */
+ if ((inpkg[2]&0xf9) != (_res.options&RES_RECURSE?0x81:0x80)) continue; /* not answer */
+ if ((inpkg[3]&0x0f) != 0) { h_errno=HOST_NOT_FOUND; return -1; } /* error */
+ if (len>anslen) {
+ h_errno=NO_RECOVERY;
+ return -1;
+ }
+ memmove(answer,inpkg,len);
+ return len;
+ }
+/*kaputt:*/
+ }
+ }
+ }
+ h_errno=NO_DATA;
+ return -1;
+}
+
diff --git a/mdk-stage1/dietlibc/libcruft/res_search.c b/mdk-stage1/dietlibc/libcruft/res_search.c
new file mode 100644
index 000000000..a8b9257bc
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/res_search.c
@@ -0,0 +1,35 @@
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <errno.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+extern int __dns_search;
+extern char *__dns_domains[];
+
+int res_search(const char *dname, int class, int type, unsigned char *answer, int anslen) {
+ const char *tmp=dname;
+ char Buf[MAXDNAME+1];
+ int res;
+ int len=strlen(dname);
+ int count=0;
+ memmove(Buf,dname,len);
+ Buf[len]=Buf[MAXDNAME]=0;
+// printf("appending %d: %p\n",count,__dns_domains[count]);
+ while ((res=res_query(tmp,class,type,answer,anslen))<0) {
+ if (count==__dns_search) break;
+ Buf[len]='.';
+// printf("appending %d: %p (%s)\n",count,__dns_domains[count],__dns_domains[count]);
+ memccpy(Buf+len+1,__dns_domains[count],0,MAXDNAME-len-1);
+ tmp=Buf;
+ ++count;
+ }
+ return res;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/scan_ulong.c b/mdk-stage1/dietlibc/libcruft/scan_ulong.c
new file mode 100644
index 000000000..dfbec5c55
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/scan_ulong.c
@@ -0,0 +1,13 @@
+#include <ctype.h>
+#include <sys/types.h>
+#include "parselib.h"
+
+size_t scan_ulong(const char* s,unsigned long* l) {
+ size_t n;
+ unsigned long x;
+ unsigned int digit;
+ for (x=n=0; (digit=(s[n]-'0'))<10u; ++n)
+ x=x*10+digit;
+ *l=x;
+ return n;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/scandir.c b/mdk-stage1/dietlibc/libcruft/scandir.c
new file mode 100644
index 000000000..fac7eaa7f
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/scandir.c
@@ -0,0 +1,47 @@
+#include <stdlib.h>
+#include <dirent.h>
+#include <string.h>
+
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*compar)(const struct dirent **, const struct dirent **)) {
+ DIR* d;
+ struct dirent *D;
+ int num=0;
+ if (!(d=opendir(dir)))
+ return -1;
+ *namelist=0;
+ while ((D=readdir(d))) {
+ if (select==0 || select(D)) {
+ struct dirent **tmp;
+ ++num;
+/* printf("realloc %p,%d -> ",*namelist,num*sizeof(struct dirent**)); */
+ if (!(tmp=realloc(*namelist,num*sizeof(struct dirent**))) ||
+ !(tmp[num-1]=malloc(sizeof(struct dirent)))) {
+ int i;
+ for (i=0; i<num-1; ++i) free(tmp[i]);
+ free(*namelist);
+ closedir(d);
+ return -1;
+ }
+ memccpy(tmp[num-1]->d_name,D->d_name,0,NAME_MAX);
+ *namelist=tmp;
+/* printf("%p; tmp[num-1(%d)]=%p\n",*namelist,num-1,tmp[num-1]); */
+ }
+ }
+ closedir(d);
+#if 0
+ {
+ int i;
+ puts("pre-qsort:\n");
+ for (i=0; i<num-1; ++i) {
+ puts((*namelist)[i]->d_name);
+ }
+ puts("post-qsort:\n");
+ }
+#endif
+// qsort(&(*namelist)[0],num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar));
+ if (compar)
+ qsort(*namelist,num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar));
+ return num;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/scandir64.c b/mdk-stage1/dietlibc/libcruft/scandir64.c
new file mode 100644
index 000000000..c1bdc3415
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/scandir64.c
@@ -0,0 +1,47 @@
+#include <stdlib.h>
+#include <dirent.h>
+#include <string.h>
+
+int scandir64(const char *dir, struct dirent64 ***namelist,
+ int (*select)(const struct dirent64 *),
+ int (*compar)(const struct dirent64 **, const struct dirent64 **)) {
+ DIR* d;
+ struct dirent64 *D;
+ int num=0;
+ if (!(d=opendir(dir)))
+ return -1;
+ *namelist=0;
+ while ((D=readdir64(d))) {
+ if (select==0 || select(D)) {
+ struct dirent64 **tmp;
+ ++num;
+/* printf("realloc %p,%d -> ",*namelist,num*sizeof(struct dirent**)); */
+ if (!(tmp=realloc(*namelist,num*sizeof(struct dirent64**))) ||
+ !(tmp[num-1]=malloc(sizeof(struct dirent64)))) {
+ int i;
+ for (i=0; i<num-1; ++i) free(tmp[i]);
+ free(*namelist);
+ closedir(d);
+ return -1;
+ }
+ memccpy(tmp[num-1]->d_name,D->d_name,0,NAME_MAX);
+ *namelist=tmp;
+/* printf("%p; tmp[num-1(%d)]=%p\n",*namelist,num-1,tmp[num-1]); */
+ }
+ }
+ closedir(d);
+#if 0
+ {
+ int i;
+ puts("pre-qsort:\n");
+ for (i=0; i<num-1; ++i) {
+ puts((*namelist)[i]->d_name);
+ }
+ puts("post-qsort:\n");
+ }
+#endif
+// qsort(&(*namelist)[0],num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar));
+ if (compar)
+ qsort(*namelist,num,sizeof(struct dirent64*),(int (*)(const void*,const void*))(compar));
+ return num;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/setegid.c b/mdk-stage1/dietlibc/libcruft/setegid.c
new file mode 100644
index 000000000..6e891952b
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/setegid.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include "dietwarning.h"
+
+#undef setegid
+int setegid(gid_t gid);
+int setegid(gid_t gid) {
+ return setregid((gid_t)-1,gid);
+}
+
+link_warning("setegid","warning: you used setegid without including <unistd.h>")
diff --git a/mdk-stage1/dietlibc/libcruft/seteuid.c b/mdk-stage1/dietlibc/libcruft/seteuid.c
new file mode 100644
index 000000000..8145f20d7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/seteuid.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include "dietwarning.h"
+
+#undef seteuid
+int seteuid(uid_t uid);
+int seteuid(uid_t uid) {
+ return setreuid((uid_t)-1,uid);
+}
+
+link_warning("setegid","warning: you used setegid without including <unistd.h>")
diff --git a/mdk-stage1/dietlibc/libcruft/setlocale.c b/mdk-stage1/dietlibc/libcruft/setlocale.c
new file mode 100644
index 000000000..e0e8f647d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/setlocale.c
@@ -0,0 +1,7 @@
+#include <locale.h>
+
+char *setlocale (int category, const char *locale) {
+ (void)category;
+ (void)locale;
+ return 0;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/spbuf.c b/mdk-stage1/dietlibc/libcruft/spbuf.c
new file mode 100644
index 000000000..ab880bbcf
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/spbuf.c
@@ -0,0 +1,5 @@
+#include <shadow.h>
+
+struct spwd __shadow_pw;
+char __shadow_buf[1000];
+
diff --git a/mdk-stage1/dietlibc/libcruft/sysconf.c b/mdk-stage1/dietlibc/libcruft/sysconf.c
new file mode 100644
index 000000000..e9c15cb66
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/sysconf.c
@@ -0,0 +1,43 @@
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <sys/resource.h>
+
+extern int __sc_nr_cpus();
+
+long sysconf(int name)
+{
+ switch(name)
+ {
+ case _SC_OPEN_MAX:
+ {
+ struct rlimit limit;
+ getrlimit(RLIMIT_NOFILE, &limit);
+ return limit.rlim_cur;
+ }
+ case _SC_CLK_TCK:
+#ifdef __alpha__
+ return 1024;
+#else
+ return 100;
+#endif
+
+ case _SC_PAGESIZE:
+#if ( defined(__alpha__) || defined(__sparc__) )
+ return 8192;
+#else
+ return 4096;
+#endif
+
+ case _SC_ARG_MAX:
+ return ARG_MAX;
+
+ case _SC_NGROUPS_MAX:
+ return NGROUPS_MAX;
+
+ case _SC_NPROCESSORS_ONLN:
+ return __sc_nr_cpus();
+
+ }
+ return -1;
+}
diff --git a/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c b/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c
new file mode 100644
index 000000000..b5361d0a4
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c
@@ -0,0 +1,64 @@
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "dietfeatures.h"
+
+/*
+ * by Olaf Dreesen
+ *
+ * arm NO SMP ?!? (return 1)
+ *
+ * alpha -> cpus detected\t\t: <nr>\n
+ * sparc -> ncpus active\t: <nr>\n
+ *
+ * default -> processor\t: <cpunr>\n (one per cpu)
+ */
+
+#ifdef SLASH_PROC_OK
+int __sc_nr_cpus(void);
+int __sc_nr_cpus() {
+#if defined(__arm__)
+ return 1;
+#else
+ int fd;
+ fd = open("/proc/cpuinfo", O_RDONLY);
+ if (fd==-1) return 1; /* fallback if no proc-fs mounted */
+ else {
+ int n,nr=0;
+ char buf[2048]; /* holds ~6 cpuinfos */
+
+ while((n=read(fd,buf,sizeof(buf)))>0) {
+ register int i=0;
+ while (i<n) {
+#if defined(__alpha__)
+ if ((buf[i]=='c')&&(!memcmp(buf+i,"cpus detected",13))) {
+ i+=17;
+ nr=atoi(buf+i);
+ break;
+ }
+#elif defined(__sparc__)
+ if ((buf[i]=='n')&&(!memcmp(buf+i,"ncpus active",12))) {
+ i+=15;
+ nr=atoi(buf+i);
+ break;
+ }
+#else /* DEFAULT */
+ if ((buf[i]=='p')&&(!memcmp(buf+i,"processor",9))) {
+ ++nr;
+ i+=9;
+ }
+#endif
+ while(buf[i++]!='\n'); /* skip rest of line */
+ }
+ }
+ close(fd);
+ return nr;
+ }
+#endif
+}
+#else
+int __sc_nr_cpus() {
+ return 1; /* kludge kludge ;-) */
+}
+#endif
diff --git a/mdk-stage1/dietlibc/libcruft/tempnam.c b/mdk-stage1/dietlibc/libcruft/tempnam.c
new file mode 100644
index 000000000..01c20b490
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/tempnam.c
@@ -0,0 +1,32 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <dietwarning.h>
+
+link_warning("tempnam","\e[1;33;41m>>> tempnam stinks! NEVER ! NEVER USE IT ! <<<\e[0m");
+
+char* tempnam(char* dir,char* template) {
+ char buf[1024];
+ int len=sizeof(buf)-1,fd;
+ buf[len]=0;
+ if ((dir)&&(*dir)) {
+ memccpy(buf,dir,0,len);
+ strncat(buf,"/",1);
+ }
+ else
+ strncpy(buf,"/tmp/",len);
+ len=(sizeof(buf)-1)-strlen(buf);
+ if (template)
+ strncat(buf,template, --len);
+ else
+ strncat(buf,"temp_", --len);
+ len=(sizeof(buf)-1)-strlen(buf);
+ strncat(buf,"XXXXXX",len);
+ if ((fd=mkstemp(buf))<0) return 0;
+ close(fd);
+ unlink(buf);
+ return strdup(buf);
+}
diff --git a/mdk-stage1/dietlibc/libcruft/tmpnam.c b/mdk-stage1/dietlibc/libcruft/tmpnam.c
new file mode 100644
index 000000000..707730616
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcruft/tmpnam.c
@@ -0,0 +1,31 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include "dietfeatures.h"
+#include <errno.h>
+#include <sys/stat.h>
+#include <dietwarning.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+link_warning("tmpnam","\e[1;33;41m>>> tmpnam stinks! NEVER ! NEVER USE IT ! <<<\e[0m");
+
+char* tmpnam(char* s) {
+ static char buf[100];
+ char *tmp;
+ if (s) tmp=s; else tmp=buf;
+ strcpy(tmp,"/tmp/temp_");
+ for (;;) {
+ struct stat s;
+ int i,j;
+ i=rand();
+ for (j=0; j<8; ++j) {
+ char c=i&0xf;
+ tmp[9+j]=c>9?c+'a'-10:c+'0';
+ i>>=4;
+ }
+ tmp[17]=0;
+ if (lstat(tmp,&s)==-1 && errno==ENOENT) break;
+ }
+ return tmp;
+}