summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libcruft
diff options
context:
space:
mode:
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/dnscruft.c132
-rw-r--r--mdk-stage1/dietlibc/libcruft/dnscruft2.c264
-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/entlib.c153
-rw-r--r--mdk-stage1/dietlibc/libcruft/entlib.h44
-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.c13
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrgid_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrnam.c13
-rw-r--r--mdk-stage1/dietlibc/libcruft/getgrnam_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyaddr.c37
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyaddr2_r.c2
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyaddr_r.c67
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyname.c39
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyname2.c40
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyname2_r.c35
-rw-r--r--mdk-stage1/dietlibc/libcruft/gethostbyname_r.c54
-rw-r--r--mdk-stage1/dietlibc/libcruft/getlogin.c3
-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/getpagesize.c1
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpass.c24
-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.c15
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwnam_r.c14
-rw-r--r--mdk-stage1/dietlibc/libcruft/getpwuid.c12
-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.c15
-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/grent.c54
-rw-r--r--mdk-stage1/dietlibc/libcruft/herrno_location.c9
-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/inet_aton.c2
-rw-r--r--mdk-stage1/dietlibc/libcruft/inet_ntoa.c2
-rw-r--r--mdk-stage1/dietlibc/libcruft/inet_ntop.c12
-rw-r--r--mdk-stage1/dietlibc/libcruft/inet_pton.c17
-rw-r--r--mdk-stage1/dietlibc/libcruft/initgroups.c3
-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/mkstemp.c14
-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/pwent.c43
-rw-r--r--mdk-stage1/dietlibc/libcruft/res_init.c6
-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/spent.c45
-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
81 files changed, 1814 insertions, 678 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/dnscruft.c b/mdk-stage1/dietlibc/libcruft/dnscruft.c
index d7a0efa50..bd8bee79a 100644
--- a/mdk-stage1/dietlibc/libcruft/dnscruft.c
+++ b/mdk-stage1/dietlibc/libcruft/dnscruft.c
@@ -7,51 +7,100 @@
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
+#include <resolv.h>
+#include <net/if.h>
+#include "dietfeatures.h"
int __dns_fd=-1;
+#ifdef WANT_IPV6_DNS
+int __dns_fd6=-1;
+#endif
-void __dns_make_fd() {
+/* the ad-hoc internal API from hell ;-) */
+void __dns_make_fd(void);
+void __dns_make_fd6(void);
+void __dns_readstartfiles(void);
+int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
+ unsigned int maxlen,unsigned char* behindpacket);
+
+void __dns_make_fd(void) {
int tmp;
struct sockaddr_in si;
- if (__dns_fd>0) return;
+ if (__dns_fd>=0) return;
tmp=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
- if (tmp<0) {
- perror("__dns_make_fd!socket");
- return;
- }
+ if (tmp<0) return;
si.sin_family=AF_INET;
si.sin_port=0;
si.sin_addr.s_addr=INADDR_ANY;
- if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) {
- perror("__dns_make_fd!bind");
- return;
- }
+ if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) return;
__dns_fd=tmp;
}
-int __dns_servers=0;
-struct sockaddr __dns_server_ips[8];
+#ifdef WANT_IPV6_DNS
+void __dns_make_fd6(void) {
+ int tmp;
+ struct sockaddr_in6 si;
+ if (__dns_fd6>=0) return;
+ tmp=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP);
+ if (tmp<0) return;
+ si.sin6_family=AF_INET6;
+ si.sin6_port=0;
+ memset(&si.sin6_addr,0,16);
+ if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) return;
+ __dns_fd6=tmp;
+}
+#endif
-int __dns_search=0;
+static int parsesockaddr(const char* c,void* x) {
+ struct sockaddr_in to;
+ if (inet_aton(c,&to.sin_addr)) {
+ to.sin_port=htons(53);
+ to.sin_family=AF_INET;
+ memmove(x,&to,sizeof(struct sockaddr_in_pad));
+ return 1;
+#ifdef WANT_IPV6_DNS
+ } else {
+ struct sockaddr_in6 to6;
+ char* d=strchr(c,'%');
+ to6.sin6_flowinfo=to6.sin6_scope_id=0;
+ if (d)
+ to6.sin6_scope_id=if_nametoindex(d+1);
+ if (inet_pton(AF_INET6,c,&to6.sin6_addr)) {
+ to6.sin6_port=htons(53);
+ to6.sin6_family=AF_INET6;
+ memmove(x,&to6,sizeof(struct sockaddr_in_pad));
+ return 1;
+ }
+#endif
+ }
+ return 0;
+}
+
+#ifdef WANT_FULL_RESOLV_CONF
+int __dns_search;
char *__dns_domains[8];
+#endif
-void __dns_readstartfiles() {
+void __dns_readstartfiles(void) {
int fd;
- char *buf=alloca(4096);
+ char __buf[4096];
+ char *buf=__buf;
int len;
- if (__dns_servers>0) return;
+ if (_res.nscount>0) return;
{
struct sockaddr_in to;
+#ifdef WANT_IPV6_DNS
+ struct sockaddr_in6 to6;
+#endif
char *cacheip=getenv("DNSCACHEIP");
- if (cacheip) {
- to.sin_port=htons(53);
- to.sin_family=AF_INET;
- if (inet_aton(cacheip,&to.sin_addr)) {
- memmove(__dns_server_ips,&to,sizeof(struct sockaddr));
- ++__dns_servers;
- }
- }
+#ifdef WANT_FULL_RESOLV_CONF
+ __dns_search=0;
+#endif
+ if (cacheip)
+ if (parsesockaddr(cacheip,_res.nsaddr_list))
+ ++_res.nscount;
}
+ _res.options=RES_RECURSE;
if ((fd=open("/etc/resolv.conf",O_RDONLY))<0) return;
len=read(fd,buf,4096);
close(fd);
@@ -65,21 +114,35 @@ void __dns_readstartfiles() {
{
char *tmp=buf;
struct sockaddr_in i;
+ char save;
while (buf<last && !isspace(*buf)) ++buf;
if (buf>=last) break;
+ save=*buf;
*buf=0;
- if (inet_aton(tmp,&i.sin_addr)) {
- i.sin_family=AF_INET;
- i.sin_port=htons(53);
- memmove(&__dns_server_ips[__dns_servers],&i,sizeof(struct sockaddr));
- if (__dns_servers<8) ++__dns_servers;
- }
+ if (parsesockaddr(tmp,&_res.nsaddr_list[_res.nscount]))
+ if (_res.nscount<MAXNS) ++_res.nscount;
+ *buf=save;
}
}
}
- if (!strncmp(buf,"search",6) || !strncmp(buf,"domain",6)) {
+#ifdef WANT_FULL_RESOLV_CONF
+ else if (!strncmp(buf,"search",6) || !strncmp(buf,"domain",6)) {
buf+=6;
+ while (buf<last && *buf!='\n') {
+ char save;
+ while (buf<last && (*buf==',' || isblank(*buf))) ++buf;
+ __dns_domains[__dns_search]=buf;
+ while (buf<last && (*buf=='.' || *buf=='-' || isalnum(*buf))) ++buf;
+ save=*buf;
+ if (buf<last) *buf=0;
+ if (__dns_domains[__dns_search]<buf &&
+ (__dns_domains[__dns_search]=strdup(__dns_domains[__dns_search])))
+ ++__dns_search;
+ if (buf<last) *buf=save;
+ }
+ continue;
}
+#endif
while (buf<last && *buf!='\n') ++buf;
while (buf<last && *buf=='\n') ++buf;
}
@@ -87,21 +150,24 @@ void __dns_readstartfiles() {
}
/* return length of decoded data or -1 */
-int __dns_decodename(unsigned char *packet,int offset,unsigned char *dest,int maxlen) {
+int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
+ unsigned int maxlen,unsigned char* behindpacket) {
unsigned char *tmp;
unsigned char *max=dest+maxlen;
unsigned char *after=packet+offset;
int ok=0;
for (tmp=after; maxlen>0&&*tmp; ) {
+ if (tmp>=behindpacket) return -1;
if ((*tmp>>6)==3) { /* goofy DNS decompression */
unsigned int ofs=((unsigned int)(*tmp&0x3f)<<8)|*(tmp+1);
- if (ofs>=offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */
+ if (ofs>=(unsigned int)offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */
if (after<tmp+2) after=tmp+2;
tmp=packet+ofs;
ok=0;
} else {
unsigned int duh;
if (dest+*tmp+1>max) return -1;
+ if (tmp+*tmp+1>=behindpacket) return -1;
for (duh=*tmp; duh>0; --duh)
*dest++=*++tmp;
*dest++='.'; ok=1;
diff --git a/mdk-stage1/dietlibc/libcruft/dnscruft2.c b/mdk-stage1/dietlibc/libcruft/dnscruft2.c
index b59207072..d4e132e42 100644
--- a/mdk-stage1/dietlibc/libcruft/dnscruft2.c
+++ b/mdk-stage1/dietlibc/libcruft/dnscruft2.c
@@ -8,178 +8,166 @@
#include <sys/poll.h>
#include <unistd.h>
#include <errno.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#include "dietfeatures.h"
+#include "dietdns.h"
-#include <stdio.h>
+extern void __dns_readstartfiles(void);
-extern int h_errno;
-
-static char dnspacket[]="\xfe\xfe\001\000\000\001\000\000\000\000\000\000";
-
-extern void __dns_make_fd();
-extern int __dns_fd;
-
-extern int __dns_servers;
-extern struct sockaddr __dns_server_ips[];
-
-extern void __dns_readstartfiles();
-
-extern int __dns_decodename(unsigned char *packet,int offset,unsigned char *dest,int maxlen);
+extern int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
+ unsigned int maxlen,unsigned char* behindpacket);
/* Oh boy, this interface sucks so badly, there are no words for it.
* Not one, not two, but _three_ error signalling methods! (*h_errnop
* nonzero? return value nonzero? *RESULT zero?) The glibc goons
* really outdid themselves with this one. */
+#ifdef WANT_FULL_RESOLV_CONF
+static int __dns_gethostbyx_r_inner(const char* name, struct hostent* result,
+ char *buf, size_t buflen,
+ struct hostent **RESULT, int *h_errnop, int lookfor);
+
+static int __dns_gethostbyx_r_inner(const char* name, struct hostent* result,
+ char *buf, size_t buflen,
+ struct hostent **RESULT, int *h_errnop, int lookfor) {
+#else
int __dns_gethostbyx_r(const char* name, struct hostent* result,
char *buf, size_t buflen,
struct hostent **RESULT, int *h_errnop, int lookfor) {
+#endif
int names,ips;
unsigned char *cur;
unsigned char *max;
- unsigned char packet[512];
- __dns_make_fd();
+ unsigned char inpkg[1500];
+ char* tmp;
+ int size;
if (lookfor==1) {
- result->h_aliases=(char**)(buf+8*4);
result->h_addrtype=AF_INET;
result->h_length=4;
- result->h_addr_list=(char**)buf;
} else {
- result->h_aliases=(char**)(buf+8*16);
result->h_addrtype=AF_INET6;
result->h_length=16;
- result->h_addr_list=(char**)buf;
}
+ result->h_aliases=(char**)(buf+8*sizeof(char*));
+ result->h_addr_list=(char**)buf;
result->h_aliases[0]=0;
cur=buf+16*sizeof(char*);
max=buf+buflen;
names=ips=0;
- memmove(packet,dnspacket,12);
- *(unsigned short*)packet=rand();
+ if ((size=res_query(name,C_IN,lookfor,inpkg,512))<0) {
+invalidpacket:
+ *h_errnop=HOST_NOT_FOUND;
+ return -1;
+ }
{
- unsigned char* x;
- const char* y,* tmp;
- x=packet+12; y=name;
- 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)) { *h_errnop=ERANGE; return 1; }
- memmove(x,y,tmp-y);
- x+=tmp-y;
- if (!*tmp) {
- *x=0;
- break;
- }
- y=tmp;
- }
- *++x= 0; *++x= lookfor; /* A */
- *++x= 0; *++x= 1; /* IN */
- ++x;
+ tmp=inpkg+12;
{
- int i; /* current server */
- int j; /* timeout count down */
- struct pollfd duh;
- i=0; j=30;
- __dns_readstartfiles();
- duh.fd=__dns_fd;
- duh.events=POLLIN;
- for (j=30; j>0; --j) {
- sendto(__dns_fd,packet,x-packet,0,(struct sockaddr*)&(__dns_server_ips[i]),sizeof(struct sockaddr));
- if (++i > __dns_servers) i=0;
- if (poll(&duh,1,1) == 1) {
- /* read and parse answer */
- unsigned char inpkg[1500];
- /*int len=*/ read(__dns_fd,inpkg,1500);
-#if 0
- {
- int tft=open("duh",0);
- read(tft,inpkg,1500);
- close(tft);
- }
-#endif
- /* header, question, answer, authority, additional */
- if (inpkg[0]!=packet[0] || inpkg[1]!=packet[1]) continue; /* wrong ID */
- if ((inpkg[2]&0xf9) != 0x81) continue; /* not answer */
- if ((inpkg[3]&0x0f) != 0) break; /* error */
- tmp=inpkg+12;
- {
- char name[257];
- unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5];
- while (q>0) {
- while (*tmp) tmp+=*tmp+1;
- tmp+=5;
- --q;
- }
- q=((unsigned short)inpkg[6]<<8)+inpkg[7];
- if (q<1) break;
- while (q>0) {
- int decofs=__dns_decodename(inpkg,tmp-(char*)inpkg,name,256);
- if (decofs<0) break;
- tmp=inpkg+decofs;
- --q;
- if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */
- tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */
- if (tmp[1]==5) { /* CNAME */
- tmp+=10;
- decofs=__dns_decodename(inpkg,tmp-(char*)inpkg,name,256);
- if (decofs<0) break;
- tmp=inpkg+decofs;
- } else
- break;
- continue;
- }
- tmp+=10; /* skip type, class, TTL and length */
- {
- int slen;
- if (lookfor==1 || lookfor==28) /* A or AAAA*/ {
- slen=strlen(name);
- if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return 1; }
- } else if (lookfor==12) /* PTR */ {
- decofs=__dns_decodename(inpkg,tmp-(char*)inpkg,name,256);
- if (decofs<0) break;
- tmp=inpkg+decofs;
- slen=strlen(name);
- } else
- slen=strlen(name);
- strcpy(cur,name);
- if (names==0)
- result->h_name=cur;
- else
- result->h_aliases[names-1]=cur;
- result->h_aliases[names]=0;
- ++names;
+ char Name[257];
+ unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5];
+ while (q>0) {
+ if (tmp>(char*)inpkg+size) goto invalidpacket;
+ while (*tmp) { tmp+=*tmp+1; if (tmp>(char*)inpkg+size) goto invalidpacket; }
+ tmp+=5;
+ --q;
+ }
+ if (tmp>(char*)inpkg+size) goto invalidpacket;
+ q=((unsigned short)inpkg[6]<<8)+inpkg[7];
+ if (q<1) goto nodata;
+ while (q>0) {
+ int decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=inpkg+decofs;
+ --q;
+ if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */
+ tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */
+ if (tmp[1]==5) { /* CNAME */
+ tmp+=10;
+ decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=inpkg+decofs;
+ } else
+ break;
+ continue;
+ }
+ tmp+=10; /* skip type, class, TTL and length */
+ {
+ int slen;
+ if (lookfor==1 || lookfor==28) /* A or AAAA*/ {
+ slen=strlen(Name);
+ if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return -1; }
+ } else if (lookfor==12) /* PTR */ {
+ decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=inpkg+decofs;
+ slen=strlen(Name);
+ } else
+ slen=strlen(Name);
+ strcpy(cur,Name);
+ if (names==0)
+ result->h_name=cur;
+ else
+ result->h_aliases[names-1]=cur;
+ result->h_aliases[names]=0;
+ if (names<8) ++names;
/* cur+=slen+1; */
- cur+=(slen|3)+1;
- result->h_addr_list[ips++] = cur;
- if (lookfor==1) /* A */ {
- *(int*)cur=*(int*)tmp;
- cur+=4;
- result->h_addr_list[ips]=0;
- } else if (lookfor==28) /* AAAA */ {
- {
- int i;
- for (i=0; i<16; ++i) cur[i]=tmp[i];
- }
- cur+=16;
- result->h_addr_list[ips]=0;
- }
- }
-/* puts(name); */
+ cur+=(slen|3)+1;
+ result->h_addr_list[ips++] = cur;
+ if (lookfor==1) /* A */ {
+ *(int*)cur=*(int*)tmp;
+ cur+=4;
+ result->h_addr_list[ips]=0;
+ } else if (lookfor==28) /* AAAA */ {
+ {
+ int k;
+ for (k=0; k<16; ++k) cur[k]=tmp[k];
}
+ cur+=16;
+ result->h_addr_list[ips]=0;
}
-/* printf("%d answers\n",((unsigned short)inpkg[6]<<8)+inpkg[7]);
- printf("ok\n");*/
- *h_errnop=0;
- *RESULT=result;
- return 0;
}
-/*kaputt:*/
+/* puts(Name); */
}
}
}
- return 1;
+ if (!names) {
+nodata:
+ *h_errnop=NO_DATA;
+ return -1;
+ }
+ *h_errnop=0;
+ *RESULT=result;
+ return 0;
+}
+
+#ifdef WANT_FULL_RESOLV_CONF
+extern int __dns_search;
+extern char *__dns_domains[];
+
+int __dns_gethostbyx_r(const char* name, struct hostent* result,
+ char *buf, size_t buflen,
+ struct hostent **RESULT, int *h_errnop, int lookfor) {
+ const char *tmp=name;
+ char Buf[MAXDNAME+1];
+ int res;
+ size_t len=strlen(name);
+ int count=0;
+ __dns_readstartfiles();
+ memmove(Buf,name,len);
+ Buf[len]=Buf[MAXDNAME]=0;
+// printf("appending %d: %p\n",count,__dns_domains[count]);
+ while ((res=__dns_gethostbyx_r_inner(tmp,result,buf,buflen,RESULT,h_errnop,lookfor))) {
+ if (res==-1 && *h_errnop!=HOST_NOT_FOUND) break;
+ 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;
}
+#endif
+
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/entlib.c b/mdk-stage1/dietlibc/libcruft/entlib.c
deleted file mode 100644
index f88b3f057..000000000
--- a/mdk-stage1/dietlibc/libcruft/entlib.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * dietlibc/lib/entlib.c - Generic delimited-line parsing library
- *
- * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
- *
- * This is a brand new implementation, based on the interface
- * described in man-pages-1.34-1mdk man pages package.
- */
-
-
-#include "entlib.h" /* this is our only include */
-
-
-/*
- * __ent_start
- *
- * Allocates and zeroes the module's state structure,
- * and open a handle to /etc/passwd.
- *
- * Returns -1 on failure and sets errno, or zero for success.
- */
-
-int __ent_start(const char *pathname, struct __ent_state **st_ref)
-{
- struct __ent_state *st;
-
- if (*st_ref)
- return 0;
-
- st = calloc(1, sizeof(*st));
- if (!st) {
- errno = ENOMEM;
- return -1;
- }
-
- st->fd = open(pathname, O_RDONLY);
- if (st->fd == -1) {
- /* errno should have been set by open(2) */
- free(st);
- st = NULL;
- return -1;
- }
-
- *st_ref = st;
- return 0;
-}
-
-
-/*
- * __ent_get_line
- *
- * Eliminates a previous line from the buffer, if any.
- * Then reads in a new line from /etc/passwd, if necessary.
- *
- * Returns -1 on failure, or zero for success.
- */
-
-int __ent_get_line(struct __ent_state *st)
-{
- int rc;
-
- /* overwrite previous line, by shifting the rest
- * of the rest to the front of the buffer
- */
- if (st->bufptr) {
- unsigned int slop = st->buflen - st->bufptr;
- memmove(st->ent_buf, &st->ent_buf[st->bufptr], slop);
- st->bufptr = 0;
- st->buflen = slop;
- st->ent_buf[st->buflen] = 0; /* null terminate */
- }
-
- if (st->buflen == __ENT_BUFSIZ || strchr(st->ent_buf, '\n'))
- return 0;
-
- rc = read(st->fd, &st->ent_buf[st->buflen], __ENT_BUFSIZ - st->buflen);
- if (rc < 0)
- return -1;
-
- st->buflen += rc;
- if (st->buflen == 0)
- return -1;
-
- return 0;
-}
-
-
-/*
- * __ent_split
- *
- * Splits a string into parts based on a delimiter.
- * Stops processing when \n is reached also.
- *
- * Returns -1 on failure, or zero on success.
- */
-
-int __ent_split(struct __ent_state *st, char **parts,
- int n_parts, int delimiter, int require_exact)
-{
- char *s = &st->ent_buf[st->bufptr];
- int idx = 0;
-
- /* empty list */
- if (!*s) {
- if (!require_exact)
- return 0;
- return -1;
- }
-
- /* scan through string, sticking string pointers
- * into parts[] as delimiters are found
- */
- parts[idx++] = s;
- while (*s) {
- st->bufptr++;
- if (*s == '\n') {
- *s = 0; /* null terminate */
- break;
- }
- if (*s == delimiter) {
- *s = 0; /* null terminate */
- /* boundary error: too many delimiters */
- if (idx == n_parts)
- return -1;
- s++;
- parts[idx++] = s;
- } else {
- s++;
- }
- }
-
- if (!require_exact)
- return 0;
- return (n_parts == idx) ? 0 : -1;
-}
-
-
-void __ent_set(struct __ent_state *st)
-{
- if (!st)
- return;
- st->buflen = st->bufptr = 0;
- lseek(st->fd, 0, SEEK_SET);
-}
-
-
-void __ent_end(struct __ent_state *st)
-{
- if (!st)
- return;
- close(st->fd);
- free(st);
-}
diff --git a/mdk-stage1/dietlibc/libcruft/entlib.h b/mdk-stage1/dietlibc/libcruft/entlib.h
deleted file mode 100644
index 2659d542e..000000000
--- a/mdk-stage1/dietlibc/libcruft/entlib.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * dietlibc/lib/entlib.h - Generic delimited-line parsing library header
- *
- * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
- *
- * This is a brand new implementation, based on the interface
- * described in man-pages-1.34-1mdk man pages package.
- */
-
-#ifndef __ENTLIB_H
-#define __ENTLIB_H
-
-#include <sys/types.h> /* for open(2), lseek(2) */
-#include <sys/stat.h> /* for open(2) */
-#include <fcntl.h> /* for open(2) */
-#include <unistd.h> /* for close(2), lseek(2) */
-#include <stdlib.h> /* for calloc(3), free(3) */
-#include <errno.h> /* for errno */
-#include <string.h> /* for memmove(3) */
-#include <stdlib.h> /* for atoi(3) */
-#include <paths.h> /* for the file locations */
-
-#include <pwd.h> /* for struct passwd */
-#include <grp.h> /* for struct group */
-#include <shadow.h> /* for struct spwd */
-
-/* should be a multiple of 64 to create decent alignment */
-#define __ENT_BUFSIZ (64 * 2)
-#define __ENT_RAW_BUFSIZ (__ENT_BUFSIZ + 2) /* some overlap required */
-
-struct __ent_state {
- char ent_buf[__ENT_RAW_BUFSIZ]; /* raw file data buffer */
- unsigned int buflen; /* amount of valid data in ent_buf */
- unsigned int bufptr; /* next valid position in ent_buf */
- int fd; /* /etc/passwd file descriptor */
-};
-
-extern int __ent_start(const char *pathname, struct __ent_state **st_ref);
-extern int __ent_get_line(struct __ent_state *st);
-extern int __ent_split(struct __ent_state *st, char **parts, int n_parts, int delimiter, int require_exact);
-extern void __ent_set(struct __ent_state *st);
-extern void __ent_end(struct __ent_state *st);
-
-#endif /* __ENTLIB_H */
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.c b/mdk-stage1/dietlibc/libcruft/getgrgid.c
index 0c223056c..c0daac5e0 100644
--- a/mdk-stage1/dietlibc/libcruft/getgrgid.c
+++ b/mdk-stage1/dietlibc/libcruft/getgrgid.c
@@ -1,14 +1,11 @@
#include <grp.h>
#include <string.h>
-#include <stdlib.h>
+
+extern struct group __group_pw;
+extern char __group_buf[1000];
struct group *getgrgid(gid_t gid) {
struct group *tmp;
- setgrent();
- for (;;) {
- tmp=getgrent();
- if (!tmp) return 0;
- if (tmp->gr_gid == gid)
- return tmp;
- }
+ getgrgid_r(gid,&__group_pw,__group_buf,sizeof(__group_buf),&tmp);
+ return tmp;
}
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.c b/mdk-stage1/dietlibc/libcruft/getgrnam.c
index 1bdbb42a8..2664ab3f6 100644
--- a/mdk-stage1/dietlibc/libcruft/getgrnam.c
+++ b/mdk-stage1/dietlibc/libcruft/getgrnam.c
@@ -1,14 +1,11 @@
#include <grp.h>
#include <string.h>
-#include <stdlib.h>
+
+extern struct group __group_pw;
+extern char __group_buf[1000];
struct group *getgrnam(const char* name) {
struct group *tmp;
- setgrent();
- for (;;) {
- tmp=getgrent();
- if (!tmp) return 0;
- if (!strcmp(tmp->gr_name,name))
- return tmp;
- }
+ getgrnam_r(name,&__group_pw,__group_buf,sizeof(__group_buf),&tmp);
+ return tmp;
}
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/gethostbyaddr.c b/mdk-stage1/dietlibc/libcruft/gethostbyaddr.c
index a4207d44d..74828df56 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyaddr.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyaddr.c
@@ -5,34 +5,31 @@
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
-#include <sys/poll.h>
#include <unistd.h>
#include <errno.h>
+#include "dietwarning.h"
-extern int h_errno;
+static const int hostentsize=((sizeof(struct hostent)+15)&(-16));
+
+extern size_t __dns_buflen;
+extern char* __dns_buf;
+extern void __dns_makebuf(size_t x);
struct hostent* gethostbyaddr(const void *addr, socklen_t len, int type) {
- static struct hostent hostbuf;
+ struct hostent *hostbuf;
struct hostent *hp;
- size_t hstbuflen;
- char *tmphstbuf;
int res;
- int herr;
-
- hstbuflen = 1024;
- /* Allocate buffer, remember to free it to avoid a memory leakage. */
- tmphstbuf = malloc (hstbuflen);
- while ((res = gethostbyaddr_r (addr, len, type, &hostbuf, tmphstbuf, hstbuflen,
- &hp, &herr)) == ERANGE)
- {
- /* Enlarge the buffer. */
- hstbuflen *= 2;
- tmphstbuf = realloc (tmphstbuf, hstbuflen);
- }
- /* Check for errors. */
- if (res || hp == NULL)
- return NULL;
+ __dns_buflen=512;
+ do {
+ __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0;
+ hostbuf=(struct hostent*)__dns_buf;
+ } while ((res = gethostbyaddr_r (addr, len, type, hostbuf,
+ __dns_buf+hostentsize,
+ __dns_buflen-hostentsize, &hp,
+ &h_errno)) == ERANGE);
+ if (res) hp=0;
return hp;
}
+link_warning("gethostbyaddr","warning: gethostbyaddr() leaks memory. Use gethostbyaddr_r instead!")
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/gethostbyaddr_r.c b/mdk-stage1/dietlibc/libcruft/gethostbyaddr_r.c
index 37174ab13..d18053c45 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyaddr_r.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyaddr_r.c
@@ -5,15 +5,10 @@
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
-#include <sys/poll.h>
#include <unistd.h>
#include <errno.h>
-
-#include <stdio.h>
-
-extern int __dns_gethostbyx_r(const char* name, struct hostent* result,
- char *buf, size_t buflen,
- struct hostent **RESULT, int *h_errnop, int lookfor);
+#include "dietfeatures.h"
+#include "dietdns.h"
static int i2a(char* dest,unsigned int x) {
register unsigned int tmp=x;
@@ -24,6 +19,10 @@ static int i2a(char* dest,unsigned int x) {
return len+1;
}
+static char hexdigit(char c) {
+ return c>9?c-10+'a':c+'0';
+}
+
/* Oh boy, this interface sucks so badly, there are no words for it.
* Not one, not two, but _three_ error signalling methods! (*h_errnop
* nonzero? return value nonzero? *RESULT zero?) The glibc goons
@@ -31,21 +30,55 @@ static int i2a(char* dest,unsigned int x) {
int gethostbyaddr_r(const char* addr, size_t length, int format,
struct hostent* result, char *buf, size_t buflen,
struct hostent **RESULT, int *h_errnop) {
+ char tmpbuf[100];
+ char* tmp;
+ int res;
+ (void)length; /* shut gcc up about unused length. The length is implicit with format */
+#ifdef WANT_ETC_HOSTS
+ {
+ struct hostent* r;
+ while ((r=gethostent_r(buf,buflen))) {
+ if (r->h_addrtype==format && !memcmp(r->h_addr_list[0],addr,r->h_length)) { /* found it! */
+ memmove(result,r,sizeof(struct hostent));
+ *RESULT=result;
+ *h_errnop=0;
+ return 0;
+ }
+ }
+ endhostent();
+ }
+#endif
if (format==AF_INET) {
- char tmpbuf[50];
- char *tmp;
- int res;
tmp=tmpbuf+i2a(tmpbuf,(unsigned char)addr[3]); *tmp++='.';
tmp+=i2a(tmp,(unsigned char)addr[2]); *tmp++='.';
tmp+=i2a(tmp,(unsigned char)addr[1]); *tmp++='.';
tmp+=i2a(tmp,(unsigned char)addr[0]); strcpy(tmp,".in-addr.arpa");
- res= __dns_gethostbyx_r(tmpbuf,result,buf+4,buflen-4,RESULT,h_errnop,12); /* 12 == ns_t_ptr */
- if (res==0) {
- result->h_addr_list[0]=buf;
- result->h_addr_list[1]=buf;
- *(int*)buf=*(int*)addr;
+ } else if (format==AF_INET6) {
+ int i;
+ tmp=tmpbuf;
+ for (i=15; i>=0; --i) {
+ tmp[0]=hexdigit(addr[i]&0xf);
+ tmp[1]='.';
+ tmp[2]=hexdigit((addr[i]>>4)&0xf);
+ tmp[3]='.';
+ tmp+=4;
+ }
+ strcpy(tmp,".ip6.int");
+ } else return 1;
+ if (buflen<sizeof(struct hostent)+16) {
+ errno=ENOMEM;
+ *h_errnop=NO_RECOVERY;
+ return 1;
+ }
+ res= __dns_gethostbyx_r(tmpbuf,result,buf+16,buflen-16,RESULT,h_errnop,12); /* 12 == ns_t_ptr */
+ if (res==0) {
+ if (format==AF_INET) {
+ result->h_length=4;
+ result->h_addrtype=format;
}
- return res;
+ memcpy(buf,addr,result->h_length);
+ result->h_addr_list[0]=buf;
+ result->h_addr_list[1]=0;
}
- return 1;
+ return res;
}
diff --git a/mdk-stage1/dietlibc/libcruft/gethostbyname.c b/mdk-stage1/dietlibc/libcruft/gethostbyname.c
index 5db5bf3c5..b4849be96 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyname.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyname.c
@@ -5,35 +5,30 @@
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
-#include <sys/poll.h>
#include <unistd.h>
#include <errno.h>
+#include "dietwarning.h"
-extern int h_errno;
+static const int hostentsize=((sizeof(struct hostent)+15)&(-16));
-struct hostent* gethostbyname (const char *host)
-{
- static struct hostent hostbuf;
+extern size_t __dns_buflen;
+extern char* __dns_buf;
+extern void __dns_makebuf(size_t x);
+
+struct hostent* gethostbyname (const char *host) {
+ struct hostent *hostbuf;
struct hostent *hp;
- size_t hstbuflen;
- char *tmphstbuf;
int res;
- int herr;
-
- hstbuflen = 1024;
- /* Allocate buffer, remember to free it to avoid a memory leakage. */
- tmphstbuf = malloc (hstbuflen);
- while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
- &hp, &herr)) == ERANGE)
- {
- /* Enlarge the buffer. */
- hstbuflen *= 2;
- tmphstbuf = realloc (tmphstbuf, hstbuflen);
- }
- /* Check for errors. */
- if (res || hp == NULL)
- return NULL;
+ __dns_buflen=512;
+ do {
+ __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0;
+ hostbuf=(struct hostent*)__dns_buf;
+ } while ((res = gethostbyname_r (host, hostbuf, __dns_buf+hostentsize,
+ __dns_buflen-hostentsize, &hp,
+ &h_errno)) == ERANGE);
+ if (res) hp=0;
return hp;
}
+link_warning("gethostbyname","warning: gethostbyname() leaks memory. Use gethostbyname_r instead!")
diff --git a/mdk-stage1/dietlibc/libcruft/gethostbyname2.c b/mdk-stage1/dietlibc/libcruft/gethostbyname2.c
index 3d8296616..1ca140dbe 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyname2.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyname2.c
@@ -1,4 +1,3 @@
-
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -6,35 +5,32 @@
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
-#include <sys/poll.h>
#include <unistd.h>
#include <errno.h>
+#include "dietwarning.h"
+
+static const int hostentsize=((sizeof(struct hostent)+15)&(-16));
-extern int h_errno;
+extern size_t __dns_buflen;
+extern char* __dns_buf;
+extern void __dns_makebuf(size_t x);
-struct hostent* gethostbyname2(const char *host,int AF)
-{
- static struct hostent hostbuf;
+struct hostent* gethostbyname2(const char *host,int AF) {
+ struct hostent *hostbuf;
struct hostent *hp;
- size_t hstbuflen;
- char *tmphstbuf;
int res;
int herr;
- hstbuflen = 1024;
- /* Allocate buffer, remember to free it to avoid a memory leakage. */
- tmphstbuf = malloc (hstbuflen);
-
- while ((res = gethostbyname2_r (host, AF,&hostbuf, tmphstbuf, hstbuflen,
- &hp, &herr)) == ERANGE)
- {
- /* Enlarge the buffer. */
- hstbuflen *= 2;
- tmphstbuf = realloc (tmphstbuf, hstbuflen);
- }
- /* Check for errors. */
- if (res || hp == NULL)
- return NULL;
+ __dns_buflen=512;
+ do {
+ __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0;
+ hostbuf=(struct hostent*)__dns_buf;
+ } while ((res = gethostbyname2_r (host, AF, hostbuf,
+ __dns_buf+hostentsize,
+ __dns_buflen-hostentsize, &hp,
+ &herr)) == ERANGE);
+ if (res) hp=0;
return hp;
}
+link_warning("gethostbyname2","warning: gethostbyname2() leaks memory. Use gethostbyname2_r instead!")
diff --git a/mdk-stage1/dietlibc/libcruft/gethostbyname2_r.c b/mdk-stage1/dietlibc/libcruft/gethostbyname2_r.c
index b505ccfbc..75da5e320 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyname2_r.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyname2_r.c
@@ -5,15 +5,10 @@
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
-#include <sys/poll.h>
#include <unistd.h>
+#include "dietfeatures.h"
#include <errno.h>
-
-#include <stdio.h>
-
-extern int __dns_gethostbyx_r(const char* name, struct hostent* result,
- char *buf, size_t buflen,
- struct hostent **RESULT, int *h_errnop, int lookfor);
+#include "dietdns.h"
/* Oh boy, this interface sucks so badly, there are no words for it.
* Not one, not two, but _three_ error signalling methods! (*h_errnop
@@ -22,7 +17,7 @@ extern int __dns_gethostbyx_r(const char* name, struct hostent* result,
int gethostbyname2_r(const char* name, int AF, struct hostent* result,
char *buf, size_t buflen,
struct hostent **RESULT, int *h_errnop) {
- int L=strlen(name);
+ size_t L=strlen(name);
int lookfor=0;
switch (AF) {
case AF_INET: lookfor=1; break;
@@ -31,6 +26,30 @@ int gethostbyname2_r(const char* name, int AF, struct hostent* result,
}
result->h_name=buf;
if (buflen<L) { *h_errnop=ERANGE; return 1; }
+#ifdef WANT_ETC_HOSTS
+ {
+ struct hostent* r;
+ while ((r=gethostent_r(buf,buflen))) {
+ if (r->h_addrtype==AF) {
+ int i;
+ if (!strcmp(r->h_name,name)) { /* found it! */
+found:
+ memmove(result,r,sizeof(struct hostent));
+ *RESULT=result;
+ *h_errnop=0;
+ endhostent();
+ return 0;
+ }
+ for (i=0; i<16; ++i) {
+ if (r->h_aliases[i]) {
+ if (!strcmp(r->h_aliases[i],name)) goto found;
+ } else break;
+ }
+ }
+ }
+ endhostent();
+ }
+#endif
strcpy(buf,name);
return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,lookfor);
}
diff --git a/mdk-stage1/dietlibc/libcruft/gethostbyname_r.c b/mdk-stage1/dietlibc/libcruft/gethostbyname_r.c
index d5a531f0f..d7a713e20 100644
--- a/mdk-stage1/dietlibc/libcruft/gethostbyname_r.c
+++ b/mdk-stage1/dietlibc/libcruft/gethostbyname_r.c
@@ -1,19 +1,15 @@
#include <string.h>
+#include <strings.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 "dietfeatures.h"
#include <errno.h>
-
-#include <stdio.h>
-
-extern int __dns_gethostbyx_r(const char* name, struct hostent* result,
- char *buf, size_t buflen,
- struct hostent **RESULT, int *h_errnop, int lookfor);
+#include "dietdns.h"
/* Oh boy, this interface sucks so badly, there are no words for it.
* Not one, not two, but _three_ error signalling methods! (*h_errnop
@@ -22,9 +18,51 @@ extern int __dns_gethostbyx_r(const char* name, struct hostent* result,
int gethostbyname_r(const char* name, struct hostent* result,
char *buf, size_t buflen,
struct hostent **RESULT, int *h_errnop) {
- int L=strlen(name);
+ size_t L=strlen(name);
result->h_name=buf;
if (buflen<L) { *h_errnop=ERANGE; return 1; }
strcpy(buf,name);
+#ifdef WANT_INET_ADDR_DNS
+ result->h_addr_list=(char**)(buf+strlen(name)+1);
+ result->h_addr_list+=sizeof(unsigned long)-((unsigned long)(result->h_addr_list)&(sizeof(unsigned long)-1));
+ result->h_addr_list[0]=(char*)&result->h_addr_list[2];
+ if (inet_pton(AF_INET,name,result->h_addr_list[0])) {
+ result->h_addrtype=AF_INET;
+ result->h_length=4;
+commonip:
+ result->h_aliases=result->h_addr_list+2*sizeof(char**);
+ result->h_aliases[0]=0;
+ result->h_addr_list[1]=0;
+ *RESULT=result;
+ *h_errnop=0;
+ return 0;
+ } else if (inet_pton(AF_INET6,name,result->h_addr_list[0])) {
+ result->h_addrtype=AF_INET6;
+ result->h_length=16;
+ goto commonip;
+ }
+#endif
+#ifdef WANT_ETC_HOSTS
+ {
+ struct hostent* r;
+ while ((r=gethostent_r(buf,buflen))) {
+ int i;
+ if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) { /* found it! */
+found:
+ memmove(result,r,sizeof(struct hostent));
+ *RESULT=result;
+ *h_errnop=0;
+ endhostent();
+ return 0;
+ }
+ for (i=0; i<16; ++i) {
+ if (r->h_aliases[i]) {
+ if (!strcasecmp(r->h_aliases[i],name)) goto found;
+ } else break;
+ }
+ }
+ endhostent();
+ }
+#endif
return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,1);
}
diff --git a/mdk-stage1/dietlibc/libcruft/getlogin.c b/mdk-stage1/dietlibc/libcruft/getlogin.c
index 359f44d9f..844d68c70 100644
--- a/mdk-stage1/dietlibc/libcruft/getlogin.c
+++ b/mdk-stage1/dietlibc/libcruft/getlogin.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
+#include <unistd.h>
-char* getlogin() {
+char* getlogin(void) {
return getenv("LOGNAME");
}
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/getpagesize.c b/mdk-stage1/dietlibc/libcruft/getpagesize.c
index dea4a9693..536d3dcef 100644
--- a/mdk-stage1/dietlibc/libcruft/getpagesize.c
+++ b/mdk-stage1/dietlibc/libcruft/getpagesize.c
@@ -6,6 +6,7 @@
#define PAGE_SIZE 4096
#endif
+size_t __libc_getpagesize(void);
size_t __libc_getpagesize(void) {
return PAGE_SIZE;
}
diff --git a/mdk-stage1/dietlibc/libcruft/getpass.c b/mdk-stage1/dietlibc/libcruft/getpass.c
index 3da7cd2b3..2183284b3 100644
--- a/mdk-stage1/dietlibc/libcruft/getpass.c
+++ b/mdk-stage1/dietlibc/libcruft/getpass.c
@@ -3,30 +3,42 @@
#include <limits.h>
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
+
+static inline int _tcsetattr(int fd,int optional,struct termios *termios_p) {
+ int tmp;
+ for (;;) {
+ if ((tmp=tcsetattr(fd,optional,termios_p)))
+ if (errno==EINTR) continue;
+ break;
+ }
+ return tmp;
+}
char *getpass(const char* prompt) {
struct termios old,tmp;
int out,in=open("/dev/tty",O_RDWR);
int doclose=(in>=0);
static char buf[PASS_MAX];
- if (doclose) { in=0; out=2; } else out=in;
+ if (!doclose) { in=0; out=2; } else out=in;
if (!tcgetattr(in,&old)) {
tmp=old;
tmp.c_lflag &= ~(ECHO|ISIG);
- tcsetattr(in,TCSAFLUSH,&tmp);
+ _tcsetattr(in,TCSAFLUSH,&tmp);
}
write(out,prompt,strlen(prompt));
{
int nread,ofs=0;
for (;;) {
- nread=read(in,buf+ofs,PASS_MAX-ofs);
- if (nread<0) {
+ nread=read(in,buf+ofs,1);
+ if (nread<=0) {
+ if (errno==EINTR) continue;
buf[ofs]=0;
break;
} else if (ofs+nread>=PASS_MAX) {
buf[PASS_MAX-1]=0;
break;
- } else if (buf[ofs+nread-1]=='\n') {
+ } else if (buf[ofs]=='\n') {
buf[ofs+nread-1]=0;
break;
}
@@ -34,7 +46,7 @@ char *getpass(const char* prompt) {
}
write(out,"\n",1);
}
- tcsetattr(in,TCSAFLUSH,&old);
+ _tcsetattr(in,TCSAFLUSH,&old);
if (doclose) close(in);
return buf;
}
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.c b/mdk-stage1/dietlibc/libcruft/getpwnam.c
index 53aae74d1..d2e204150 100644
--- a/mdk-stage1/dietlibc/libcruft/getpwnam.c
+++ b/mdk-stage1/dietlibc/libcruft/getpwnam.c
@@ -1,14 +1,11 @@
#include <pwd.h>
#include <string.h>
-#include <stdlib.h>
-struct passwd *getpwnam(const char * name) {
+extern struct passwd __passwd_pw;
+extern char __passwd_buf[1000];
+
+struct passwd *getpwnam(const char* name) {
struct passwd *tmp;
- setpwent();
- for (;;) {
- tmp=getpwent();
- if (!tmp) return 0;
- if (!strcmp(tmp->pw_name,name))
- return tmp;
- }
+ getpwnam_r(name,&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp);
+ return tmp;
}
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.c b/mdk-stage1/dietlibc/libcruft/getpwuid.c
index eef14e6e8..bca6a8a0c 100644
--- a/mdk-stage1/dietlibc/libcruft/getpwuid.c
+++ b/mdk-stage1/dietlibc/libcruft/getpwuid.c
@@ -2,13 +2,11 @@
#include <string.h>
#include <stdlib.h>
+extern struct passwd __passwd_pw;
+extern char __passwd_buf[1000];
+
struct passwd *getpwuid(uid_t uid) {
struct passwd *tmp;
- setpwent();
- for (;;) {
- tmp=getpwent();
- if (!tmp) return 0;
- if (tmp->pw_uid==uid)
- return tmp;
- }
+ getpwuid_r(uid,&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp);
+ return tmp;
}
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.c b/mdk-stage1/dietlibc/libcruft/getspnam.c
index e6573345d..a4eafbfb2 100644
--- a/mdk-stage1/dietlibc/libcruft/getspnam.c
+++ b/mdk-stage1/dietlibc/libcruft/getspnam.c
@@ -1,14 +1,11 @@
#include <shadow.h>
#include <string.h>
-#include <stdlib.h>
-struct spwd *getspnam(const char * name) {
+extern struct spwd __shadow_pw;
+extern char __shadow_buf[1000];
+
+struct spwd *getspnam(const char* name) {
struct spwd *tmp;
- setspent();
- for (;;) {
- tmp=getspent();
- if (!tmp) return 0;
- if (!strcmp(tmp->sp_namp,name))
- return tmp;
- }
+ getspnam_r(name,&__shadow_pw,__shadow_buf,sizeof(__shadow_buf),&tmp);
+ return tmp;
}
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/grent.c b/mdk-stage1/dietlibc/libcruft/grent.c
deleted file mode 100644
index 0357657de..000000000
--- a/mdk-stage1/dietlibc/libcruft/grent.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * dietlibc/lib/grent.c - getgrent(3)/setgrent(3)/endgrent(3) implementation
- *
- * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
- *
- * This is a brand new implementation, based on the interface
- * described in man-pages-1.34-1mdk man pages package.
- */
-
-
-#include "entlib.h" /* this is our only include */
-
-#define MAX_GROUP_MEMBERS 16 /* matches Linux kernel task struct */
-
-static struct __ent_state *st = NULL; /* state held across calls */
-static char *gr_mem[MAX_GROUP_MEMBERS+1];
-static struct group gr;
-
-struct group *getgrent(void)
-{
- char *parts[4], *grouplist;
- unsigned int bufptr;
-
- if (__ent_start(_PATH_GROUP, &st))
- return NULL;
- if (__ent_get_line(st))
- goto err_out;
- if (__ent_split(st, parts, 4, ':', 1) < 0)
- goto err_out;
-
- gr.gr_name = parts[0];
- gr.gr_passwd = parts[1];
- gr.gr_gid = (gid_t) atoi(parts[2]);
- grouplist = parts[3];
-
- memset(&gr_mem, 0, sizeof(gr_mem));
- gr.gr_mem = gr_mem;
-
- /* rewind bufptr to beginning of group list */
- bufptr = st->bufptr;
- st->bufptr = (int) (grouplist - st->ent_buf);
-
- __ent_split(st, gr_mem, MAX_GROUP_MEMBERS, ',', 0);
- st->bufptr = bufptr;
-
- return &gr;
-
-err_out:
- st->buflen = st->bufptr = 0; /* invalidate file data buffer */
- return NULL;
-}
-
-void setgrent(void) { __ent_set(st); }
-void endgrent(void) { __ent_end(st); st=NULL; }
diff --git a/mdk-stage1/dietlibc/libcruft/herrno_location.c b/mdk-stage1/dietlibc/libcruft/herrno_location.c
index 203f73d4b..5908fe212 100644
--- a/mdk-stage1/dietlibc/libcruft/herrno_location.c
+++ b/mdk-stage1/dietlibc/libcruft/herrno_location.c
@@ -1,5 +1,8 @@
-extern int h_errno;
+#include <errno.h>
+#include <resolv.h>
+#include <netdb.h>
-int *__h_errno_location() { return &h_errno; }
+int *__h_errno_location(void);
+int *__h_errno_location(void) { return &h_errno; }
-int *h_errno_location() __attribute__((weak,alias("__h_errno_location")));
+int *h_errno_location(void) __attribute__((weak,alias("__h_errno_location")));
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/inet_aton.c b/mdk-stage1/dietlibc/libcruft/inet_aton.c
index ac7d9d007..01adb341e 100644
--- a/mdk-stage1/dietlibc/libcruft/inet_aton.c
+++ b/mdk-stage1/dietlibc/libcruft/inet_aton.c
@@ -24,7 +24,7 @@ int inet_aton(const char *cp, struct in_addr *inp) {
char *tmp=(char*)cp;
for (i=24; ;) {
long j;
- j=strtol(tmp,&tmp,0);
+ j=strtoul(tmp,&tmp,0);
if (*tmp==0) {
ip|=j;
break;
diff --git a/mdk-stage1/dietlibc/libcruft/inet_ntoa.c b/mdk-stage1/dietlibc/libcruft/inet_ntoa.c
index f8c975f7a..632d81424 100644
--- a/mdk-stage1/dietlibc/libcruft/inet_ntoa.c
+++ b/mdk-stage1/dietlibc/libcruft/inet_ntoa.c
@@ -2,8 +2,6 @@
#include <netinet/in.h>
#include <arpa/inet.h>
-extern char *inet_ntoa_r(struct in_addr in,char* buf);
-
char *inet_ntoa(struct in_addr in) {
static char buf[20];
return inet_ntoa_r(in,buf);
diff --git a/mdk-stage1/dietlibc/libcruft/inet_ntop.c b/mdk-stage1/dietlibc/libcruft/inet_ntop.c
index 77c47f239..81bee0a90 100644
--- a/mdk-stage1/dietlibc/libcruft/inet_ntop.c
+++ b/mdk-stage1/dietlibc/libcruft/inet_ntop.c
@@ -1,6 +1,6 @@
+#include <sys/socket.h>
#include <arpa/inet.h>
-
-extern char *inet_ntoa_r(struct in_addr in,char* buf);
+#include <string.h>
static const unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff};
@@ -17,8 +17,7 @@ static int fmt_xlong(char* s,unsigned int i) {
return s-bak+1;
}
-unsigned int fmt_ip6(char *s,const char ip[16])
-{
+static unsigned int fmt_ip6(char *s,const char ip[16]) {
unsigned int len;
unsigned int i;
unsigned int temp;
@@ -53,13 +52,16 @@ unsigned int fmt_ip6(char *s,const char ip[16])
}
}
}
+ if (compressing) {
+ *s++=':'; ++len;
+ }
*s=0;
return len;
}
const char* inet_ntop(int AF, const void *CP, char *BUF, size_t LEN) {
char buf[100];
- int len;
+ size_t len;
if (AF==AF_INET) {
inet_ntoa_r(*(struct in_addr*)CP,buf);
len=strlen(buf);
diff --git a/mdk-stage1/dietlibc/libcruft/inet_pton.c b/mdk-stage1/dietlibc/libcruft/inet_pton.c
index d5c17509c..a62785d5f 100644
--- a/mdk-stage1/dietlibc/libcruft/inet_pton.c
+++ b/mdk-stage1/dietlibc/libcruft/inet_pton.c
@@ -1,6 +1,9 @@
#include <stdlib.h>
+#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
+#include <string.h>
+#include "dietfeatures.h"
static unsigned int scan_ip6(const char *s,char ip[16])
{
@@ -9,8 +12,8 @@ static unsigned int scan_ip6(const char *s,char ip[16])
unsigned long u;
char suffix[16];
- int prefixlen=0;
- int suffixlen=0;
+ unsigned int prefixlen=0;
+ unsigned int suffixlen=0;
for (i=0; i<16; i++) ip[i]=0;
@@ -26,7 +29,7 @@ static unsigned int scan_ip6(const char *s,char ip[16])
}
{
char *tmp;
- u=strtol(s,&tmp,16);
+ u=strtoul(s,&tmp,16);
i=tmp-s;
}
@@ -60,7 +63,7 @@ static unsigned int scan_ip6(const char *s,char ip[16])
i=tmp-s;
}
if (!i) {
- len--;
+ if (*s) len--;
break;
}
if (suffixlen+prefixlen<=12 && s[i]=='.') {
@@ -83,12 +86,14 @@ static unsigned int scan_ip6(const char *s,char ip[16])
}
int inet_pton(int AF, const char *CP, void *BUF) {
+ int len;
if (AF==AF_INET) {
if (!inet_aton(CP,(struct in_addr*)BUF))
return 0;
} else if (AF==AF_INET6) {
- if (CP[scan_ip6(CP,BUF)])
- return 0;
+ if (CP[len=scan_ip6(CP,BUF)])
+ if (CP[len]!='%') /* allow "fe80::220:e0ff:fe69:ad92%eth0" */
+ return 0;
} else {
errno=EAFNOSUPPORT;
return -1;
diff --git a/mdk-stage1/dietlibc/libcruft/initgroups.c b/mdk-stage1/dietlibc/libcruft/initgroups.c
index 7d24866e9..932fddfd6 100644
--- a/mdk-stage1/dietlibc/libcruft/initgroups.c
+++ b/mdk-stage1/dietlibc/libcruft/initgroups.c
@@ -3,9 +3,10 @@
#include <string.h>
int initgroups(const char *user, gid_t group) {
- int n=0;
+ int n=1;
gid_t grouplist[32];
struct group *g;
+ grouplist[0]=group;
setgrent();
while ((g=getgrent())) {
char **duh=g->gr_mem;
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/mkstemp.c b/mdk-stage1/dietlibc/libcruft/mkstemp.c
index 3b24ecb54..7dc19d4ed 100644
--- a/mdk-stage1/dietlibc/libcruft/mkstemp.c
+++ b/mdk-stage1/dietlibc/libcruft/mkstemp.c
@@ -1,14 +1,21 @@
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
+#include <stdlib.h>
#include <errno.h>
+#include "dietfeatures.h"
+
+#ifndef O_NOFOLLOW
+#define O_NOFOLLOW 0
+#endif
int mkstemp(char* template) {
char *tmp=template+strlen(template)-6;
int randfd;
int i,res;
unsigned int random;
- for (i=0; i<6; ++i) if (tmp[i]!='X') { __set_errno(EINVAL); return -1; }
+ if (tmp<template) goto error;
+ for (i=0; i<6; ++i) if (tmp[i]!='X') { error: errno=EINVAL; return -1; }
randfd=open("/dev/urandom",O_RDONLY);
for (;;) {
read(randfd,&random,sizeof(random));
@@ -16,8 +23,9 @@ int mkstemp(char* template) {
int hexdigit=(random>>(i*5))&0x1f;
tmp[i]=hexdigit>9?hexdigit+'a'-10:hexdigit+'0';
}
- res=open(template,O_CREAT|O_RDWR|O_EXCL,0600);
- if (res>=0) return res;
+ res=open(template,O_CREAT|O_RDWR|O_EXCL|O_NOFOLLOW,0600);
+ if (res>=0 || errno!=EEXIST) break;
}
close(randfd);
+ return res;
}
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/pwent.c b/mdk-stage1/dietlibc/libcruft/pwent.c
deleted file mode 100644
index 30a8a0957..000000000
--- a/mdk-stage1/dietlibc/libcruft/pwent.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * dietlibc/lib/pwent.c - getpwent(3)/setpwent(3)/endpwent(3) implementation
- *
- * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
- *
- * This is a brand new implementation, based on the interface
- * described in man-pages-1.34-1mdk man pages package.
- */
-
-
-#include "entlib.h" /* this is our only include */
-
-static struct __ent_state *st = NULL; /* state held across calls */
-static struct passwd pw;
-
-struct passwd *getpwent(void)
-{
- char *parts[7];
-
- if (__ent_start(_PATH_PASSWD, &st))
- return NULL;
- if (__ent_get_line(st))
- goto err_out;
- if (__ent_split(st, parts, 7, ':', 1) < 0)
- goto err_out;
-
- pw.pw_name = parts[0];
- pw.pw_passwd = parts[1];
- pw.pw_uid = (uid_t) atoi(parts[2]);
- pw.pw_gid = (gid_t) atoi(parts[3]);
- pw.pw_gecos = parts[4];
- pw.pw_dir = parts[5];
- pw.pw_shell = parts[6];
-
- return &pw;
-
-err_out:
- st->buflen = st->bufptr = 0; /* invalidate file data buffer */
- return NULL;
-}
-
-void setpwent(void) { __ent_set(st); }
-void endpwent(void) { __ent_end(st); st=NULL; }
diff --git a/mdk-stage1/dietlibc/libcruft/res_init.c b/mdk-stage1/dietlibc/libcruft/res_init.c
index 9322af298..78baa2b30 100644
--- a/mdk-stage1/dietlibc/libcruft/res_init.c
+++ b/mdk-stage1/dietlibc/libcruft/res_init.c
@@ -1,7 +1,9 @@
-extern int __dns_servers;
+#include <resolv.h>
+
extern void __dns_readstartfiles(void);
int res_init(void) {
- __dns_servers=0;
+ _res.nscount=0;
__dns_readstartfiles();
+ return 0;
}
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/spent.c b/mdk-stage1/dietlibc/libcruft/spent.c
deleted file mode 100644
index e4beb81e4..000000000
--- a/mdk-stage1/dietlibc/libcruft/spent.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * dietlibc/lib/spent.c - getspent(3)/setspent(3)/endspent(3) implementation
- *
- * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
- *
- * This is a brand new implementation, based on the interface
- * described in man-pages-1.34-1mdk man pages package.
- */
-
-
-#include "entlib.h" /* this is our only include */
-
-static struct __ent_state *st = NULL; /* state held across calls */
-static struct spwd sp;
-
-struct spwd *getspent(void)
-{
- char *parts[9];
-
- if (__ent_start(_PATH_SHADOW, &st))
- return NULL;
- if (__ent_get_line(st))
- goto err_out;
- if (__ent_split(st, parts, 9, ':', 1) < 0)
- goto err_out;
-
- sp.sp_namp = parts[0];
- sp.sp_pwdp = parts[1];
- sp.sp_lstchg = atoi(parts[2]); /* XXX: atol */
- sp.sp_min = atoi(parts[3]);
- sp.sp_max = atoi(parts[4]);
- sp.sp_warn = atoi(parts[5]);
- sp.sp_inact = atoi(parts[6]);
- sp.sp_expire = atoi(parts[7]);
- sp.sp_flag = atoi(parts[8]);
-
- return &sp;
-
-err_out:
- st->buflen = st->bufptr = 0; /* invalidate file data buffer */
- return NULL;
-}
-
-void setspent(void) { __ent_set(st); }
-void endspent(void) { __ent_end(st); st=NULL; }
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;
+}