summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMystery Man <unknown@mandriva.org>2001-05-14 13:50:02 +0000
committerMystery Man <unknown@mandriva.org>2001-05-14 13:50:02 +0000
commit307b99f54bd4ff16de91c4d191cf1cf5bd4e2669 (patch)
treeafb96786d841a84044ff729a29af859c62fdc588
parent3e3a822d182adc09a3969f4f37489c07755c52f8 (diff)
downloaddrakx-307b99f54bd4ff16de91c4d191cf1cf5bd4e2669.tar
drakx-307b99f54bd4ff16de91c4d191cf1cf5bd4e2669.tar.gz
drakx-307b99f54bd4ff16de91c4d191cf1cf5bd4e2669.tar.bz2
drakx-307b99f54bd4ff16de91c4d191cf1cf5bd4e2669.tar.xz
drakx-307b99f54bd4ff16de91c4d191cf1cf5bd4e2669.zip
This commit was manufactured by cvs2svn to create branch 'dietlibc'.
-rw-r--r--mdk-stage1/dietlibc/libregex/rx.c434
-rw-r--r--mdk-stage1/dietlibc/librpc/auth_none.c128
-rw-r--r--mdk-stage1/dietlibc/librpc/auth_unix.c313
-rw-r--r--mdk-stage1/dietlibc/librpc/authunix_prot.c69
-rw-r--r--mdk-stage1/dietlibc/librpc/bindresvport.c79
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_generic.c112
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_perror.c302
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_raw.c230
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_simple.c116
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_tcp.c463
-rw-r--r--mdk-stage1/dietlibc/librpc/clnt_udp.c437
-rw-r--r--mdk-stage1/dietlibc/librpc/get_myaddress.c69
-rw-r--r--mdk-stage1/dietlibc/librpc/getrpcent.c274
-rw-r--r--mdk-stage1/dietlibc/librpc/getrpcport.c57
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_clnt.c118
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_getmaps.c85
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_getport.c90
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_prot.c58
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_prot2.c116
-rw-r--r--mdk-stage1/dietlibc/librpc/pmap_rmt.c403
-rw-r--r--mdk-stage1/dietlibc/librpc/rpc_callmsg.c189
-rw-r--r--mdk-stage1/dietlibc/librpc/rpc_commondata.c42
-rw-r--r--mdk-stage1/dietlibc/librpc/rpc_dtablesize.c50
-rw-r--r--mdk-stage1/dietlibc/librpc/rpc_prot.c281
-rw-r--r--mdk-stage1/dietlibc/librpc/svc.c479
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_auth.c115
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_auth_unix.c136
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_raw.c159
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_run.c71
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_simple.c144
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_tcp.c406
-rw-r--r--mdk-stage1/dietlibc/librpc/svc_udp.c467
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr.c536
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_array.c152
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_float.c284
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_mem.c180
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_rec.c573
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_reference.c130
-rw-r--r--mdk-stage1/dietlibc/librpc/xdr_stdio.c187
-rw-r--r--mdk-stage1/dietlibc/libshell/fnmatch.c74
-rw-r--r--mdk-stage1/dietlibc/libshell/glob.c356
-rw-r--r--mdk-stage1/dietlibc/libshell/realpath.c31
-rw-r--r--mdk-stage1/dietlibc/libstdio/clearerr.c5
-rw-r--r--mdk-stage1/dietlibc/libstdio/fclose.c24
-rw-r--r--mdk-stage1/dietlibc/libstdio/fdglue.c49
-rw-r--r--mdk-stage1/dietlibc/libstdio/fdopen.c21
-rw-r--r--mdk-stage1/dietlibc/libstdio/feof.c9
-rw-r--r--mdk-stage1/dietlibc/libstdio/ferror.c5
-rw-r--r--mdk-stage1/dietlibc/libstdio/fflush.c62
-rw-r--r--mdk-stage1/dietlibc/libstdio/fgetc.c40
-rw-r--r--mdk-stage1/dietlibc/libstdio/fgets.c20
-rw-r--r--mdk-stage1/dietlibc/libstdio/fileno.c5
-rw-r--r--mdk-stage1/dietlibc/libstdio/fopen.c21
-rw-r--r--mdk-stage1/dietlibc/libstdio/fprintf.c23
-rw-r--r--mdk-stage1/dietlibc/libstdio/fputc.c19
-rw-r--r--mdk-stage1/dietlibc/libstdio/fputs.c6
-rw-r--r--mdk-stage1/dietlibc/libstdio/fread.c51
-rw-r--r--mdk-stage1/dietlibc/libstdio/freopen.c9
-rw-r--r--mdk-stage1/dietlibc/libstdio/fseek.c11
-rw-r--r--mdk-stage1/dietlibc/libstdio/ftell.c7
-rw-r--r--mdk-stage1/dietlibc/libstdio/fwrite.c30
-rw-r--r--mdk-stage1/dietlibc/libstdio/printf.c29
-rw-r--r--mdk-stage1/dietlibc/libstdio/putchar.c6
-rw-r--r--mdk-stage1/dietlibc/libstdio/setvbuf.c18
-rw-r--r--mdk-stage1/dietlibc/libstdio/stderr.c13
-rw-r--r--mdk-stage1/dietlibc/libstdio/stdin.c13
-rw-r--r--mdk-stage1/dietlibc/libstdio/stdout.c14
-rw-r--r--mdk-stage1/dietlibc/libstdio/ungetc.c11
-rw-r--r--mdk-stage1/dietlibc/libugly/asctime.c7
-rw-r--r--mdk-stage1/dietlibc/libugly/asctime_r.c29
-rw-r--r--mdk-stage1/dietlibc/libugly/asprintf.c22
-rw-r--r--mdk-stage1/dietlibc/libugly/ctime.c5
-rw-r--r--mdk-stage1/dietlibc/libugly/daemon.c35
-rw-r--r--mdk-stage1/dietlibc/libugly/endmntent.c7
-rw-r--r--mdk-stage1/dietlibc/libugly/facilitynames.c32
-rw-r--r--mdk-stage1/dietlibc/libugly/getmntent.c30
-rw-r--r--mdk-stage1/dietlibc/libugly/getprotoent.c130
-rw-r--r--mdk-stage1/dietlibc/libugly/gmtime.c6
-rw-r--r--mdk-stage1/dietlibc/libugly/gmtime_r.c35
-rw-r--r--mdk-stage1/dietlibc/libugly/isleap.c6
-rw-r--r--mdk-stage1/dietlibc/libugly/localtime.c6
-rw-r--r--mdk-stage1/dietlibc/libugly/localtime_r.c21
-rw-r--r--mdk-stage1/dietlibc/libugly/logging.c211
-rw-r--r--mdk-stage1/dietlibc/libugly/mktime.c21
-rw-r--r--mdk-stage1/dietlibc/libugly/pclose.c11
-rw-r--r--mdk-stage1/dietlibc/libugly/popen.c32
-rw-r--r--mdk-stage1/dietlibc/libugly/prioritynames.c22
-rw-r--r--mdk-stage1/dietlibc/libugly/setenv.c17
-rw-r--r--mdk-stage1/dietlibc/libugly/setmntent.c7
-rw-r--r--mdk-stage1/dietlibc/libugly/strftime.c182
-rw-r--r--mdk-stage1/dietlibc/libugly/strsignal.c92
-rw-r--r--mdk-stage1/dietlibc/libugly/system.c69
-rw-r--r--mdk-stage1/dietlibc/libugly/time_table_spd.c17
-rw-r--r--mdk-stage1/dietlibc/libugly/tzfile.c86
-rw-r--r--mdk-stage1/dietlibc/libugly/unsetenv.c6
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/_llseek.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/_newselect.c6
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/access.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/chdir.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/chmod.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/chown.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/chroot.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/clone.c1
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/close.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/dup.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/dup2.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/execve.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/exit.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fchdir.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fchmod.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fchown.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fcntl.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/flock.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fork.c6
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/fsync.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/ftruncate.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getcwd.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getdents.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getegid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/geteuid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getgid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getgroups.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getpgid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getpid.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getppid.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getpriority.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getresgid.c8
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getresuid.c8
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getrlimit.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getrusage.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getsid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/gettimeofday.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/getuid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/ioctl.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/kill.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/lchown.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/link.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/lseek.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/mkdir.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/mknod.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/mount.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/mprotect.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/mremap.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/munmap.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/nanosleep.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/open.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/pipe.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/poll.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/read.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/readlink.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/reboot.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/rename.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/rmdir.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setdomainname.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setgid.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setgroups.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sethostname.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setitimer.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setpgid.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setpriority.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setregid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setresgid.c8
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setresuid.c8
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setreuid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setrlimit.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setsid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/setuid.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sigaction.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/signal.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sigpending.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sigprocmask.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sigsuspend.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/socketcall.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/swapoff.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/swapon.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/symlink.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/sync.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/syslog.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/time.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/truncate.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/umask.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/umount.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/uname.c5
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/unlink.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/utime.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/vhangup.c3
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/wait4.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/waitpid.c4
-rw-r--r--mdk-stage1/dietlibc/syscalls.c/write.c3
189 files changed, 11041 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libregex/rx.c b/mdk-stage1/dietlibc/libregex/rx.c
new file mode 100644
index 000000000..b28358c2e
--- /dev/null
+++ b/mdk-stage1/dietlibc/libregex/rx.c
@@ -0,0 +1,434 @@
+#include <regex.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <string.h>
+
+/* this is ugly.
+ * the idea is to build a parse tree, then do some poor man's OOP with a
+ * generic matcher function call that is always that the start of each
+ * record, and a next pointer. When the parse tree is done, we need to
+ * recursively set the next pointers to point to the part of the parse
+ * tree that needs to match next.
+ * This is the prototype of the generic match function call pointer.
+ * The first argument is the "this" pointer, the second is the text to
+ * be matched against, ofs is the offset from the start of the matched
+ * text (so we can match "^") and matches is an array where match
+ * positions are stored. */
+/* now declared in regex.h: */
+/* typedef int (*matcher)(void*,const char*,int ofs,regmatch_t* matches,int plus,int eflags); */
+
+/* one would think that this is approach is an order of magnitude slower
+ * than the standard NFA approach, but it isn't. The busybox grep took
+ * 0.26 seconds for a fixed string compared to 0.19 seconds for the
+ * glibc regex. */
+
+/* first part: parse a regex into a parse tree */
+struct bracketed {
+ unsigned int cc[32];
+};
+
+/* now declared in regex.h:
+struct regex {
+ matcher m;
+ void* next;
+ int pieces;
+ int num;
+ struct branch *b;
+}; */
+
+struct atom {
+ matcher m;
+ void* next;
+ enum { EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, } type;
+ int bnum;
+ union {
+ struct regex r;
+ struct bracketed b;
+ char c;
+ } u;
+};
+
+struct piece {
+ matcher m;
+ void* next;
+ struct atom a;
+ unsigned char min,max;
+};
+
+struct branch {
+ matcher m;
+ void* next;
+ int num;
+ struct piece *p;
+};
+
+static void clearcc(unsigned int* x) {
+ memset(x,0,sizeof(*x));
+}
+
+static void setcc(unsigned int* x,unsigned int bit) {
+ x[bit/32]|=(1<<((bit%32)-1));
+}
+
+static int issetcc(unsigned int* x,unsigned int bit) {
+ return x[bit/32] & (1<<((bit%32)-1));
+}
+
+static const char* parsebracketed(struct bracketed*__restrict__ b,const char*__restrict__ s,regex_t*__restrict__ rx) {
+ const char* t;
+ int i,negflag=0;
+ if (*s!='[') return s;
+ t=s+1;
+ clearcc(b->cc);
+ if (*t=='^') { negflag=1; ++t; }
+ do {
+ if (*t==0) return s;
+ setcc(b->cc,rx->cflags&REG_ICASE?*t:tolower(*t));
+ if (t[1]=='-' && t[2]!=']') {
+ for (i=*t+1; i<=t[2]; ++i) setcc(b->cc,rx->cflags&REG_ICASE?i:tolower(i));
+ t+=2;
+ }
+ ++t;
+ } while (*t!=']');
+ if (negflag) for (i=0; i<32; ++i) b->cc[i]=~b->cc[i];
+ return t+1;
+}
+
+static const char* parseregex(struct regex* r,const char* s,regex_t* rx);
+
+static int matchatom(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
+ register struct atom* a=(struct atom*)x;
+ int matchlen=0;
+ switch (a->type) {
+ case EMPTY:
+// printf("matching EMPTY against \"%s\"\n",s);
+ preg->l[a->bnum].rm_so=preg->l[a->bnum].rm_eo=ofs;
+ goto match;
+ case REGEX:
+// printf("matching REGEX against \"%s\"\n",s);
+ if ((matchlen=a->u.r.m(a,s,ofs,preg,0,eflags))>=0) {
+ preg->l[a->bnum].rm_so=ofs;
+ preg->l[a->bnum].rm_eo=ofs+matchlen;
+ goto match;
+ }
+ break;
+ case BRACKET:
+// printf("matching BRACKET against \"%s\"\n",s);
+ matchlen=1;
+ if (*s=='\n' && (preg->cflags&REG_NEWLINE)) break;
+ if (*s && issetcc(a->u.b.cc,(preg->cflags&REG_ICASE?tolower(*s):*s)))
+ goto match;
+ break;
+ case ANY:
+// printf("matching ANY against \"%s\"\n",s);
+ if (*s=='\n' && (preg->cflags&REG_NEWLINE)) break;
+ matchlen=1;
+ if (*s) goto match;
+ break;
+ case LINESTART:
+// printf("matching LINESTART against \"%s\"\n",s);
+ if (ofs==0 && (eflags&REG_NOTBOL)==0) {
+ goto match;
+ }
+ break;
+ case LINEEND:
+// printf("matching LINEEND against \"%s\"\n",s);
+ if ((*s && *s!='\n') || (eflags&REG_NOTEOL)==0) break;
+ goto match;
+ case WORDSTART:
+ if ((ofs==0 || isspace(s[-1])) && !isspace(*s))
+ goto match;
+ break;
+ case WORDEND:
+ if (ofs>0 && !isspace(s[-1]) && isspace(*s))
+ goto match;
+ break;
+ case CHAR:
+// printf("matching CHAR %c against \"%s\"\n",a->u.c,s);
+ matchlen=1;
+ if (((preg->cflags&REG_ICASE)?tolower(*s):*s)==a->u.c) goto match;
+ break;
+ }
+ return -1;
+match:
+ if (a->next)
+ return ((struct atom*)(a->next))->m(a->next,s+matchlen,ofs+matchlen,preg,plus+matchlen,eflags);
+ else
+ return plus+matchlen;
+}
+
+static const char* parseatom(struct atom*__restrict__ a,const char*__restrict__ s,regex_t*__restrict__ rx) {
+ const char *tmp;
+ a->m=matchatom;
+ a->bnum=-1;
+ switch (*s) {
+ case '(':
+ a->bnum=++rx->brackets;
+ if (s[1]==')') {
+ a->type=EMPTY;
+ return s+2;
+ }
+ a->type=REGEX;
+ if ((tmp=parseregex(&a->u.r,s+1,rx))!=s) {
+ if (*tmp==')')
+ return tmp+1;
+ }
+ case 0:
+ case '|':
+ case ')':
+ return s;
+ case '[':
+ a->type=BRACKET;
+ if ((tmp=parsebracketed(&a->u.b,s,rx))!=s)
+ return tmp;
+ return s;
+ case '.':
+ a->type=ANY;
+ break;
+ case '^':
+ a->type=LINESTART;
+ break;
+ case '$':
+ a->type=LINEEND;
+ break;
+ case '\\':
+ if (!*++s) return s;
+ if (*s=='<') {
+ a->type=WORDSTART;
+ break;
+ } else if (*s=='>') {
+ a->type=WORDEND;
+ break;
+ }
+ default:
+ a->type=CHAR;
+ a->u.c=rx->cflags&REG_ICASE?*s:tolower(*s);
+ break;
+ }
+ return s+1;
+}
+
+/* needs to do "greedy" matching, i.e. match as often as possible */
+static int matchpiece(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
+ register struct piece* a=(struct piece*)x;
+ int matchlen=0;
+ int tmp,num=0;
+ unsigned int *offsets=alloca(sizeof(int)*a->max);
+ offsets[0]=0;
+// printf("matchpiece \"%s\"...\n",s);
+ /* first, try to match the atom as often as possible, up to a->max times */
+ if (a->max == 1 && a->min == 1)
+ return a->a.m(&a->a,s+matchlen,ofs+matchlen,preg,0,eflags);
+ while (num<a->max) {
+ void* save=a->a.next;
+ a->a.next=0;
+ if ((tmp=a->a.m(&a->a,s+matchlen,ofs+matchlen,preg,0,eflags))>=0) {
+ a->a.next=save;
+ ++num;
+ matchlen+=tmp;
+ offsets[num]=tmp;
+ } else {
+ a->a.next=save;
+ break;
+ }
+ }
+ if (num<a->min) return -1; /* already at minimum matches; signal mismatch */
+ /* then, while the rest does not match, back off */
+ for (;;) {
+ if (a->next)
+ tmp=((struct atom*)(a->next))->m(a->next,s+matchlen,ofs+matchlen,preg,plus+matchlen,eflags);
+ else
+ tmp=plus+matchlen;
+ if (tmp>=0) break; /* it did match; don't back off any further */
+ matchlen-=offsets[num];
+ --num;
+ }
+ return tmp;
+}
+
+static const char* parsepiece(struct piece*__restrict__ p,const char*__restrict__ s,regex_t*__restrict__ rx) {
+ const char* tmp=parseatom(&p->a,s,rx);
+ if (tmp==s) return s;
+ p->m=matchpiece;
+ p->min=p->max=1;
+ switch (*tmp) {
+ case '*': p->min=0; p->max=RE_DUP_MAX; break;
+ case '+': p->min=1; p->max=RE_DUP_MAX; break;
+ case '?': p->min=0; p->max=1; break;
+ case '{':
+ if (isdigit(*++tmp)) {
+ p->min=*tmp-'0'; p->max=RE_DUP_MAX;
+ while (isdigit(*++tmp)) p->min=p->min*10+*tmp-'0';
+ if (*tmp==',') {
+ if (isdigit(*++tmp)) {
+ p->max=*tmp-'0';
+ while (isdigit(*++tmp)) p->max=p->max*10+*tmp-'0';
+ }
+ }
+ if (*tmp!='}') return s;
+ ++tmp;
+ }
+ default:
+ return tmp;
+ }
+ return tmp+1;
+}
+
+/* trivial, just pass through */
+static int matchbranch(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
+ register struct branch* a=(struct branch*)x;
+ int tmp;
+ tmp=a->p->m(a->p,s,ofs,preg,plus,eflags);
+ if (tmp>=0) {
+ if (a->next)
+ return ((struct atom*)(a->next))->m(a->next,s+tmp,ofs+tmp,preg,plus+tmp,eflags);
+ else
+ return plus+tmp;
+ }
+ return -1;
+}
+
+static const char* parsebranch(struct branch*__restrict__ b,const char*__restrict__ s,regex_t*__restrict__ rx,int*__restrict__ pieces) {
+ struct piece p;
+ const char *tmp;
+ b->m=matchbranch;
+ b->num=0; b->p=0;
+ for (;;) {
+ if (*s=='|') {
+ if (b->num==0) {
+ tmp=s+1;
+ p.a.type=EMPTY;
+ p.min=p.max=1;
+ }
+ } else {
+ tmp=parsepiece(&p,s,rx);
+ if (tmp==s) return s;
+ }
+ if (!(b->p=realloc(b->p,++b->num*sizeof(p)))) return s;
+ b->p[b->num-1]=p;
+ if (*s=='|') { ++tmp; break; }
+ s=tmp;
+ }
+ *pieces+=b->num;
+ return tmp;
+}
+
+/* try the branches one by one */
+static int matchregex(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
+ register struct regex* a=(struct regex*)x;
+ int i,tmp;
+ for (i=0; i<a->num; ++i) {
+ tmp=a->b[i].m(&a->b[i],s,ofs,preg,plus,eflags);
+ if (tmp>=0) {
+ if (a->next)
+ return ((struct atom*)(a->next))->m(a->next,s+tmp,ofs+tmp,preg,plus+tmp,eflags);
+ else
+ return plus+tmp;
+ }
+ }
+ return -1;
+}
+
+static const char* parseregex(struct regex*__restrict__ r,const char*__restrict__ s,regex_t*__restrict__ p) {
+ struct branch b;
+ const char *tmp;
+ r->m=matchregex;
+ r->num=0; r->b=0; r->pieces=0;
+ for (;;) {
+ tmp=parsebranch(&b,s,p,&r->pieces);
+ if (tmp==s) return s;
+ if (!(r->b=realloc(r->b,++r->num*sizeof(b)))) return s;
+ r->b[r->num-1]=b;
+ s=tmp;
+ }
+ return tmp;
+}
+
+
+/* The matcher relies on the presence of next pointers, of which the
+ * parser does not know the correct destination. So we need an
+ * additional pass through the data structure that sets the next
+ * pointers correctly. */
+static void regex_putnext(struct regex* r,void* next);
+
+static void atom_putnext(struct atom*__restrict__ a,void*__restrict__ next) {
+ a->next=next;
+ if (a->type==REGEX)
+ regex_putnext(&a->u.r,next);
+}
+
+static void piece_putnext(struct piece*__restrict__ p,void*__restrict__ next) {
+ p->next=next;
+ atom_putnext(&p->a,next);
+}
+
+static void branch_putnext(struct branch*__restrict__ b,void*__restrict__ next) {
+ int i;
+ for (i=0; i<b->num-1; ++i)
+ piece_putnext(&b->p[i],&b->p[i+1]);
+ piece_putnext(&b->p[i],0);
+ b->next=next;
+}
+
+static void regex_putnext(struct regex*__restrict__ r,void*__restrict__ next) {
+ int i;
+ for (i=0; i<r->num; ++i)
+ branch_putnext(&r->b[i],next);
+ r->next=next;
+}
+
+
+
+int regcomp(regex_t*__restrict__ preg, const char*__restrict__ regex, int cflags) {
+ const char* t=parseregex(&preg->r,regex,preg);
+ if (t==regex) return -1;
+ regex_putnext(&preg->r,0);
+ preg->cflags=cflags;
+ return 0;
+}
+
+int regexec(const regex_t*__restrict__ preg, const char*__restrict__ string, size_t nmatch, regmatch_t pmatch[], int eflags) {
+ int matched;
+ const char *orig=string;
+ ((regex_t*)preg)->l=alloca(sizeof(regmatch_t)*(preg->brackets+1));
+ while (*string) {
+ matched=preg->r.m((void*)&preg->r,string,string-orig,(regex_t*)preg,0,eflags);
+ if (matched>=0) {
+ if ((preg->cflags&REG_NOSUB)==0) memmove(pmatch,preg->l,nmatch*sizeof(regmatch_t));
+ return 0;
+ }
+ ++string; eflags|=REG_NOTBOL;
+ }
+ return REG_NOMATCH;
+}
+
+
+
+void regfree(regex_t* preg) {
+ int i;
+ for (i=0; i<preg->r.num; ++i) {
+ free(preg->r.b[i].p);
+ free(preg->r.b);
+ }
+}
+
+size_t regerror(int errcode, const regex_t*__restrict__ preg, char*__restrict__ errbuf, size_t errbuf_size) {
+ strncpy(errbuf,"invalid regular expression (sorry)",errbuf_size);
+ return strlen(errbuf);
+}
+
+
+
+
+#if 0
+int main() {
+ struct regex r;
+ int bnum=-1;
+ const char* t=parseregex(&r,"^a*ab$",&bnum);
+ regex_putnext(&r,0);
+ printf("%d pieces, %s\n",r.pieces,t);
+ printf("%d\n",r.m(&r,"aaab",0,0,0));
+ return 0;
+}
+#endif
diff --git a/mdk-stage1/dietlibc/librpc/auth_none.c b/mdk-stage1/dietlibc/librpc/auth_none.c
new file mode 100644
index 000000000..7a4dffe87
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/auth_none.c
@@ -0,0 +1,128 @@
+/* @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * auth_none.c
+ * Creates a client authentication handle for passing "null"
+ * credentials and verifiers to remote systems.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#define MAX_MARSHEL_SIZE 20
+
+/*
+ * Authenticator operations routines
+ */
+static void authnone_verf();
+static void authnone_destroy();
+static bool_t authnone_marshal();
+static bool_t authnone_validate();
+static bool_t authnone_refresh();
+
+static struct auth_ops ops = {
+ authnone_verf,
+ authnone_marshal,
+ authnone_validate,
+ authnone_refresh,
+ authnone_destroy
+};
+
+static struct authnone_private {
+ AUTH no_client;
+ char marshalled_client[MAX_MARSHEL_SIZE];
+ u_int mcnt;
+} *authnone_private;
+
+AUTH *authnone_create()
+{
+ register struct authnone_private *ap = authnone_private;
+ XDR xdr_stream;
+ register XDR *xdrs;
+
+ if (ap == 0) {
+ ap = (struct authnone_private *) calloc(1, sizeof(*ap));
+ if (ap == 0)
+ return (0);
+ authnone_private = ap;
+ }
+ if (!ap->mcnt) {
+ ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
+ ap->no_client.ah_ops = &ops;
+ xdrs = &xdr_stream;
+ xdrmem_create(xdrs, ap->marshalled_client,
+ (u_int) MAX_MARSHEL_SIZE, XDR_ENCODE);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
+ ap->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+ }
+ return (&ap->no_client);
+}
+
+ /*ARGSUSED*/ static bool_t authnone_marshal(client, xdrs)
+AUTH *client;
+XDR *xdrs;
+{
+ register struct authnone_private *ap = authnone_private;
+
+ if (ap == 0)
+ return (0);
+ return ((*xdrs->x_ops->x_putbytes) (xdrs,
+ ap->marshalled_client, ap->mcnt));
+}
+
+static void authnone_verf()
+{
+}
+
+static bool_t authnone_validate()
+{
+
+ return (TRUE);
+}
+
+static bool_t authnone_refresh()
+{
+
+ return (FALSE);
+}
+
+static void authnone_destroy()
+{
+}
diff --git a/mdk-stage1/dietlibc/librpc/auth_unix.c b/mdk-stage1/dietlibc/librpc/auth_unix.c
new file mode 100644
index 000000000..5daeb5f4a
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/auth_unix.c
@@ -0,0 +1,313 @@
+/* @(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * auth_unix.c, Implements UNIX style authentication parameters.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The system is very weak. The client uses no encryption for it's
+ * credentials and only sends null verifiers. The server sends backs
+ * null verifiers or optionally a verifier that suggests a new short hand
+ * for the credentials.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * Unix authenticator operations vector
+ */
+static void authunix_nextverf();
+static bool_t authunix_marshal();
+static bool_t authunix_validate();
+static bool_t authunix_refresh();
+static void authunix_destroy();
+
+static struct auth_ops auth_unix_ops = {
+ authunix_nextverf,
+ authunix_marshal,
+ authunix_validate,
+ authunix_refresh,
+ authunix_destroy
+};
+
+/*
+ * This struct is pointed to by the ah_private field of an auth_handle.
+ */
+struct audata {
+ struct opaque_auth au_origcred; /* original credentials */
+ struct opaque_auth au_shcred; /* short hand cred */
+ u_long au_shfaults; /* short hand cache faults */
+ char au_marshed[MAX_AUTH_BYTES];
+ u_int au_mpos; /* xdr pos at end of marshed */
+};
+
+#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
+
+static void marshal_new_auth();
+
+
+/*
+ * Create a unix style authenticator.
+ * Returns an auth handle with the given stuff in it.
+ */
+AUTH *authunix_create __P ((char *machname, uid_t uid,
+ gid_t gid, int len,
+ gid_t *aup_gids))
+{
+ struct authunix_parms aup;
+ char mymem[MAX_AUTH_BYTES];
+ struct timeval now;
+ XDR xdrs;
+ register AUTH *auth;
+ register struct audata *au;
+
+ /*
+ * Allocate and set up auth handle
+ */
+ auth = (AUTH *) mem_alloc(sizeof(*auth));
+#ifndef KERNEL
+ if (auth == NULL) {
+ (void) fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ au = (struct audata *) mem_alloc(sizeof(*au));
+#ifndef KERNEL
+ if (au == NULL) {
+ (void) fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ auth->ah_ops = &auth_unix_ops;
+ auth->ah_private = (caddr_t) au;
+ auth->ah_verf = au->au_shcred = _null_auth;
+ au->au_shfaults = 0;
+
+ /*
+ * fill in param struct from the given params
+ */
+ (void) gettimeofday(&now, (struct timezone *) 0);
+ aup.aup_time = now.tv_sec;
+ aup.aup_machname = machname;
+ aup.aup_uid = uid;
+ aup.aup_gid = gid;
+ aup.aup_len = (u_int) len;
+ aup.aup_gids = aup_gids;
+
+ /*
+ * Serialize the parameters into origcred
+ */
+ xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
+ if (!xdr_authunix_parms(&xdrs, &aup))
+ abort();
+ au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
+ au->au_origcred.oa_flavor = AUTH_UNIX;
+#ifdef KERNEL
+ au->au_origcred.oa_base = mem_alloc((u_int) len);
+#else
+ if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
+ (void) fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ bcopy(mymem, au->au_origcred.oa_base, (u_int) len);
+
+ /*
+ * set auth handle to reflect new cred.
+ */
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+ return (auth);
+}
+
+/*
+ * Returns an auth handle with parameters determined by doing lots of
+ * syscalls.
+ */
+AUTH *authunix_create_default()
+{
+ register int len;
+ char machname[MAX_MACHINE_NAME + 1];
+ register int uid;
+ register int gid;
+ gid_t gids[NGRPS];
+
+ if (gethostname(machname, MAX_MACHINE_NAME) == -1)
+ abort();
+ machname[MAX_MACHINE_NAME] = 0;
+ uid = geteuid();
+ gid = getegid();
+ if ((len = getgroups(NGRPS, gids)) < 0)
+ abort();
+ return (authunix_create(machname, uid, gid, len, gids));
+}
+
+/*
+ * authunix operations
+ */
+
+static void authunix_nextverf(auth)
+AUTH *auth;
+{
+ /* no action necessary */
+}
+
+static bool_t authunix_marshal(auth, xdrs)
+AUTH *auth;
+XDR *xdrs;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
+}
+
+static bool_t authunix_validate(auth, verf)
+register AUTH *auth;
+struct opaque_auth verf;
+{
+ register struct audata *au;
+ XDR xdrs;
+
+ if (verf.oa_flavor == AUTH_SHORT) {
+ au = AUTH_PRIVATE(auth);
+ xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE);
+
+ if (au->au_shcred.oa_base != NULL) {
+ mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
+ au->au_shcred.oa_base = NULL;
+ }
+ if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
+ auth->ah_cred = au->au_shcred;
+ } else {
+ xdrs.x_op = XDR_FREE;
+ (void) xdr_opaque_auth(&xdrs, &au->au_shcred);
+ au->au_shcred.oa_base = NULL;
+ auth->ah_cred = au->au_origcred;
+ }
+ marshal_new_auth(auth);
+ }
+ return (TRUE);
+}
+
+static bool_t authunix_refresh(auth)
+register AUTH *auth;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+ struct authunix_parms aup;
+ struct timeval now;
+ XDR xdrs;
+ register int stat;
+
+ if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
+ /* there is no hope. Punt */
+ return (FALSE);
+ }
+ au->au_shfaults++;
+
+ /* first deserialize the creds back into a struct authunix_parms */
+ aup.aup_machname = NULL;
+ aup.aup_gids = (gid_t *) NULL;
+ xdrmem_create(&xdrs, au->au_origcred.oa_base,
+ au->au_origcred.oa_length, XDR_DECODE);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (!stat)
+ goto done;
+
+ /* update the time and serialize in place */
+ (void) gettimeofday(&now, (struct timezone *) 0);
+ aup.aup_time = now.tv_sec;
+ xdrs.x_op = XDR_ENCODE;
+ XDR_SETPOS(&xdrs, 0);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (!stat)
+ goto done;
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+ done:
+ /* free the struct authunix_parms created by deserializing */
+ xdrs.x_op = XDR_FREE;
+ (void) xdr_authunix_parms(&xdrs, &aup);
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+static void authunix_destroy(auth)
+register AUTH *auth;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
+
+ if (au->au_shcred.oa_base != NULL)
+ mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
+
+ mem_free(auth->ah_private, sizeof(struct audata));
+
+ if (auth->ah_verf.oa_base != NULL)
+ mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
+
+ mem_free((caddr_t) auth, sizeof(*auth));
+}
+
+/*
+ * Marshals (pre-serializes) an auth struct.
+ * sets private data, au_marshed and au_mpos
+ */
+static void marshal_new_auth(auth)
+register AUTH *auth;
+{
+ XDR xdr_stream;
+ register XDR *xdrs = &xdr_stream;
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
+ if ((!xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
+ (!xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
+ perror("auth_none.c - Fatal marshalling problem");
+ } else {
+ au->au_mpos = XDR_GETPOS(xdrs);
+ }
+ XDR_DESTROY(xdrs);
+}
diff --git a/mdk-stage1/dietlibc/librpc/authunix_prot.c b/mdk-stage1/dietlibc/librpc/authunix_prot.c
new file mode 100644
index 000000000..ddcadb808
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/authunix_prot.c
@@ -0,0 +1,69 @@
+/* @(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * authunix_prot.c
+ * XDR for UNIX style authentication parameters for RPC
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * XDR for unix authentication parameters.
+ */
+bool_t xdr_authunix_parms(xdrs, p)
+register XDR *xdrs;
+register struct authunix_parms *p;
+{
+ int a,b;
+
+ if (xdr_u_long(xdrs, &(p->aup_time))
+ && xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
+ && xdr_int(xdrs, &a)
+ && xdr_int(xdrs, &b)
+ && xdr_array(xdrs, (caddr_t *) & (p->aup_gids),
+ &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t)xdr_int)) {
+ p->aup_uid=(uid_t)a;
+ p->aup_gid=(gid_t)b;
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/bindresvport.c b/mdk-stage1/dietlibc/librpc/bindresvport.c
new file mode 100644
index 000000000..8b65261dd
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/bindresvport.c
@@ -0,0 +1,79 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1987 by Sun Microsystems, Inc.
+ */
+
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+/*
+ * Bind a socket to a privileged IP port
+ */
+int bindresvport(sd, sin)
+int sd;
+struct sockaddr_in *sin;
+{
+ int res;
+ static short port;
+ struct sockaddr_in myaddr;
+ extern int errno;
+ int i;
+
+#define STARTPORT 600
+#define ENDPORT (IPPORT_RESERVED - 1)
+#define NPORTS (ENDPORT - STARTPORT + 1)
+
+ if (sin == (struct sockaddr_in *) 0) {
+ sin = &myaddr;
+ bzero(sin, sizeof(*sin));
+ sin->sin_family = AF_INET;
+ } else if (sin->sin_family != AF_INET) {
+ errno = EPFNOSUPPORT;
+ return (-1);
+ }
+ if (port == 0) {
+ port = (getpid() % NPORTS) + STARTPORT;
+ }
+ res = -1;
+ errno = EADDRINUSE;
+ for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) {
+ sin->sin_port = htons(port++);
+ if (port > ENDPORT) {
+ port = STARTPORT;
+ }
+ res = bind(sd, (struct sockaddr*)sin, sizeof(struct sockaddr_in));
+ }
+ return (res);
+}
diff --git a/mdk-stage1/dietlibc/librpc/clnt_generic.c b/mdk-stage1/dietlibc/librpc/clnt_generic.c
new file mode 100644
index 000000000..9bb81cc80
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_generic.c
@@ -0,0 +1,112 @@
+/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
+#endif
+/*
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ */
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/*
+ * Generic client creation: takes (hostname, program-number, protocol) and
+ * returns client handle. Default options are set, which the user can
+ * change using the rpc equivalent of ioctl()'s.
+ */
+CLIENT *clnt_create __P ((const char *hostname, const u_long prog,
+ const u_long vers, const char *proto))
+{
+ struct hostent *h;
+ struct protoent *p;
+ struct sockaddr_in sin;
+ int sock;
+ struct timeval tv;
+ CLIENT *client;
+
+ h = gethostbyname(hostname);
+ if (h == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
+ return (NULL);
+ }
+ if (h->h_addrtype != AF_INET) {
+ /*
+ * Only support INET for now
+ */
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+#ifdef __linux__
+ bzero((char *) &sin, sizeof(sin));
+#endif
+ sin.sin_family = h->h_addrtype;
+ sin.sin_port = 0;
+#ifndef __linux__
+ bzero(sin.sin_zero, sizeof(sin.sin_zero));
+#endif
+ bcopy(h->h_addr, (char *) &sin.sin_addr, h->h_length);
+ p = getprotobyname(proto);
+ if (p == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ sock = RPC_ANYSOCK;
+ switch (p->p_proto) {
+ case IPPROTO_UDP:
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ client = clntudp_create(&sin, prog, vers, tv, &sock);
+ if (client == NULL) {
+ return (NULL);
+ }
+ tv.tv_sec = 25;
+ clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
+ break;
+ case IPPROTO_TCP:
+ client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
+ if (client == NULL) {
+ return (NULL);
+ }
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
+ break;
+ default:
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ return (client);
+}
diff --git a/mdk-stage1/dietlibc/librpc/clnt_perror.c b/mdk-stage1/dietlibc/librpc/clnt_perror.c
new file mode 100644
index 000000000..4ede1a43e
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_perror.c
@@ -0,0 +1,302 @@
+/* @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * clnt_perror.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+#include <stdio.h>
+
+#include <rpc/types.h>
+#include <rpc/auth.h>
+#include <rpc/clnt.h>
+
+//extern char *sys_errlist[];
+//static char *auth_errmsg();
+
+extern char *strcpy();
+
+#if 0
+static char *buf;
+
+static char *_buf()
+{
+
+ if (buf == 0)
+ buf = (char *) malloc(256);
+ return (buf);
+}
+#endif
+
+/*
+ * Print reply error info
+ */
+char *clnt_sperror __P ((CLIENT *rpch, const char *s))
+{
+#if 0
+ struct rpc_err e;
+ void clnt_perrno();
+ char *err;
+ char *str = _buf();
+ char *strstart = str;
+
+ if (str == 0)
+ return (0);
+ CLNT_GETERR(rpch, &e);
+
+ (void) sprintf(str, "%s: ", s);
+ str += strlen(str);
+
+ (void) strcpy(str, clnt_sperrno(e.re_status));
+ str += strlen(str);
+
+ switch (e.re_status) {
+ case RPC_SUCCESS:
+ case RPC_CANTENCODEARGS:
+ case RPC_CANTDECODERES:
+ case RPC_TIMEDOUT:
+ case RPC_PROGUNAVAIL:
+ case RPC_PROCUNAVAIL:
+ case RPC_CANTDECODEARGS:
+ case RPC_SYSTEMERROR:
+ case RPC_UNKNOWNHOST:
+ case RPC_UNKNOWNPROTO:
+ case RPC_PMAPFAILURE:
+ case RPC_PROGNOTREGISTERED:
+ case RPC_FAILED:
+ break;
+
+ case RPC_CANTSEND:
+ case RPC_CANTRECV:
+ (void) sprintf(str, "; errno = %s", sys_errlist[e.re_errno]);
+ str += strlen(str);
+ break;
+
+ case RPC_VERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu",
+ e.re_vers.low, e.re_vers.high);
+ str += strlen(str);
+ break;
+
+ case RPC_AUTHERROR:
+ err = auth_errmsg(e.re_why);
+ (void) sprintf(str, "; why = ");
+ str += strlen(str);
+ if (err != NULL) {
+ (void) sprintf(str, "%s", err);
+ } else {
+ (void) sprintf(str,
+ "(unknown authentication error - %d)",
+ (int) e.re_why);
+ }
+ str += strlen(str);
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu",
+ e.re_vers.low, e.re_vers.high);
+ str += strlen(str);
+ break;
+
+ default: /* unknown */
+ (void) sprintf(str,
+ "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
+ str += strlen(str);
+ break;
+ }
+ (void) sprintf(str, "\n");
+ return (strstart);
+#endif
+ return (0);
+}
+
+void clnt_perror __P ((CLIENT *rpch, const char *s))
+{
+ (void) fprintf(stderr, "%s", clnt_sperror(rpch, s));
+}
+
+
+struct rpc_errtab {
+ enum clnt_stat status;
+ char *message;
+};
+
+#if 0
+static struct rpc_errtab rpc_errlist[] = {
+ {RPC_SUCCESS,
+ "RPC: Success"},
+ {RPC_CANTENCODEARGS,
+ "RPC: Can't encode arguments"},
+ {RPC_CANTDECODERES,
+ "RPC: Can't decode result"},
+ {RPC_CANTSEND,
+ "RPC: Unable to send"},
+ {RPC_CANTRECV,
+ "RPC: Unable to receive"},
+ {RPC_TIMEDOUT,
+ "RPC: Timed out"},
+ {RPC_VERSMISMATCH,
+ "RPC: Incompatible versions of RPC"},
+ {RPC_AUTHERROR,
+ "RPC: Authentication error"},
+ {RPC_PROGUNAVAIL,
+ "RPC: Program unavailable"},
+ {RPC_PROGVERSMISMATCH,
+ "RPC: Program/version mismatch"},
+ {RPC_PROCUNAVAIL,
+ "RPC: Procedure unavailable"},
+ {RPC_CANTDECODEARGS,
+ "RPC: Server can't decode arguments"},
+ {RPC_SYSTEMERROR,
+ "RPC: Remote system error"},
+ {RPC_UNKNOWNHOST,
+ "RPC: Unknown host"},
+ {RPC_UNKNOWNPROTO,
+ "RPC: Unknown protocol"},
+ {RPC_PMAPFAILURE,
+ "RPC: Port mapper failure"},
+ {RPC_PROGNOTREGISTERED,
+ "RPC: Program not registered"},
+ {RPC_FAILED,
+ "RPC: Failed (unspecified error)"}
+};
+#endif
+
+/*
+ * This interface for use by clntrpc
+ */
+char *clnt_sperrno(stat)
+enum clnt_stat stat;
+{
+#if 0
+ int i;
+
+ for (i = 0; i < sizeof(rpc_errlist) / sizeof(struct rpc_errtab); i++) {
+ if (rpc_errlist[i].status == stat) {
+ return (rpc_errlist[i].message);
+ }
+ }
+#endif
+ return ("RPC: (unknown error code)");
+}
+
+void clnt_perrno(num)
+enum clnt_stat num;
+{
+ (void) fprintf(stderr, "%s", clnt_sperrno(num));
+}
+
+
+char *clnt_spcreateerror __P ((__const char *s))
+{
+#if 0
+ extern int sys_nerr;
+ extern char *sys_errlist[];
+ char *str = _buf();
+
+ if (str == 0)
+ return (0);
+ (void) sprintf(str, "%s: ", s);
+ (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
+ switch (rpc_createerr.cf_stat) {
+ case RPC_PMAPFAILURE:
+ (void) strcat(str, " - ");
+ (void) strcat(str, clnt_sperrno(rpc_createerr.cf_error.re_status));
+ break;
+
+ case RPC_SYSTEMERROR:
+ (void) strcat(str, " - ");
+ if (rpc_createerr.cf_error.re_errno > 0
+ && rpc_createerr.cf_error.re_errno < sys_nerr)
+ (void) strcat(str,
+ sys_errlist[rpc_createerr.cf_error.re_errno]);
+ else
+ (void) sprintf(&str[strlen(str)], "Error %d",
+ rpc_createerr.cf_error.re_errno);
+ break;
+ }
+ (void) strcat(str, "\n");
+ return (str);
+#endif
+ return(0);
+}
+
+extern void clnt_pcreateerror __P ((__const char *s))
+{
+ (void) fprintf(stderr, "%s", clnt_spcreateerror(s));
+}
+
+struct auth_errtab {
+ enum auth_stat status;
+ char *message;
+};
+
+#if 0
+static struct auth_errtab auth_errlist[] = {
+ {AUTH_OK,
+ "Authentication OK"},
+ {AUTH_BADCRED,
+ "Invalid client credential"},
+ {AUTH_REJECTEDCRED,
+ "Server rejected credential"},
+ {AUTH_BADVERF,
+ "Invalid client verifier"},
+ {AUTH_REJECTEDVERF,
+ "Server rejected verifier"},
+ {AUTH_TOOWEAK,
+ "Client credential too weak"},
+ {AUTH_INVALIDRESP,
+ "Invalid server verifier"},
+ {AUTH_FAILED,
+ "Failed (unspecified error)"},
+};
+
+static char *auth_errmsg(stat)
+enum auth_stat stat;
+{
+ int i;
+
+ for (i = 0; i < sizeof(auth_errlist) / sizeof(struct auth_errtab); i++) {
+ if (auth_errlist[i].status == stat) {
+ return (auth_errlist[i].message);
+ }
+ }
+ return (NULL);
+}
+#endif
diff --git a/mdk-stage1/dietlibc/librpc/clnt_raw.c b/mdk-stage1/dietlibc/librpc/clnt_raw.c
new file mode 100644
index 000000000..7479b55d6
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_raw.c
@@ -0,0 +1,230 @@
+/* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * clnt_raw.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Memory based rpc for simple testing and timing.
+ * Interface to create an rpc client and server in the same process.
+ * This lets us similate rpc and get round trip overhead, without
+ * any interference from the kernal.
+ */
+
+#include <rpc/rpc.h>
+
+#define MCALL_MSG_SIZE 24
+
+/*
+ * This is the "network" we will be moving stuff over.
+ */
+static struct clntraw_private {
+ CLIENT client_object;
+ XDR xdr_stream;
+ char _raw_buf[UDPMSGSIZE];
+ char mashl_callmsg[MCALL_MSG_SIZE];
+ u_int mcnt;
+} *clntraw_private;
+
+static enum clnt_stat clntraw_call();
+static void clntraw_abort();
+static void clntraw_geterr();
+static bool_t clntraw_freeres();
+static bool_t clntraw_control();
+static void clntraw_destroy();
+
+static struct clnt_ops client_ops = {
+ clntraw_call,
+ clntraw_abort,
+ clntraw_geterr,
+ clntraw_freeres,
+ clntraw_destroy,
+ clntraw_control
+};
+
+void svc_getreq();
+
+/*
+ * Create a client handle for memory based rpc.
+ */
+CLIENT *clntraw_create(prog, vers)
+u_long prog;
+u_long vers;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ struct rpc_msg call_msg;
+ XDR *xdrs = &clp->xdr_stream;
+ CLIENT *client = &clp->client_object;
+
+ if (clp == 0) {
+ clp = (struct clntraw_private *) calloc(1, sizeof(*clp));
+ if (clp == 0)
+ return (0);
+ clntraw_private = clp;
+ }
+ /*
+ * pre-serialize the staic part of the call msg and stash it away
+ */
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+ xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
+ if (!xdr_callhdr(xdrs, &call_msg)) {
+ perror("clnt_raw.c - Fatal header serialization error.");
+ }
+ clp->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+
+ /*
+ * Set xdrmem for client/server shared buffer
+ */
+ xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+
+ /*
+ * create client handle
+ */
+ client->cl_ops = &client_ops;
+ client->cl_auth = authnone_create();
+ return (client);
+}
+
+static enum clnt_stat
+clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
+CLIENT *h;
+u_long proc;
+xdrproc_t xargs;
+caddr_t argsp;
+xdrproc_t xresults;
+caddr_t resultsp;
+struct timeval timeout;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ register XDR *xdrs = &clp->xdr_stream;
+ struct rpc_msg msg;
+ enum clnt_stat status;
+ struct rpc_err error;
+
+ if (clp == 0)
+ return (RPC_FAILED);
+ call_again:
+ /*
+ * send request
+ */
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
+ if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
+ (!XDR_PUTLONG(xdrs, (long *) &proc)) ||
+ (!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
+ return (RPC_CANTENCODEARGS);
+ }
+ (void) XDR_GETPOS(xdrs); /* called just to cause overhead */
+
+ /*
+ * We have to call server input routine here because this is
+ * all going on in one process. Yuk.
+ */
+ svc_getreq(1);
+
+ /*
+ * get results
+ */
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = resultsp;
+ msg.acpted_rply.ar_results.proc = xresults;
+ if (!xdr_replymsg(xdrs, &msg))
+ return (RPC_CANTDECODERES);
+ _seterr_reply(&msg, &error);
+ status = error.re_status;
+
+ if (status == RPC_SUCCESS) {
+ if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ } /* end successful completion */
+ else {
+ if (AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+
+ if (status == RPC_SUCCESS) {
+ if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ if (msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void) xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
+ }
+ }
+
+ return (status);
+}
+
+static void clntraw_geterr()
+{
+}
+
+
+static bool_t clntraw_freeres(cl, xdr_res, res_ptr)
+CLIENT *cl;
+xdrproc_t xdr_res;
+caddr_t res_ptr;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ register XDR *xdrs = &clp->xdr_stream;
+ bool_t rval;
+
+ if (clp == 0) {
+ rval = (bool_t) RPC_FAILED;
+ return (rval);
+ }
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res) (xdrs, res_ptr));
+}
+
+static void clntraw_abort()
+{
+}
+
+static bool_t clntraw_control()
+{
+ return (FALSE);
+}
+
+static void clntraw_destroy()
+{
+}
diff --git a/mdk-stage1/dietlibc/librpc/clnt_simple.c b/mdk-stage1/dietlibc/librpc/clnt_simple.c
new file mode 100644
index 000000000..f309f86ff
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_simple.c
@@ -0,0 +1,116 @@
+/* @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * clnt_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
+
+static struct callrpc_private {
+ CLIENT *client;
+ int socket;
+ int oldprognum, oldversnum, valid;
+ char *oldhost;
+} *callrpc_private;
+
+int callrpc (const char *host, const u_long prognum,
+ const u_long versnum, const u_long procnum,
+ const xdrproc_t inproc, const char *in,
+ const xdrproc_t outproc, char *out)
+{
+ register struct callrpc_private *crp = callrpc_private;
+ struct sockaddr_in server_addr;
+ enum clnt_stat clnt_stat;
+ struct hostent *hp;
+ struct timeval timeout, tottimeout;
+
+ if (crp == 0) {
+ crp = (struct callrpc_private *) calloc(1, sizeof(*crp));
+ if (crp == 0)
+ return (0);
+ callrpc_private = crp;
+ }
+ if (crp->oldhost == NULL) {
+ crp->oldhost = malloc(256);
+ crp->oldhost[0] = 0;
+ crp->socket = RPC_ANYSOCK;
+ }
+ if (crp->valid && crp->oldprognum == prognum
+ && crp->oldversnum == versnum && strcmp(crp->oldhost, host) == 0) {
+ /* reuse old client */
+ } else {
+ crp->valid = 0;
+ (void) close(crp->socket);
+ crp->socket = RPC_ANYSOCK;
+ if (crp->client) {
+ clnt_destroy(crp->client);
+ crp->client = NULL;
+ }
+ if ((hp = gethostbyname(host)) == NULL)
+ return ((int) RPC_UNKNOWNHOST);
+ timeout.tv_usec = 0;
+ timeout.tv_sec = 5;
+ bcopy(hp->h_addr, (char *) &server_addr.sin_addr, hp->h_length);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ if ((crp->client = clntudp_create(&server_addr, (u_long) prognum,
+ (u_long) versnum, timeout,
+ &crp->socket)) == NULL)
+ return ((int) rpc_createerr.cf_stat);
+ crp->valid = 1;
+ crp->oldprognum = prognum;
+ crp->oldversnum = versnum;
+ (void) strcpy(crp->oldhost, host);
+ }
+ tottimeout.tv_sec = 25;
+ tottimeout.tv_usec = 0;
+ clnt_stat = clnt_call(crp->client, procnum, inproc, (char*)in,
+ outproc, out, tottimeout);
+ /*
+ * if call failed, empty cache
+ */
+ if (clnt_stat != RPC_SUCCESS)
+ crp->valid = 0;
+ return ((int) clnt_stat);
+}
diff --git a/mdk-stage1/dietlibc/librpc/clnt_tcp.c b/mdk-stage1/dietlibc/librpc/clnt_tcp.c
new file mode 100644
index 000000000..8c39e8933
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_tcp.c
@@ -0,0 +1,463 @@
+/* @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * TCP based RPC supports 'batched calls'.
+ * A sequence of calls may be batched-up in a send buffer. The rpc call
+ * return immediately to the client even though the call was not necessarily
+ * sent. The batching occurs if the results' xdr routine is NULL (0) AND
+ * the rpc timeout value is zero (see clnt.h, rpc).
+ *
+ * Clients should NOT casually batch calls that in fact return results; that is,
+ * the server side should be aware that a call is batched and not produce any
+ * return message. Batched calls that produce many result messages can
+ * deadlock (netlock) the client and the server....
+ *
+ * Now go hang yourself.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+#include <unistd.h>
+
+#define MCALL_MSG_SIZE 24
+
+extern int errno;
+
+static int readtcp();
+static int writetcp();
+
+static enum clnt_stat clnttcp_call();
+static void clnttcp_abort();
+static void clnttcp_geterr();
+static bool_t clnttcp_freeres();
+static bool_t clnttcp_control();
+static void clnttcp_destroy();
+
+static struct clnt_ops tcp_ops = {
+ clnttcp_call,
+ clnttcp_abort,
+ clnttcp_geterr,
+ clnttcp_freeres,
+ clnttcp_destroy,
+ clnttcp_control
+};
+
+struct ct_data {
+ int ct_sock;
+ bool_t ct_closeit;
+ struct timeval ct_wait;
+ bool_t ct_waitset; /* wait set by clnt_control? */
+ struct sockaddr_in ct_addr;
+ struct rpc_err ct_error;
+ char ct_mcall[MCALL_MSG_SIZE]; /* marshalled callmsg */
+ u_int ct_mpos; /* pos after marshal */
+ XDR ct_xdrs;
+};
+
+/*
+ * Create a client handle for a tcp/ip connection.
+ * If *sockp<0, *sockp is set to a newly created TCP socket and it is
+ * connected to raddr. If *sockp non-negative then
+ * raddr is ignored. The rpc/tcp package does buffering
+ * similar to stdio, so the client must pick send and receive buffer sizes,];
+ * 0 => use the default.
+ * If raddr->sin_port is 0, then a binder on the remote machine is
+ * consulted for the right port number.
+ * NB: *sockp is copied into a private area.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is set null authentication. Caller may wish to set this
+ * something more useful.
+ */
+CLIENT *clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
+struct sockaddr_in *raddr;
+u_long prog;
+u_long vers;
+register int *sockp;
+u_int sendsz;
+u_int recvsz;
+{
+ CLIENT *h;
+ register struct ct_data *ct;
+ struct timeval now;
+ struct rpc_msg call_msg;
+
+ h = (CLIENT *) mem_alloc(sizeof(*h));
+ if (h == NULL) {
+ (void) fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ ct = (struct ct_data *) mem_alloc(sizeof(*ct));
+ if (ct == NULL) {
+ (void) fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+
+ /*
+ * If no port number given ask the pmap for one
+ */
+ if (raddr->sin_port == 0) {
+ u_short port;
+
+ if ((port = pmap_getport(raddr, prog, vers, IPPROTO_TCP)) == 0) {
+ mem_free((caddr_t) ct, sizeof(struct ct_data));
+
+ mem_free((caddr_t) h, sizeof(CLIENT));
+ return ((CLIENT *) NULL);
+ }
+ raddr->sin_port = htons(port);
+ }
+
+ /*
+ * If no socket given, open one
+ */
+ if (*sockp < 0) {
+ *sockp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ (void) bindresvport(*sockp, (struct sockaddr_in *) 0);
+ if ((*sockp < 0)
+ || (connect(*sockp, (struct sockaddr *) raddr,
+ sizeof(*raddr)) < 0)) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ (void) close(*sockp);
+ goto fooy;
+ }
+ ct->ct_closeit = TRUE;
+ } else {
+ ct->ct_closeit = FALSE;
+ }
+
+ /*
+ * Set up private data struct
+ */
+ ct->ct_sock = *sockp;
+ ct->ct_wait.tv_usec = 0;
+ ct->ct_waitset = FALSE;
+ ct->ct_addr = *raddr;
+
+ /*
+ * Initialize call message
+ */
+ (void) gettimeofday(&now, (struct timezone *) 0);
+ call_msg.rm_xid = getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+
+ /*
+ * pre-serialize the staic part of the call msg and stash it away
+ */
+ xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
+ XDR_ENCODE);
+ if (!xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
+ if (ct->ct_closeit) {
+ (void) close(*sockp);
+ }
+ goto fooy;
+ }
+ ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
+ XDR_DESTROY(&(ct->ct_xdrs));
+
+ /*
+ * Create a client handle which uses xdrrec for serialization
+ * and authnone for authentication.
+ */
+ xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
+ (caddr_t) ct, readtcp, writetcp);
+ h->cl_ops = &tcp_ops;
+ h->cl_private = (caddr_t) ct;
+ h->cl_auth = authnone_create();
+ return (h);
+
+ fooy:
+ /*
+ * Something goofed, free stuff and barf
+ */
+ mem_free((caddr_t) ct, sizeof(struct ct_data));
+
+ mem_free((caddr_t) h, sizeof(CLIENT));
+ return ((CLIENT *) NULL);
+}
+
+static enum clnt_stat
+clnttcp_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr,
+ timeout)
+register CLIENT *h;
+u_long proc;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+xdrproc_t xdr_results;
+caddr_t results_ptr;
+struct timeval timeout;
+{
+ register struct ct_data *ct = (struct ct_data *) h->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+ struct rpc_msg reply_msg;
+ u_long x_id;
+ u_long *msg_x_id = (u_long *) (ct->ct_mcall); /* yuk */
+ register bool_t shipnow;
+ int refreshes = 2;
+
+ if (!ct->ct_waitset) {
+ ct->ct_wait = timeout;
+ }
+
+ shipnow =
+ (xdr_results == (xdrproc_t) 0 && timeout.tv_sec == 0
+ && timeout.tv_usec == 0) ? FALSE : TRUE;
+
+ call_again:
+ xdrs->x_op = XDR_ENCODE;
+ ct->ct_error.re_status = RPC_SUCCESS;
+ x_id = ntohl(--(*msg_x_id));
+ if ((!XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
+ (!XDR_PUTLONG(xdrs, (long *) &proc)) ||
+ (!AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (!(*xdr_args) (xdrs, args_ptr))) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTENCODEARGS;
+ (void) xdrrec_endofrecord(xdrs, TRUE);
+ return (ct->ct_error.re_status);
+ }
+ if (!xdrrec_endofrecord(xdrs, shipnow))
+ return (ct->ct_error.re_status = RPC_CANTSEND);
+ if (!shipnow)
+ return (RPC_SUCCESS);
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+ return (ct->ct_error.re_status = RPC_TIMEDOUT);
+ }
+
+
+ /*
+ * Keep receiving until we get a valid transaction id
+ */
+ xdrs->x_op = XDR_DECODE;
+ while (TRUE) {
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = NULL;
+ reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
+ if (!xdrrec_skiprecord(xdrs))
+ return (ct->ct_error.re_status);
+ /* now decode and validate the response header */
+ if (!xdr_replymsg(xdrs, &reply_msg)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ continue;
+ return (ct->ct_error.re_status);
+ }
+ if (reply_msg.rm_xid == x_id)
+ break;
+ }
+
+ /*
+ * process header
+ */
+ _seterr_reply(&reply_msg, &(ct->ct_error));
+ if (ct->ct_error.re_status == RPC_SUCCESS) {
+ if (!AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf)) {
+ ct->ct_error.re_status = RPC_AUTHERROR;
+ ct->ct_error.re_why = AUTH_INVALIDRESP;
+ } else if (!(*xdr_results) (xdrs, results_ptr)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTDECODERES;
+ }
+ /* free verifier ... */
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void) xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (refreshes-- && AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+ return (ct->ct_error.re_status);
+}
+
+static void clnttcp_geterr(h, errp)
+CLIENT *h;
+struct rpc_err *errp;
+{
+ register struct ct_data *ct = (struct ct_data *) h->cl_private;
+
+ *errp = ct->ct_error;
+}
+
+static bool_t clnttcp_freeres(cl, xdr_res, res_ptr)
+CLIENT *cl;
+xdrproc_t xdr_res;
+caddr_t res_ptr;
+{
+ register struct ct_data *ct = (struct ct_data *) cl->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res) (xdrs, res_ptr));
+}
+
+static void clnttcp_abort()
+{
+}
+
+static bool_t clnttcp_control(cl, request, info)
+CLIENT *cl;
+int request;
+char *info;
+{
+ register struct ct_data *ct = (struct ct_data *) cl->cl_private;
+
+ switch (request) {
+ case CLSET_TIMEOUT:
+ ct->ct_wait = *(struct timeval *) info;
+ ct->ct_waitset = TRUE;
+ break;
+ case CLGET_TIMEOUT:
+ *(struct timeval *) info = ct->ct_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ *(struct sockaddr_in *) info = ct->ct_addr;
+ break;
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+
+static void clnttcp_destroy(h)
+CLIENT *h;
+{
+ register struct ct_data *ct = (struct ct_data *) h->cl_private;
+
+ if (ct->ct_closeit) {
+ (void) close(ct->ct_sock);
+ }
+ XDR_DESTROY(&(ct->ct_xdrs));
+ mem_free((caddr_t) ct, sizeof(struct ct_data));
+
+ mem_free((caddr_t) h, sizeof(CLIENT));
+}
+
+/*
+ * Interface between xdr serializer and tcp connection.
+ * Behaves like the system calls, read & write, but keeps some error state
+ * around for the rpc level.
+ */
+static int readtcp(ct, buf, len)
+register struct ct_data *ct;
+caddr_t buf;
+register int len;
+{
+#ifdef FD_SETSIZE
+ fd_set mask;
+ fd_set readfds;
+
+ if (len == 0)
+ return (0);
+ FD_ZERO(&mask);
+ FD_SET(ct->ct_sock, &mask);
+#else
+ register int mask = 1 << (ct->ct_sock);
+ int readfds;
+
+ if (len == 0)
+ return (0);
+
+#endif /* def FD_SETSIZE */
+ while (TRUE) {
+ readfds = mask;
+ switch (select
+ (_rpc_dtablesize(), &readfds, 0, 0,
+ &(ct->ct_wait))) {
+ case 0:
+ ct->ct_error.re_status = RPC_TIMEDOUT;
+ return (-1);
+
+ case -1:
+ if (errno == EINTR)
+ continue;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ ct->ct_error.re_errno = errno;
+ return (-1);
+ }
+ break;
+ }
+ switch (len = read(ct->ct_sock, buf, len)) {
+
+ case 0:
+ /* premature eof */
+ ct->ct_error.re_errno = ECONNRESET;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ len = -1; /* it's really an error */
+ break;
+
+ case -1:
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ break;
+ }
+ return (len);
+}
+
+static int writetcp(ct, buf, len)
+struct ct_data *ct;
+caddr_t buf;
+int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = write(ct->ct_sock, buf, cnt)) == -1) {
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTSEND;
+ return (-1);
+ }
+ }
+ return (len);
+}
diff --git a/mdk-stage1/dietlibc/librpc/clnt_udp.c b/mdk-stage1/dietlibc/librpc/clnt_udp.c
new file mode 100644
index 000000000..7305d3ff1
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/clnt_udp.c
@@ -0,0 +1,437 @@
+/* @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * clnt_udp.c, Implements a UDP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+#include <unistd.h>
+
+extern int errno;
+
+/*
+ * UDP bases client side rpc operations
+ */
+static enum clnt_stat clntudp_call();
+static void clntudp_abort();
+static void clntudp_geterr();
+static bool_t clntudp_freeres();
+static bool_t clntudp_control();
+static void clntudp_destroy();
+
+static struct clnt_ops udp_ops = {
+ clntudp_call,
+ clntudp_abort,
+ clntudp_geterr,
+ clntudp_freeres,
+ clntudp_destroy,
+ clntudp_control
+};
+
+/*
+ * Private data kept per client handle
+ */
+struct cu_data {
+ int cu_sock;
+ bool_t cu_closeit;
+ struct sockaddr_in cu_raddr;
+ int cu_rlen;
+ struct timeval cu_wait;
+ struct timeval cu_total;
+ struct rpc_err cu_error;
+ XDR cu_outxdrs;
+ u_int cu_xdrpos;
+ u_int cu_sendsz;
+ char *cu_outbuf;
+ u_int cu_recvsz;
+ char cu_inbuf[1];
+};
+
+/*
+ * Create a UDP based client handle.
+ * If *sockp<0, *sockp is set to a newly created UPD socket.
+ * If raddr->sin_port is 0 a binder on the remote machine
+ * is consulted for the correct port number.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is initialized to null authentication.
+ * Caller may wish to set this something more useful.
+ *
+ * wait is the amount of time used between retransmitting a call if
+ * no response has been heard; retransmition occurs until the actual
+ * rpc call times out.
+ *
+ * sendsz and recvsz are the maximum allowable packet sizes that can be
+ * sent and received.
+ */
+CLIENT *clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz,
+ recvsz)
+struct sockaddr_in *raddr;
+u_long program;
+u_long version;
+struct timeval wait;
+register int *sockp;
+u_int sendsz;
+u_int recvsz;
+{
+ CLIENT *cl;
+ register struct cu_data *cu;
+ struct timeval now;
+ struct rpc_msg call_msg;
+
+ cl = (CLIENT *) mem_alloc(sizeof(CLIENT));
+ if (cl == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ sendsz = ((sendsz + 3) / 4) * 4;
+ recvsz = ((recvsz + 3) / 4) * 4;
+ cu = (struct cu_data *) mem_alloc(sizeof(*cu) + sendsz + recvsz);
+ if (cu == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ cu->cu_outbuf = &cu->cu_inbuf[recvsz];
+
+ (void) gettimeofday(&now, (struct timezone *) 0);
+ if (raddr->sin_port == 0) {
+ u_short port;
+
+ if ((port =
+ pmap_getport(raddr, program, version, IPPROTO_UDP)) == 0) {
+ goto fooy;
+ }
+ raddr->sin_port = htons(port);
+ }
+ cl->cl_ops = &udp_ops;
+ cl->cl_private = (caddr_t) cu;
+ cu->cu_raddr = *raddr;
+ cu->cu_rlen = sizeof(cu->cu_raddr);
+ cu->cu_wait = wait;
+ cu->cu_total.tv_sec = -1;
+ cu->cu_total.tv_usec = -1;
+ cu->cu_sendsz = sendsz;
+ cu->cu_recvsz = recvsz;
+ call_msg.rm_xid = getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = program;
+ call_msg.rm_call.cb_vers = version;
+ xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf, sendsz, XDR_ENCODE);
+ if (!xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
+ goto fooy;
+ }
+ cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
+ if (*sockp < 0) {
+ int dontblock = 1;
+
+ *sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (*sockp < 0) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ /* attempt to bind to prov port */
+ (void) bindresvport(*sockp, (struct sockaddr_in *) 0);
+ /* the sockets rpc controls are non-blocking */
+ (void) ioctl(*sockp, FIONBIO, (char *) &dontblock);
+ cu->cu_closeit = TRUE;
+ } else {
+ cu->cu_closeit = FALSE;
+ }
+ cu->cu_sock = *sockp;
+ cl->cl_auth = authnone_create();
+ return (cl);
+ fooy:
+ if (cu)
+ mem_free((caddr_t) cu, sizeof(*cu) + sendsz + recvsz);
+ if (cl)
+ mem_free((caddr_t) cl, sizeof(CLIENT));
+ return ((CLIENT *) NULL);
+}
+
+CLIENT *clntudp_create(raddr, program, version, wait, sockp)
+struct sockaddr_in *raddr;
+u_long program;
+u_long version;
+struct timeval wait;
+register int *sockp;
+{
+
+ return (clntudp_bufcreate(raddr, program, version, wait, sockp,
+ UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum clnt_stat
+clntudp_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
+register CLIENT *cl; /* client handle */
+u_long proc; /* procedure number */
+xdrproc_t xargs; /* xdr routine for args */
+caddr_t argsp; /* pointer to args */
+xdrproc_t xresults; /* xdr routine for results */
+caddr_t resultsp; /* pointer to results */
+struct timeval utimeout; /* seconds to wait before giving up */
+{
+ register struct cu_data *cu = (struct cu_data *) cl->cl_private;
+ register XDR *xdrs;
+ register int outlen;
+ register int inlen;
+ int fromlen;
+
+#ifdef FD_SETSIZE
+ fd_set readfds;
+ fd_set mask;
+#else
+ int readfds;
+ register int mask;
+#endif /* def FD_SETSIZE */
+ struct sockaddr_in from;
+ struct rpc_msg reply_msg;
+ XDR reply_xdrs;
+ struct timeval time_waited;
+ bool_t ok;
+ int nrefreshes = 2; /* number of times to refresh cred */
+ struct timeval timeout;
+
+ if (cu->cu_total.tv_usec == -1) {
+ timeout = utimeout; /* use supplied timeout */
+ } else {
+ timeout = cu->cu_total; /* use default timeout */
+ }
+
+ time_waited.tv_sec = 0;
+ time_waited.tv_usec = 0;
+ call_again:
+ xdrs = &(cu->cu_outxdrs);
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, cu->cu_xdrpos);
+ /*
+ * the transaction is the first thing in the out buffer
+ */
+ (*(u_short *) (cu->cu_outbuf))++;
+ if ((!XDR_PUTLONG(xdrs, (long *) &proc)) ||
+ (!AUTH_MARSHALL(cl->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp)))
+ return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
+ outlen = (int) XDR_GETPOS(xdrs);
+
+ send_again:
+ if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0,
+ (struct sockaddr *) &(cu->cu_raddr), cu->cu_rlen)
+ != outlen) {
+ cu->cu_error.re_errno = errno;
+ return (cu->cu_error.re_status = RPC_CANTSEND);
+ }
+
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+ }
+ /*
+ * sub-optimal code appears here because we have
+ * some clock time to spare while the packets are in flight.
+ * (We assume that this is actually only executed once.)
+ */
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = resultsp;
+ reply_msg.acpted_rply.ar_results.proc = xresults;
+#ifdef FD_SETSIZE
+ FD_ZERO(&mask);
+ FD_SET(cu->cu_sock, &mask);
+#else
+ mask = 1 << cu->cu_sock;
+#endif /* def FD_SETSIZE */
+ for (;;) {
+ readfds = mask;
+ switch (select(_rpc_dtablesize(), &readfds, 0, 0, &(cu->cu_wait))) {
+
+ case 0:
+ time_waited.tv_sec += cu->cu_wait.tv_sec;
+ time_waited.tv_usec += cu->cu_wait.tv_usec;
+ while (time_waited.tv_usec >= 1000000) {
+ time_waited.tv_sec++;
+ time_waited.tv_usec -= 1000000;
+ }
+ if ((time_waited.tv_sec < timeout.tv_sec) ||
+ ((time_waited.tv_sec == timeout.tv_sec) &&
+ (time_waited.tv_usec < timeout.tv_usec)))
+ goto send_again;
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+
+ /*
+ * buggy in other cases because time_waited is not being
+ * updated.
+ */
+ case -1:
+ if (errno == EINTR)
+ continue;
+ cu->cu_error.re_errno = errno;
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+ do {
+ fromlen = sizeof(struct sockaddr);
+
+ inlen = recvfrom(cu->cu_sock, cu->cu_inbuf,
+ (int) cu->cu_recvsz, 0,
+ (struct sockaddr *) &from, &fromlen);
+ } while (inlen < 0 && errno == EINTR);
+ if (inlen < 0) {
+ if (errno == EWOULDBLOCK)
+ continue;
+ cu->cu_error.re_errno = errno;
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+ if (inlen < sizeof(u_long))
+ continue;
+ /* see if reply transaction id matches sent id */
+ if (*((u_long *) (cu->cu_inbuf)) != *((u_long *) (cu->cu_outbuf)))
+ continue;
+ /* we now assume we have the proper reply */
+ break;
+ }
+
+ /*
+ * now decode and validate the response
+ */
+ xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int) inlen, XDR_DECODE);
+ ok = xdr_replymsg(&reply_xdrs, &reply_msg);
+ /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
+ if (ok) {
+ _seterr_reply(&reply_msg, &(cu->cu_error));
+ if (cu->cu_error.re_status == RPC_SUCCESS) {
+ if (!AUTH_VALIDATE(cl->cl_auth,
+ &reply_msg.acpted_rply.ar_verf)) {
+ cu->cu_error.re_status = RPC_AUTHERROR;
+ cu->cu_error.re_why = AUTH_INVALIDRESP;
+ }
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void) xdr_opaque_auth(xdrs,
+ &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (nrefreshes > 0 && AUTH_REFRESH(cl->cl_auth)) {
+ nrefreshes--;
+ goto call_again;
+ }
+ } /* end of unsuccessful completion */
+ } /* end of valid reply message */
+ else {
+ cu->cu_error.re_status = RPC_CANTDECODERES;
+ }
+ return (cu->cu_error.re_status);
+}
+
+static void clntudp_geterr(cl, errp)
+CLIENT *cl;
+struct rpc_err *errp;
+{
+ register struct cu_data *cu = (struct cu_data *) cl->cl_private;
+
+ *errp = cu->cu_error;
+}
+
+
+static bool_t clntudp_freeres(cl, xdr_res, res_ptr)
+CLIENT *cl;
+xdrproc_t xdr_res;
+caddr_t res_ptr;
+{
+ register struct cu_data *cu = (struct cu_data *) cl->cl_private;
+ register XDR *xdrs = &(cu->cu_outxdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res) (xdrs, res_ptr));
+}
+
+static void clntudp_abort( /*h */ )
+ /*CLIENT *h; */
+{
+}
+
+static bool_t clntudp_control(cl, request, info)
+CLIENT *cl;
+int request;
+char *info;
+{
+ register struct cu_data *cu = (struct cu_data *) cl->cl_private;
+
+ switch (request) {
+ case CLSET_TIMEOUT:
+ cu->cu_total = *(struct timeval *) info;
+ break;
+ case CLGET_TIMEOUT:
+ *(struct timeval *) info = cu->cu_total;
+ break;
+ case CLSET_RETRY_TIMEOUT:
+ cu->cu_wait = *(struct timeval *) info;
+ break;
+ case CLGET_RETRY_TIMEOUT:
+ *(struct timeval *) info = cu->cu_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ *(struct sockaddr_in *) info = cu->cu_raddr;
+ break;
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+static void clntudp_destroy(cl)
+CLIENT *cl;
+{
+ register struct cu_data *cu = (struct cu_data *) cl->cl_private;
+
+ if (cu->cu_closeit) {
+ (void) close(cu->cu_sock);
+ }
+ XDR_DESTROY(&(cu->cu_outxdrs));
+ mem_free((caddr_t) cu, (sizeof(*cu) + cu->cu_sendsz + cu->cu_recvsz));
+ mem_free((caddr_t) cl, sizeof(CLIENT));
+}
diff --git a/mdk-stage1/dietlibc/librpc/get_myaddress.c b/mdk-stage1/dietlibc/librpc/get_myaddress.c
new file mode 100644
index 000000000..cd63383d0
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/get_myaddress.c
@@ -0,0 +1,69 @@
+/* @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * get_myaddress.c
+ *
+ * Get client's IP address via ioctl. This avoids using the yellowpages.
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/pmap_prot.h>
+#include <sys/socket.h>
+#include <stdio.h>
+//#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+/* DO use gethostbyname because it's portable */
+#include <unistd.h>
+#include <netdb.h>
+#include <string.h>
+void get_myaddress(struct sockaddr_in* addr)
+{
+ char localhost[256 + 1];
+ struct hostent *hp;
+
+ gethostname(localhost, 256);
+ if ((hp = gethostbyname(localhost)) == NULL) {
+ perror("get_myaddress: gethostbyname");
+ exit(1);
+ }
+ addr->sin_family = AF_INET;
+ bcopy((char *) hp->h_addr, (char *) &addr->sin_addr, hp->h_length);
+ addr->sin_port = htons(PMAPPORT);
+}
diff --git a/mdk-stage1/dietlibc/librpc/getrpcent.c b/mdk-stage1/dietlibc/librpc/getrpcent.c
new file mode 100644
index 000000000..5e7f694d2
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/getrpcent.c
@@ -0,0 +1,274 @@
+/* @(#)getrpcent.c 2.2 88/07/29 4.0 RPCSRC */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)getrpcent.c 1.9 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1985 by Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <rpc/rpc.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+
+/*
+ * Internet version.
+ */
+struct rpcdata {
+ FILE *rpcf;
+ char *current;
+ int currentlen;
+ int stayopen;
+#define MAXALIASES 35
+ char *rpc_aliases[MAXALIASES];
+ struct rpcent rpc;
+ char line[BUFSIZ + 1];
+ char *domain;
+} *rpcdata;
+
+static struct rpcent *interpret();
+struct hostent *gethostent();
+char *inet_ntoa();
+
+#ifndef __linux__
+static char *index();
+#else
+char *index();
+#endif
+
+static char RPCDB[] = "/etc/rpc";
+
+static struct rpcdata *_rpcdata()
+{
+ register struct rpcdata *d = rpcdata;
+
+ if (d == 0) {
+ d = (struct rpcdata *) calloc(1, sizeof(struct rpcdata));
+
+ rpcdata = d;
+ }
+ return (d);
+}
+
+struct rpcent *getrpcbynumber(number)
+register int number;
+{
+ register struct rpcdata *d = _rpcdata();
+ register struct rpcent *p;
+
+ if (d == 0)
+ return (0);
+ setrpcent(0);
+ while ((p = getrpcent())) {
+ if (p->r_number == number)
+ break;
+ }
+ endrpcent();
+ return (p);
+}
+
+struct rpcent *
+#ifdef __linux__
+getrpcbyname(const char *name)
+#else
+getrpcbyname(name)
+char *name;
+#endif
+{
+ struct rpcent *rpc;
+ char **rp;
+
+ setrpcent(0);
+ while ((rpc = getrpcent())) {
+ if (strcmp(rpc->r_name, name) == 0)
+ return (rpc);
+ for (rp = rpc->r_aliases; *rp != NULL; rp++) {
+ if (strcmp(*rp, name) == 0)
+ return (rpc);
+ }
+ }
+ endrpcent();
+ return (NULL);
+}
+
+#ifdef __linux__
+void
+#endif
+setrpcent(f)
+int f;
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+ if (d->rpcf == NULL)
+ d->rpcf = fopen(RPCDB, "r");
+ else
+ rewind(d->rpcf);
+ if (d->current)
+ free(d->current);
+ d->current = NULL;
+ d->stayopen |= f;
+}
+
+#ifdef __linux__
+void
+#endif
+endrpcent()
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+ if (d->current && !d->stayopen) {
+ free(d->current);
+ d->current = NULL;
+ }
+ if (d->rpcf && !d->stayopen) {
+ fclose(d->rpcf);
+ d->rpcf = NULL;
+ }
+}
+
+struct rpcent *getrpcent()
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return (NULL);
+ if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
+ return (NULL);
+ if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
+ return (NULL);
+ return interpret(d->line, strlen(d->line));
+}
+
+#ifdef __linux__
+static char *firstwhite(s)
+char *s;
+{
+ char *s1, *s2;
+
+ s1 = index(s, ' ');
+ s2 = index(s, '\t');
+ if (s1) {
+ if (s2)
+ return (s1 < s2) ? s1 : s2;
+ else
+ return s1;
+ } else
+ return s2;
+}
+#endif
+
+static struct rpcent *interpret(const char* val, int len)
+{
+ register struct rpcdata *d = _rpcdata();
+ char *p;
+ register char *cp, **q;
+
+ if (d == 0)
+ return 0;
+ strncpy(d->line, val, len);
+ p = d->line;
+ d->line[len] = '\n';
+ if (*p == '#')
+ return (getrpcent());
+ cp = index(p, '#');
+ if (cp == NULL) {
+ cp = index(p, '\n');
+ if (cp == NULL)
+ return (getrpcent());
+ }
+ *cp = '\0';
+#ifdef __linux__
+ if ((cp = firstwhite(p)))
+ *cp++ = 0;
+ else
+ return (getrpcent());
+#else
+ cp = index(p, ' ');
+ if (cp == NULL) {
+ cp = index(p, '\t');
+ if (cp == NULL)
+ return (getrpcent());
+ }
+ *cp++ = '\0';
+#endif
+ /* THIS STUFF IS INTERNET SPECIFIC */
+ d->rpc.r_name = d->line;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ d->rpc.r_number = atoi(cp);
+ q = d->rpc.r_aliases = d->rpc_aliases;
+#ifdef __linux__
+ if ((cp = firstwhite(cp)))
+ *cp++ = '\0';
+#else
+ cp = index(p, ' ');
+ if (cp != NULL)
+ *cp++ = '\0';
+ else {
+ cp = index(p, '\t');
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+#endif
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &(d->rpc_aliases[MAXALIASES - 1]))
+ *q++ = cp;
+#ifdef __linux__
+ if ((cp = firstwhite(cp)))
+ *cp++ = '\0';
+#else
+ cp = index(p, ' ');
+ if (cp != NULL)
+ *cp++ = '\0';
+ else {
+ cp = index(p, '\t');
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+#endif
+ }
+ *q = NULL;
+ return (&d->rpc);
+}
diff --git a/mdk-stage1/dietlibc/librpc/getrpcport.c b/mdk-stage1/dietlibc/librpc/getrpcport.c
new file mode 100644
index 000000000..a7085cbe7
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/getrpcport.c
@@ -0,0 +1,57 @@
+/* @(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)getrpcport.c 1.3 87/08/11 SMI";
+#endif
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1985 by Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <rpc/pmap_clnt.h>
+
+extern int getrpcport (const char * host, u_long prognum,
+ u_long versnum, u_int proto)
+{
+ struct sockaddr_in addr;
+ struct hostent *hp;
+
+ if ((hp = gethostbyname(host)) == NULL)
+ return (0);
+ bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length);
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ return (pmap_getport(&addr, prognum, versnum, proto));
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_clnt.c b/mdk-stage1/dietlibc/librpc/pmap_clnt.c
new file mode 100644
index 000000000..428675656
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_clnt.c
@@ -0,0 +1,118 @@
+/* @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_clnt.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <unistd.h>
+
+static struct timeval timeout = { 5, 0 };
+static struct timeval tottimeout = { 60, 0 };
+
+void clnt_perror();
+
+
+/*
+ * Set a mapping between program,version and port.
+ * Calls the pmap service remotely to do the mapping.
+ */
+bool_t pmap_set(program, version, protocol, port)
+u_long program;
+u_long version;
+int protocol;
+u_short port;
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+
+ get_myaddress(&myaddress);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE,
+ RPCSMALLMSGSIZE);
+ if (client == (CLIENT *) NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = port;
+ if (CLNT_CALL(client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, (caddr_t)&parms, (xdrproc_t)xdr_bool, (caddr_t)&rslt,
+ tottimeout) != RPC_SUCCESS) {
+ clnt_perror(client, "Cannot register service");
+ return (FALSE);
+ }
+ CLNT_DESTROY(client);
+ (void) close(socket);
+ return (rslt);
+}
+
+/*
+ * Remove the mapping between program,version and port.
+ * Calls the pmap service remotely to do the un-mapping.
+ */
+bool_t pmap_unset(program, version)
+u_long program;
+u_long version;
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+
+ get_myaddress(&myaddress);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE,
+ RPCSMALLMSGSIZE);
+ if (client == (CLIENT *) NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_port = parms.pm_prot = 0;
+ CLNT_CALL(client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, (caddr_t)&parms, (xdrproc_t)xdr_bool, (caddr_t)&rslt,
+ tottimeout);
+ CLNT_DESTROY(client);
+ (void) close(socket);
+ return (rslt);
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_getmaps.c b/mdk-stage1/dietlibc/librpc/pmap_getmaps.c
new file mode 100644
index 000000000..6940783fb
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_getmaps.c
@@ -0,0 +1,85 @@
+/* @(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_getmap.c
+ * Client interface to pmap rpc service.
+ * contains pmap_getmaps, which is only tcp service involved
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <errno.h>
+//#include <net/if.h>
+#include <sys/ioctl.h>
+#define NAMELEN 255
+#define MAX_BROADCAST_SIZE 1400
+#include <unistd.h>
+
+extern int errno;
+
+/*
+ * Get a copy of the current port maps.
+ * Calls the pmap service remotely to do get the maps.
+ */
+struct pmaplist *pmap_getmaps(address)
+struct sockaddr_in *address;
+{
+ struct pmaplist *head = (struct pmaplist *) NULL;
+ int socket = -1;
+ struct timeval minutetimeout;
+ register CLIENT *client;
+
+ minutetimeout.tv_sec = 60;
+ minutetimeout.tv_usec = 0;
+ address->sin_port = htons(PMAPPORT);
+ client = clnttcp_create(address, PMAPPROG, PMAPVERS, &socket, 50, 500);
+ if (client != (CLIENT *) NULL) {
+ if (CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_pmaplist,
+ (caddr_t)&head, minutetimeout) != RPC_SUCCESS) {
+ clnt_perror(client, "pmap_getmaps rpc problem");
+ }
+ CLNT_DESTROY(client);
+ }
+ (void) close(socket);
+ address->sin_port = 0;
+ return (head);
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_getport.c b/mdk-stage1/dietlibc/librpc/pmap_getport.c
new file mode 100644
index 000000000..174dca41a
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_getport.c
@@ -0,0 +1,90 @@
+/* @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_getport.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+//#include <net/if.h>
+#include <unistd.h>
+
+static struct timeval timeout = { 5, 0 };
+static struct timeval tottimeout = { 60, 0 };
+
+/*
+ * Find the mapped port for program,version.
+ * Calls the pmap service remotely to do the lookup.
+ * Returns 0 if no map exists.
+ */
+u_short pmap_getport(address, program, version, protocol)
+struct sockaddr_in *address;
+u_long program;
+u_long version;
+u_int protocol;
+{
+ u_short port = 0;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+
+ address->sin_port = htons(PMAPPORT);
+ client = clntudp_bufcreate(address, PMAPPROG,
+ PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE,
+ RPCSMALLMSGSIZE);
+ if (client != (CLIENT *) NULL) {
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = 0; /* not needed or used */
+ if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (caddr_t)&parms,
+ (xdrproc_t)xdr_u_short, (caddr_t)&port, tottimeout) != RPC_SUCCESS) {
+ rpc_createerr.cf_stat = RPC_PMAPFAILURE;
+ clnt_geterr(client, &rpc_createerr.cf_error);
+ } else if (port == 0) {
+ rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
+ }
+ CLNT_DESTROY(client);
+ }
+ (void) close(socket);
+ address->sin_port = 0;
+ return (port);
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_prot.c b/mdk-stage1/dietlibc/librpc/pmap_prot.c
new file mode 100644
index 000000000..ec8b5af79
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_prot.c
@@ -0,0 +1,58 @@
+/* @(#)pmap_prot.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_prot.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+bool_t xdr_pmap(xdrs, regs)
+XDR *xdrs;
+struct pmap *regs;
+{
+
+ if (xdr_u_long(xdrs, &regs->pm_prog) &&
+ xdr_u_long(xdrs, &regs->pm_vers) &&
+ xdr_u_long(xdrs, &regs->pm_prot))
+ return (xdr_u_long(xdrs, &regs->pm_port));
+ return (FALSE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_prot2.c b/mdk-stage1/dietlibc/librpc/pmap_prot2.c
new file mode 100644
index 000000000..870c844ed
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_prot2.c
@@ -0,0 +1,116 @@
+/* @(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_prot2.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+/*
+ * What is going on with linked lists? (!)
+ * First recall the link list declaration from pmap_prot.h:
+ *
+ * struct pmaplist {
+ * struct pmap pml_map;
+ * struct pmaplist *pml_map;
+ * };
+ *
+ * Compare that declaration with a corresponding xdr declaration that
+ * is (a) pointer-less, and (b) recursive:
+ *
+ * typedef union switch (bool_t) {
+ *
+ * case TRUE: struct {
+ * struct pmap;
+ * pmaplist_t foo;
+ * };
+ *
+ * case FALSE: struct {};
+ * } pmaplist_t;
+ *
+ * Notice that the xdr declaration has no nxt pointer while
+ * the C declaration has no bool_t variable. The bool_t can be
+ * interpreted as ``more data follows me''; if FALSE then nothing
+ * follows this bool_t; if TRUE then the bool_t is followed by
+ * an actual struct pmap, and then (recursively) by the
+ * xdr union, pamplist_t.
+ *
+ * This could be implemented via the xdr_union primitive, though this
+ * would cause a one recursive call per element in the list. Rather than do
+ * that we can ``unwind'' the recursion
+ * into a while loop and do the union arms in-place.
+ *
+ * The head of the list is what the C programmer wishes to past around
+ * the net, yet is the data that the pointer points to which is interesting;
+ * this sounds like a job for xdr_reference!
+ */
+bool_t xdr_pmaplist(XDR* xdrs, struct pmaplist** rp)
+{
+ /*
+ * more_elements is pre-computed in case the direction is
+ * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
+ * xdr_bool when the direction is XDR_DECODE.
+ */
+ bool_t more_elements;
+ register int freeing = (xdrs->x_op == XDR_FREE);
+ register struct pmaplist **next=0;
+
+ while (TRUE) {
+ more_elements = (bool_t) (*rp != NULL);
+ if (!xdr_bool(xdrs, &more_elements))
+ return (FALSE);
+ if (!more_elements)
+ return (TRUE); /* we are done */
+ /*
+ * the unfortunate side effect of non-recursion is that in
+ * the case of freeing we must remember the next object
+ * before we free the current object ...
+ */
+ if (freeing)
+ next = &((*rp)->pml_next);
+ if (!xdr_reference(xdrs, (caddr_t *) rp,
+ (u_int) sizeof(struct pmaplist), (xdrproc_t)xdr_pmap))
+ return (FALSE);
+
+ rp = (freeing) ? next : &((*rp)->pml_next);
+ }
+}
diff --git a/mdk-stage1/dietlibc/librpc/pmap_rmt.c b/mdk-stage1/dietlibc/librpc/pmap_rmt.c
new file mode 100644
index 000000000..02efcf91c
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/pmap_rmt.c
@@ -0,0 +1,403 @@
+/* @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * pmap_rmt.c
+ * Client interface to pmap rpc service.
+ * remote call and broadcast service
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_rmt.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <errno.h>
+//#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#define MAX_BROADCAST_SIZE 1400
+#include <unistd.h>
+#include <string.h>
+
+extern int errno;
+static struct timeval timeout = { 3, 0 };
+
+
+/*
+ * pmapper remote-call-service interface.
+ * This routine is used to call the pmapper remote call service
+ * which will look up a service program in the port maps, and then
+ * remotely call that routine with the given parameters. This allows
+ * programs to do a lookup and call in one step.
+*/
+enum clnt_stat
+pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
+ port_ptr)
+struct sockaddr_in *addr;
+u_long prog, vers, proc;
+xdrproc_t xdrargs, xdrres;
+caddr_t argsp, resp;
+struct timeval tout;
+u_long *port_ptr;
+{
+ int socket = -1;
+ register CLIENT *client;
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ enum clnt_stat stat;
+
+ addr->sin_port = htons(PMAPPORT);
+ client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &socket);
+ if (client != (CLIENT *) NULL) {
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.args_ptr = argsp;
+ a.xdr_args = xdrargs;
+ r.port_ptr = port_ptr;
+ r.results_ptr = resp;
+ r.xdr_results = xdrres;
+ stat = CLNT_CALL(client, PMAPPROC_CALLIT, (xdrproc_t)xdr_rmtcall_args, (caddr_t)&a,
+ (xdrproc_t)xdr_rmtcallres, (caddr_t)&r, tout);
+ CLNT_DESTROY(client);
+ } else {
+ stat = RPC_FAILED;
+ }
+ (void) close(socket);
+ addr->sin_port = 0;
+ return (stat);
+}
+
+
+/*
+ * XDR remote call arguments
+ * written for XDR_ENCODE direction only
+ */
+bool_t xdr_rmtcall_args(XDR* xdrs, struct rmtcallargs* cap)
+{
+ u_int lenposition, argposition, position;
+
+ if (xdr_u_long(xdrs, &(cap->prog)) &&
+ xdr_u_long(xdrs, &(cap->vers)) && xdr_u_long(xdrs, &(cap->proc))) {
+ lenposition = XDR_GETPOS(xdrs);
+ if (!xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ argposition = XDR_GETPOS(xdrs);
+ if (!(*(cap->xdr_args)) (xdrs, cap->args_ptr))
+ return (FALSE);
+ position = XDR_GETPOS(xdrs);
+ cap->arglen = (u_long) position - (u_long) argposition;
+ XDR_SETPOS(xdrs, lenposition);
+ if (!xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ XDR_SETPOS(xdrs, position);
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR remote call results
+ * written for XDR_DECODE direction only
+ */
+bool_t xdr_rmtcallres(XDR* xdrs, struct rmtcallres* crp)
+{
+ caddr_t port_ptr;
+
+ port_ptr = (caddr_t) crp->port_ptr;
+ if (xdr_reference(xdrs, &port_ptr, sizeof(u_long),
+ (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
+ crp->port_ptr = (u_long *) port_ptr;
+ return ((*(crp->xdr_results)) (xdrs, crp->results_ptr));
+ }
+ return (FALSE);
+}
+
+
+/*
+ * The following is kludged-up support for simple rpc broadcasts.
+ * Someday a large, complicated system will replace these trivial
+ * routines which only support udp/ip .
+ */
+
+static int getbroadcastnets(addrs, sock, buf)
+struct in_addr *addrs;
+int sock; /* any valid socket will do */
+char *buf; /* why allocxate more when we can use existing... */
+{
+#ifdef __linux__
+ struct sockaddr_in addr;
+
+ get_myaddress(&addr);
+#if 1
+ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
+#else
+ addrs[0] = inet_makeaddr(inet_netof(addr.sin_addr), INADDR_ANY);
+#endif
+ return 1;
+#else
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr;
+ struct sockaddr_in *sin;
+ int n, i;
+
+ ifc.ifc_len = UDPMSGSIZE;
+ ifc.ifc_buf = buf;
+ if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) {
+ perror("broadcast: ioctl (get interface configuration)");
+ return (0);
+ }
+ ifr = ifc.ifc_req;
+ for (i = 0, n = ifc.ifc_len / sizeof(struct ifreq); n > 0; n--, ifr++) {
+ ifreq = *ifr;
+ if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
+ perror("broadcast: ioctl (get interface flags)");
+ continue;
+ }
+ if ((ifreq.ifr_flags & IFF_BROADCAST) &&
+ (ifreq.ifr_flags & IFF_UP) &&
+ ifr->ifr_addr.sa_family == AF_INET) {
+ sin = (struct sockaddr_in *) &ifr->ifr_addr;
+#ifdef SIOCGIFBRDADDR /* 4.3BSD */
+ if (ioctl(sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0) {
+#if 1
+ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
+#else
+ addrs[i++] = inet_makeaddr(inet_netof
+ (sin->sin_addr.s_addr),
+ INADDR_ANY);
+#endif
+ } else {
+ addrs[i++] = ((struct sockaddr_in *)
+ &ifreq.ifr_addr)->sin_addr;
+ }
+#else /* 4.2 BSD */
+#if 1
+ printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
+#else
+ addrs[i++] = inet_makeaddr(inet_netof
+ (sin->sin_addr.s_addr), INADDR_ANY);
+#endif
+#endif
+ }
+ }
+ return (i);
+#endif
+}
+
+enum clnt_stat
+clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
+ eachresult)
+u_long prog; /* program number */
+u_long vers; /* version number */
+u_long proc; /* procedure number */
+xdrproc_t xargs; /* xdr routine for args */
+caddr_t argsp; /* pointer to args */
+xdrproc_t xresults; /* xdr routine for results */
+caddr_t resultsp; /* pointer to results */
+resultproc_t eachresult; /* call with each result obtained */
+{
+ enum clnt_stat stat;
+ AUTH *unix_auth = authunix_create_default();
+ XDR xdr_stream;
+ register XDR *xdrs = &xdr_stream;
+ int outlen, inlen, fromlen, nets;
+ register int sock;
+ int on = 1;
+
+#ifdef FD_SETSIZE
+ fd_set mask;
+ fd_set readfds;
+#else
+ int readfds;
+ register int mask;
+#endif /* def FD_SETSIZE */
+ register int i;
+ bool_t done = FALSE;
+ register u_long xid;
+ u_long port;
+ struct in_addr addrs[20];
+ struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ struct rpc_msg msg;
+ struct timeval t;
+ char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
+
+ /*
+ * initialization: create a socket, a broadcast address, and
+ * preserialize the arguments into a send buffer.
+ */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("Cannot create socket for broadcast rpc");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#ifdef SO_BROADCAST
+ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
+ perror("Cannot set socket option SO_BROADCAST");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#endif /* def SO_BROADCAST */
+#ifdef FD_SETSIZE
+ FD_ZERO(&mask);
+ FD_SET(sock, &mask);
+#else
+ mask = (1 << sock);
+#endif /* def FD_SETSIZE */
+ nets = getbroadcastnets(addrs, sock, inbuf);
+ bzero((char *) &baddr, sizeof(baddr));
+ baddr.sin_family = AF_INET;
+ baddr.sin_port = htons(PMAPPORT);
+ baddr.sin_addr.s_addr = htonl(INADDR_ANY);
+/* baddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY); */
+ (void) gettimeofday(&t, (struct timezone *) 0);
+ msg.rm_xid = xid = getpid() ^ t.tv_sec ^ t.tv_usec;
+ t.tv_usec = 0;
+ msg.rm_direction = CALL;
+ msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ msg.rm_call.cb_prog = PMAPPROG;
+ msg.rm_call.cb_vers = PMAPVERS;
+ msg.rm_call.cb_proc = PMAPPROC_CALLIT;
+ msg.rm_call.cb_cred = unix_auth->ah_cred;
+ msg.rm_call.cb_verf = unix_auth->ah_verf;
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.xdr_args = xargs;
+ a.args_ptr = argsp;
+ r.port_ptr = &port;
+ r.xdr_results = xresults;
+ r.results_ptr = resultsp;
+ xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
+ if ((!xdr_callmsg(xdrs, &msg)) || (!xdr_rmtcall_args(xdrs, &a))) {
+ stat = RPC_CANTENCODEARGS;
+ goto done_broad;
+ }
+ outlen = (int) xdr_getpos(xdrs);
+ xdr_destroy(xdrs);
+ /*
+ * Basic loop: broadcast a packet and wait a while for response(s).
+ * The response timeout grows larger per iteration.
+ */
+ for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) {
+ for (i = 0; i < nets; i++) {
+ baddr.sin_addr = addrs[i];
+ if (sendto(sock, outbuf, outlen, 0,
+ (struct sockaddr *) &baddr,
+ sizeof(struct sockaddr)) != outlen) {
+ perror("Cannot send broadcast packet");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+ }
+ if (eachresult == NULL) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ }
+ recv_again:
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = (caddr_t) & r;
+ msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_rmtcallres;
+ readfds = mask;
+ switch (select(_rpc_dtablesize(), &readfds, 0, 0, &t)) {
+
+ case 0: /* timed out */
+ stat = RPC_TIMEDOUT;
+ continue;
+
+ case -1: /* some kind of error */
+ if (errno == EINTR)
+ goto recv_again;
+ perror("Broadcast select problem");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+
+ } /* end of select results switch */
+ try_again:
+ fromlen = sizeof(struct sockaddr);
+
+ inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
+ (struct sockaddr *) &raddr, &fromlen);
+ if (inlen < 0) {
+ if (errno == EINTR)
+ goto try_again;
+ perror("Cannot receive reply to broadcast");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+ }
+ if (inlen < sizeof(u_long))
+ goto recv_again;
+ /*
+ * see if reply transaction id matches sent id.
+ * If so, decode the results.
+ */
+ xdrmem_create(xdrs, inbuf, (u_int) inlen, XDR_DECODE);
+ if (xdr_replymsg(xdrs, &msg)) {
+ if ((msg.rm_xid == xid) &&
+ (msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
+ (msg.acpted_rply.ar_stat == SUCCESS)) {
+ raddr.sin_port = htons((u_short) port);
+ done = (*eachresult) (resultsp, &raddr);
+ }
+ /* otherwise, we just ignore the errors ... */
+ } else {
+#ifdef notdef
+ /* some kind of deserialization problem ... */
+ if (msg.rm_xid == xid)
+ fprintf(stderr, "Broadcast deserialization problem");
+ /* otherwise, just random garbage */
+#endif
+ }
+ xdrs->x_op = XDR_FREE;
+ msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
+ (void) xdr_replymsg(xdrs, &msg);
+ (void) (*xresults) (xdrs, resultsp);
+ xdr_destroy(xdrs);
+ if (done) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ } else {
+ goto recv_again;
+ }
+ }
+ done_broad:
+ (void) close(sock);
+ AUTH_DESTROY(unix_auth);
+ return (stat);
+}
diff --git a/mdk-stage1/dietlibc/librpc/rpc_callmsg.c b/mdk-stage1/dietlibc/librpc/rpc_callmsg.c
new file mode 100644
index 000000000..4b3a9880e
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/rpc_callmsg.c
@@ -0,0 +1,189 @@
+/* @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * rpc_callmsg.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+
+#include <sys/param.h>
+
+#include <rpc/rpc.h>
+#include <string.h>
+
+/*
+ * XDR a call message
+ */
+bool_t xdr_callmsg(xdrs, cmsg)
+register XDR *xdrs;
+register struct rpc_msg *cmsg;
+{
+ register int32_t *buf;
+ register struct opaque_auth *oa;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_cred.oa_length)
+ + 2 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_verf.oa_length));
+ if (buf != NULL) {
+ IXDR_PUT_LONG(buf, cmsg->rm_xid);
+ IXDR_PUT_ENUM(buf, cmsg->rm_direction);
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
+ oa = &cmsg->rm_call.cb_cred;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ bcopy(oa->oa_base, (caddr_t) buf, oa->oa_length);
+ buf += RNDUP(oa->oa_length) / sizeof(long);
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ bcopy(oa->oa_base, (caddr_t) buf, oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) / sizeof (long);
+ */
+ }
+ return (TRUE);
+ }
+ }
+ if (xdrs->x_op == XDR_DECODE) {
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
+ if (buf != NULL) {
+ cmsg->rm_xid = IXDR_GET_LONG(buf);
+ cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
+
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
+ oa = &cmsg->rm_call.cb_cred;
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ bcopy((caddr_t) buf, oa->oa_base, oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) /
+ sizeof (long);
+ */
+ }
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
+ xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ }
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ bcopy((caddr_t) buf, oa->oa_base, oa->oa_length);
+ /* no real need...
+ buf += RNDUP(oa->oa_length) /
+ sizeof (long);
+ */
+ }
+ }
+ return (TRUE);
+ }
+ }
+ if (xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *) & (cmsg->rm_direction)) &&
+ (cmsg->rm_direction == CALL) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) &&
+ xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)))
+ return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
+ return (FALSE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/rpc_commondata.c b/mdk-stage1/dietlibc/librpc/rpc_commondata.c
new file mode 100644
index 000000000..39648d284
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/rpc_commondata.c
@@ -0,0 +1,42 @@
+/* @(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#include <rpc/rpc.h>
+/*
+ * This file should only contain common data (global data) that is exported
+ * by public interfaces
+ */
+struct opaque_auth _null_auth;
+
+#ifdef FD_SETSIZE
+fd_set svc_fdset;
+#else
+int svc_fds;
+#endif /* def FD_SETSIZE */
+struct rpc_createerr rpc_createerr;
diff --git a/mdk-stage1/dietlibc/librpc/rpc_dtablesize.c b/mdk-stage1/dietlibc/librpc/rpc_dtablesize.c
new file mode 100644
index 000000000..b08ebaccd
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/rpc_dtablesize.c
@@ -0,0 +1,50 @@
+/* @(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";
+#endif
+
+#include <unistd.h>
+
+/*
+ * Cache the result of getdtablesize(), so we don't have to do an
+ * expensive system call every time.
+ */
+int _rpc_dtablesize()
+{
+ static int size;
+
+ if (size == 0) {
+ size = getdtablesize();
+ }
+ return (size);
+}
diff --git a/mdk-stage1/dietlibc/librpc/rpc_prot.c b/mdk-stage1/dietlibc/librpc/rpc_prot.c
new file mode 100644
index 000000000..19a4db27f
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/rpc_prot.c
@@ -0,0 +1,281 @@
+/* @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * rpc_prot.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements the rpc message definition,
+ * its serializer and some common rpc utility routines.
+ * The routines are meant for various implementations of rpc -
+ * they are NOT for the rpc client or rpc service implementations!
+ * Because authentication stuff is easy and is part of rpc, the opaque
+ * routines are also in this program.
+ */
+
+#include <sys/param.h>
+
+#include <rpc/rpc.h>
+
+/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
+
+struct opaque_auth _null_auth;
+
+/*
+ * XDR an opaque authentication struct
+ * (see auth.h)
+ */
+bool_t xdr_opaque_auth(xdrs, ap)
+register XDR *xdrs;
+register struct opaque_auth *ap;
+{
+
+ if (xdr_enum(xdrs, &(ap->oa_flavor)))
+ return (xdr_bytes(xdrs, &ap->oa_base,
+ &ap->oa_length, MAX_AUTH_BYTES));
+ return (FALSE);
+}
+
+/*
+ * XDR a DES block
+ */
+bool_t xdr_des_block(xdrs, blkp)
+register XDR *xdrs;
+register des_block *blkp;
+{
+ return (xdr_opaque(xdrs, (caddr_t) blkp, sizeof(des_block)));
+}
+
+/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
+
+/*
+ * XDR the MSG_ACCEPTED part of a reply message union
+ */
+bool_t xdr_accepted_reply(xdrs, ar)
+register XDR *xdrs;
+register struct accepted_reply *ar;
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (!xdr_opaque_auth(xdrs, &(ar->ar_verf)))
+ return (FALSE);
+ if (!xdr_enum(xdrs, (enum_t *) & (ar->ar_stat)))
+ return (FALSE);
+ switch (ar->ar_stat) {
+
+ case SUCCESS:
+ return ((*(ar->ar_results.proc)) (xdrs, ar->ar_results.where));
+
+ case PROG_MISMATCH:
+ if (!xdr_u_long(xdrs, &(ar->ar_vers.low)))
+ return (FALSE);
+ return (xdr_u_long(xdrs, &(ar->ar_vers.high)));
+ }
+ return (TRUE); /* TRUE => open ended set of problems */
+}
+
+/*
+ * XDR the MSG_DENIED part of a reply message union
+ */
+bool_t xdr_rejected_reply(xdrs, rr)
+register XDR *xdrs;
+register struct rejected_reply *rr;
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (!xdr_enum(xdrs, (enum_t *) & (rr->rj_stat)))
+ return (FALSE);
+ switch (rr->rj_stat) {
+
+ case RPC_MISMATCH:
+ if (!xdr_u_long(xdrs, &(rr->rj_vers.low)))
+ return (FALSE);
+ return (xdr_u_long(xdrs, &(rr->rj_vers.high)));
+
+ case AUTH_ERROR:
+ return (xdr_enum(xdrs, (enum_t *) & (rr->rj_why)));
+ }
+ return (FALSE);
+}
+
+static struct xdr_discrim reply_dscrm[3] = {
+ {(int) MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply},
+ {(int) MSG_DENIED, (xdrproc_t)xdr_rejected_reply},
+ {__dontcare__, NULL_xdrproc_t}
+};
+
+/*
+ * XDR a reply message
+ */
+bool_t xdr_replymsg(xdrs, rmsg)
+register XDR *xdrs;
+register struct rpc_msg *rmsg;
+{
+ if (xdr_u_long(xdrs, &(rmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *) & (rmsg->rm_direction)) &&
+ (rmsg->rm_direction == REPLY))
+ return (xdr_union(xdrs, (enum_t *) & (rmsg->rm_reply.rp_stat),
+ (caddr_t) & (rmsg->rm_reply.ru), reply_dscrm,
+ NULL_xdrproc_t));
+ return (FALSE);
+}
+
+
+/*
+ * Serializes the "static part" of a call message header.
+ * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
+ * The rm_xid is not really static, but the user can easily munge on the fly.
+ */
+bool_t xdr_callhdr(xdrs, cmsg)
+register XDR *xdrs;
+register struct rpc_msg *cmsg;
+{
+
+ cmsg->rm_direction = CALL;
+ cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ if (
+ (xdrs->x_op == XDR_ENCODE) &&
+ xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *) & (cmsg->rm_direction)) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)))
+ return (xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)));
+ return (FALSE);
+}
+
+/* ************************** Client utility routine ************* */
+
+static void accepted(acpt_stat, error)
+register enum accept_stat acpt_stat;
+register struct rpc_err *error;
+{
+
+ switch (acpt_stat) {
+
+ case PROG_UNAVAIL:
+ error->re_status = RPC_PROGUNAVAIL;
+ return;
+
+ case PROG_MISMATCH:
+ error->re_status = RPC_PROGVERSMISMATCH;
+ return;
+
+ case PROC_UNAVAIL:
+ error->re_status = RPC_PROCUNAVAIL;
+ return;
+
+ case GARBAGE_ARGS:
+ error->re_status = RPC_CANTDECODEARGS;
+ return;
+
+ case SYSTEM_ERR:
+ error->re_status = RPC_SYSTEMERROR;
+ return;
+
+ case SUCCESS:
+ error->re_status = RPC_SUCCESS;
+ return;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long) MSG_ACCEPTED;
+ error->re_lb.s2 = (long) acpt_stat;
+}
+
+static void rejected(rjct_stat, error)
+register enum reject_stat rjct_stat;
+register struct rpc_err *error;
+{
+
+ switch (rjct_stat) {
+
+ case RPC_VERSMISMATCH:
+ error->re_status = RPC_VERSMISMATCH;
+ return;
+
+ case AUTH_ERROR:
+ error->re_status = RPC_AUTHERROR;
+ return;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long) MSG_DENIED;
+ error->re_lb.s2 = (long) rjct_stat;
+}
+
+/*
+ * given a reply message, fills in the error
+ */
+void _seterr_reply(msg, error)
+register struct rpc_msg *msg;
+register struct rpc_err *error;
+{
+
+ /* optimized for normal, SUCCESSful case */
+ switch (msg->rm_reply.rp_stat) {
+
+ case MSG_ACCEPTED:
+ if (msg->acpted_rply.ar_stat == SUCCESS) {
+ error->re_status = RPC_SUCCESS;
+ return;
+ };
+ accepted(msg->acpted_rply.ar_stat, error);
+ break;
+
+ case MSG_DENIED:
+ rejected(msg->rjcted_rply.rj_stat, error);
+ break;
+
+ default:
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long) (msg->rm_reply.rp_stat);
+ break;
+ }
+ switch (error->re_status) {
+
+ case RPC_VERSMISMATCH:
+ error->re_vers.low = msg->rjcted_rply.rj_vers.low;
+ error->re_vers.high = msg->rjcted_rply.rj_vers.high;
+ break;
+
+ case RPC_AUTHERROR:
+ error->re_why = msg->rjcted_rply.rj_why;
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ error->re_vers.low = msg->acpted_rply.ar_vers.low;
+ error->re_vers.high = msg->acpted_rply.ar_vers.high;
+ break;
+ }
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc.c b/mdk-stage1/dietlibc/librpc/svc.c
new file mode 100644
index 000000000..4fcdb5216
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc.c
@@ -0,0 +1,479 @@
+/* @(#)svc.c 2.4 88/08/11 4.0 RPCSRC; from 1.44 88/02/08 SMI */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc.c 1.41 87/10/13 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc.c, Server-side remote procedure call interface.
+ *
+ * There are two sets of procedures here. The xprt routines are
+ * for handling transport handles. The svc routines handle the
+ * list of service routines.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <errno.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#ifdef __linux__
+#include <sys/types.h>
+#endif
+
+extern int errno;
+
+#ifdef FD_SETSIZE
+static SVCXPRT **xports;
+#else
+#define NOFILE 32
+
+static SVCXPRT *xports[NOFILE];
+#endif /* def FD_SETSIZE */
+
+#define NULL_SVC ((struct svc_callout *)0)
+#define RQCRED_SIZE 400 /* this size is excessive */
+
+/*
+ * The services list
+ * Each entry represents a set of procedures (an rpc program).
+ * The dispatch routine takes request structs and runs the
+ * apropriate procedure.
+ */
+static struct svc_callout {
+ struct svc_callout *sc_next;
+ u_long sc_prog;
+ u_long sc_vers;
+ void (*sc_dispatch) ();
+} *svc_head;
+
+static struct svc_callout *svc_find();
+
+/* *************** SVCXPRT related stuff **************** */
+
+/*
+ * Activate a transport handle.
+ */
+void xprt_register(xprt)
+SVCXPRT *xprt;
+{
+ register int sock = xprt->xp_sock;
+
+#ifdef FD_SETSIZE
+ if (xports == NULL) {
+ xports = (SVCXPRT **)
+ mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
+ }
+ if (sock < _rpc_dtablesize()) {
+ xports[sock] = xprt;
+ FD_SET(sock, &svc_fdset);
+ }
+#else
+ if (sock < NOFILE) {
+ xports[sock] = xprt;
+ svc_fds |= (1 << sock);
+ }
+#endif /* def FD_SETSIZE */
+
+}
+
+/*
+ * De-activate a transport handle.
+ */
+void xprt_unregister(xprt)
+SVCXPRT *xprt;
+{
+ register int sock = xprt->xp_sock;
+
+#ifdef FD_SETSIZE
+ if ((sock < _rpc_dtablesize()) && (xports[sock] == xprt)) {
+ xports[sock] = (SVCXPRT *) 0;
+ FD_CLR(sock, &svc_fdset);
+ }
+#else
+ if ((sock < NOFILE) && (xports[sock] == xprt)) {
+ xports[sock] = (SVCXPRT *) 0;
+ svc_fds &= ~(1 << sock);
+ }
+#endif /* def FD_SETSIZE */
+}
+
+
+/* ********************** CALLOUT list related stuff ************* */
+
+/*
+ * Add a service program to the callout list.
+ * The dispatch routine will be called when a rpc request for this
+ * program number comes in.
+ */
+bool_t svc_register(xprt, prog, vers, dispatch, protocol)
+SVCXPRT *xprt;
+u_long prog;
+u_long vers;
+void (*dispatch) ();
+rpcprot_t protocol;
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) != NULL_SVC) {
+ if (s->sc_dispatch == dispatch)
+ goto pmap_it; /* he is registering another xptr */
+ return (FALSE);
+ }
+ s = (struct svc_callout *) mem_alloc(sizeof(struct svc_callout));
+
+ if (s == (struct svc_callout *) 0) {
+ return (FALSE);
+ }
+ s->sc_prog = prog;
+ s->sc_vers = vers;
+ s->sc_dispatch = dispatch;
+ s->sc_next = svc_head;
+ svc_head = s;
+ pmap_it:
+ /* now register the information with the local binder service */
+ if (protocol) {
+ return (pmap_set(prog, vers, protocol, xprt->xp_port));
+ }
+ return (TRUE);
+}
+
+/*
+ * Remove a service program from the callout list.
+ */
+void svc_unregister(prog, vers)
+u_long prog;
+u_long vers;
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) == NULL_SVC)
+ return;
+ if (prev == NULL_SVC) {
+ svc_head = s->sc_next;
+ } else {
+ prev->sc_next = s->sc_next;
+ }
+ s->sc_next = NULL_SVC;
+ mem_free((char *) s, (u_int) sizeof(struct svc_callout));
+
+ /* now unregister the information with the local binder service */
+ (void) pmap_unset(prog, vers);
+}
+
+/*
+ * Search the callout list for a program number, return the callout
+ * struct.
+ */
+static struct svc_callout *svc_find(prog, vers, prev)
+u_long prog;
+u_long vers;
+struct svc_callout **prev;
+{
+ register struct svc_callout *s, *p;
+
+ p = NULL_SVC;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if ((s->sc_prog == prog) && (s->sc_vers == vers))
+ goto done;
+ p = s;
+ }
+ done:
+ *prev = p;
+ return (s);
+}
+
+/* ******************* REPLY GENERATION ROUTINES ************ */
+
+/*
+ * Send a reply to an rpc request
+ */
+bool_t svc_sendreply(xprt, xdr_results, xdr_location)
+register SVCXPRT *xprt;
+xdrproc_t xdr_results;
+caddr_t xdr_location;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SUCCESS;
+ rply.acpted_rply.ar_results.where = xdr_location;
+ rply.acpted_rply.ar_results.proc = xdr_results;
+ return (SVC_REPLY(xprt, &rply));
+}
+
+/*
+ * No procedure error reply
+ */
+void svcerr_noproc(xprt)
+register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROC_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Can't decode args error reply
+ */
+void svcerr_decode(xprt)
+register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = GARBAGE_ARGS;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Some system error
+ */
+void svcerr_systemerr(xprt)
+register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SYSTEM_ERR;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Authentication error reply
+ */
+void svcerr_auth(xprt, why)
+SVCXPRT *xprt;
+enum auth_stat why;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_DENIED;
+ rply.rjcted_rply.rj_stat = AUTH_ERROR;
+ rply.rjcted_rply.rj_why = why;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Auth too weak error reply
+ */
+void svcerr_weakauth(xprt)
+SVCXPRT *xprt;
+{
+
+ svcerr_auth(xprt, AUTH_TOOWEAK);
+}
+
+/*
+ * Program unavailable error reply
+ */
+void svcerr_noprog(xprt)
+register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Program version mismatch error reply
+ */
+void svcerr_progvers(xprt, low_vers, high_vers)
+register SVCXPRT *xprt;
+u_long low_vers;
+u_long high_vers;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_MISMATCH;
+ rply.acpted_rply.ar_vers.low = low_vers;
+ rply.acpted_rply.ar_vers.high = high_vers;
+ SVC_REPLY(xprt, &rply);
+}
+
+/* ******************* SERVER INPUT STUFF ******************* */
+
+/*
+ * Get server side input from some transport.
+ *
+ * Statement of authentication parameters management:
+ * This function owns and manages all authentication parameters, specifically
+ * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
+ * the "cooked" credentials (rqst->rq_clntcred).
+ * However, this function does not know the structure of the cooked
+ * credentials, so it make the following assumptions:
+ * a) the structure is contiguous (no pointers), and
+ * b) the cred structure size does not exceed RQCRED_SIZE bytes.
+ * In all events, all three parameters are freed upon exit from this routine.
+ * The storage is trivially management on the call stack in user land, but
+ * is mallocated in kernel land.
+ */
+
+void svc_getreq(rdfds)
+int rdfds;
+{
+#ifdef FD_SETSIZE
+ fd_set readfds;
+
+ FD_ZERO(&readfds);
+/*#ifdef __linux__*/
+#if 0
+ readfds = rdfds;
+#else
+ readfds.fds_bits[0] = rdfds;
+#endif
+ svc_getreqset(&readfds);
+#else
+ int readfds = rdfds & svc_fds;
+
+ svc_getreqset(&readfds);
+#endif /* def FD_SETSIZE */
+}
+
+void svc_getreqset(readfds)
+#ifdef FD_SETSIZE
+fd_set *readfds;
+{
+#else
+int *readfds;
+{
+ int readfds_local = *readfds;
+#endif /* def FD_SETSIZE */
+ enum xprt_stat stat;
+ struct rpc_msg msg;
+ int prog_found;
+ u_long low_vers;
+ u_long high_vers;
+ struct svc_req r;
+ register SVCXPRT *xprt;
+ register u_long mask;
+ register int bit;
+ register u_long *maskp;
+ register int setsize;
+ register int sock;
+ char cred_area[2 * MAX_AUTH_BYTES + RQCRED_SIZE];
+
+ msg.rm_call.cb_cred.oa_base = cred_area;
+ msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
+ r.rq_clntcred = &(cred_area[2 * MAX_AUTH_BYTES]);
+
+
+#ifdef FD_SETSIZE
+ setsize = _rpc_dtablesize();
+#ifdef __linux__
+/*#define NFDBITS 32*/
+ maskp = (u_long *) readfds;
+#else
+ maskp = (u_long *) readfds->fds_bits;
+#endif
+ for (sock = 0; sock < setsize; sock += NFDBITS) {
+ for (mask = *maskp++; (bit = ffs(mask)); mask ^= (1 << (bit - 1))) {
+ /* sock has input waiting */
+ xprt = xports[sock + bit - 1];
+#else
+ for (sock = 0; readfds_local != 0; sock++, readfds_local >>= 1) {
+ if ((readfds_local & 1) != 0) {
+ /* sock has input waiting */
+ xprt = xports[sock];
+#endif /* def FD_SETSIZE */
+ /* now receive msgs from xprtprt (support batch calls) */
+ do {
+ if (SVC_RECV(xprt, &msg)) {
+
+ /* now find the exported program and call it */
+ register struct svc_callout *s;
+ enum auth_stat why;
+
+ r.rq_xprt = xprt;
+ r.rq_prog = msg.rm_call.cb_prog;
+ r.rq_vers = msg.rm_call.cb_vers;
+ r.rq_proc = msg.rm_call.cb_proc;
+ r.rq_cred = msg.rm_call.cb_cred;
+ /* first authenticate the message */
+ if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
+ svcerr_auth(xprt, why);
+ goto call_done;
+ }
+ /* now match message with a registered service */
+ prog_found = FALSE;
+ low_vers = 0 - 1;
+ high_vers = 0;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if (s->sc_prog == r.rq_prog) {
+ if (s->sc_vers == r.rq_vers) {
+ (*s->sc_dispatch) (&r, xprt);
+ goto call_done;
+ } /* found correct version */
+ prog_found = TRUE;
+ if (s->sc_vers < low_vers)
+ low_vers = s->sc_vers;
+ if (s->sc_vers > high_vers)
+ high_vers = s->sc_vers;
+ } /* found correct program */
+ }
+ /*
+ * if we got here, the program or version
+ * is not served ...
+ */
+ if (prog_found)
+ svcerr_progvers(xprt, low_vers, high_vers);
+ else
+ svcerr_noprog(xprt);
+ /* Fall through to ... */
+ }
+ call_done:
+ if ((stat = SVC_STAT(xprt)) == XPRT_DIED) {
+ SVC_DESTROY(xprt);
+ break;
+ }
+ } while (stat == XPRT_MOREREQS);
+ }
+ }
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_auth.c b/mdk-stage1/dietlibc/librpc/svc_auth.c
new file mode 100644
index 000000000..336586d95
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_auth.c
@@ -0,0 +1,115 @@
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)svc_auth.c 2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
+#endif
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * svc_auth_nodes.c, Server-side rpc authenticator interface,
+ * *WITHOUT* DES authentication.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+
+/*
+ * svcauthsw is the bdevsw of server side authentication.
+ *
+ * Server side authenticators are called from authenticate by
+ * using the client auth struct flavor field to index into svcauthsw.
+ * The server auth flavors must implement a routine that looks
+ * like:
+ *
+ * enum auth_stat
+ * flavorx_auth(rqst, msg)
+ * register struct svc_req *rqst;
+ * register struct rpc_msg *msg;
+ *
+ */
+
+enum auth_stat _svcauth_null(); /* no authentication */
+enum auth_stat _svcauth_unix(); /* unix style (uid, gids) */
+enum auth_stat _svcauth_short(); /* short hand unix style */
+
+static struct {
+ enum auth_stat (*authenticator) ();
+} svcauthsw[] = {
+ { _svcauth_null }, /* AUTH_NULL */
+ { _svcauth_unix }, /* AUTH_UNIX */
+ { _svcauth_short }, /* AUTH_SHORT */
+};
+
+#define AUTH_MAX 2 /* HIGHEST AUTH NUMBER */
+
+
+/*
+ * The call rpc message, msg has been obtained from the wire. The msg contains
+ * the raw form of credentials and verifiers. authenticate returns AUTH_OK
+ * if the msg is successfully authenticated. If AUTH_OK then the routine also
+ * does the following things:
+ * set rqst->rq_xprt->verf to the appropriate response verifier;
+ * sets rqst->rq_client_cred to the "cooked" form of the credentials.
+ *
+ * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
+ * its length is set appropriately.
+ *
+ * The caller still owns and is responsible for msg->u.cmb.cred and
+ * msg->u.cmb.verf. The authentication system retains ownership of
+ * rqst->rq_client_cred, the cooked credentials.
+ *
+ * There is an assumption that any flavour less than AUTH_NULL is
+ * invalid.
+ */
+enum auth_stat _authenticate(rqst, msg)
+register struct svc_req *rqst;
+struct rpc_msg *msg;
+{
+ register int cred_flavor;
+
+ rqst->rq_cred = msg->rm_call.cb_cred;
+ rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ cred_flavor = rqst->rq_cred.oa_flavor;
+ if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
+ return ((*(svcauthsw[cred_flavor].authenticator)) (rqst, msg));
+ }
+
+ return (AUTH_REJECTEDCRED);
+}
+
+enum auth_stat _svcauth_null( /*rqst, msg */ )
+ /*struct svc_req *rqst;
+ struct rpc_msg *msg; */
+{
+
+ return (AUTH_OK);
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_auth_unix.c b/mdk-stage1/dietlibc/librpc/svc_auth_unix.c
new file mode 100644
index 000000000..7e0305f0a
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_auth_unix.c
@@ -0,0 +1,136 @@
+/* @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_auth_unix.c
+ * Handles UNIX flavor authentication parameters on the service side of rpc.
+ * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
+ * _svcauth_unix does full blown unix style uid,gid+gids auth,
+ * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
+ * Note: the shorthand has been gutted for efficiency.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <string.h>
+
+/*
+ * Unix longhand authenticator
+ */
+enum auth_stat _svcauth_unix(rqst, msg)
+register struct svc_req *rqst;
+register struct rpc_msg *msg;
+{
+ register enum auth_stat stat;
+ XDR xdrs;
+ register struct authunix_parms *aup;
+ register int32_t *buf;
+ struct area {
+ struct authunix_parms area_aup;
+ char area_machname[MAX_MACHINE_NAME + 1];
+ gid_t area_gids[NGRPS];
+ } *area;
+ u_int auth_len;
+ int str_len, gid_len;
+ register int i;
+
+ area = (struct area *) rqst->rq_clntcred;
+ aup = &area->area_aup;
+ aup->aup_machname = area->area_machname;
+ aup->aup_gids = area->area_gids;
+ auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
+ xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,
+ XDR_DECODE);
+ buf = XDR_INLINE(&xdrs, auth_len);
+ if (buf != NULL) {
+ aup->aup_time = IXDR_GET_LONG(buf);
+ str_len = IXDR_GET_U_LONG(buf);
+ if (str_len > MAX_MACHINE_NAME) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ bcopy((caddr_t) buf, aup->aup_machname, (u_int) str_len);
+ aup->aup_machname[str_len] = 0;
+ str_len = RNDUP(str_len);
+ buf += str_len / sizeof(long);
+
+ aup->aup_uid = IXDR_GET_LONG(buf);
+ aup->aup_gid = IXDR_GET_LONG(buf);
+ gid_len = IXDR_GET_U_LONG(buf);
+ if (gid_len > NGRPS) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ aup->aup_len = gid_len;
+ for (i = 0; i < gid_len; i++) {
+ aup->aup_gids[i] = IXDR_GET_LONG(buf);
+ }
+ /*
+ * five is the smallest unix credentials structure -
+ * timestamp, hostname len (0), uid, gid, and gids len (0).
+ */
+ if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
+ (void) printf("bad auth_len gid %d str %d auth %d\n",
+ gid_len, str_len, auth_len);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ } else if (!xdr_authunix_parms(&xdrs, aup)) {
+ xdrs.x_op = XDR_FREE;
+ (void) xdr_authunix_parms(&xdrs, aup);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ stat = AUTH_OK;
+ done:
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+
+/*
+ * Shorthand unix authenticator
+ * Looks up longhand in a cache.
+ */
+ /*ARGSUSED*/ enum auth_stat _svcauth_short(rqst, msg)
+struct svc_req *rqst;
+struct rpc_msg *msg;
+{
+ return (AUTH_REJECTEDCRED);
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_raw.c b/mdk-stage1/dietlibc/librpc/svc_raw.c
new file mode 100644
index 000000000..c13ea5e06
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_raw.c
@@ -0,0 +1,159 @@
+/* @(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_raw.c, This a toy for simple testing and timing.
+ * Interface to create an rpc client and server in the same UNIX process.
+ * This lets us similate rpc and get rpc (round trip) overhead, without
+ * any interference from the kernal.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+
+
+/*
+ * This is the "network" that we will be moving data over
+ */
+static struct svcraw_private {
+ char _raw_buf[UDPMSGSIZE];
+ SVCXPRT server;
+ XDR xdr_stream;
+ char verf_body[MAX_AUTH_BYTES];
+} *svcraw_private;
+
+static bool_t svcraw_recv();
+static enum xprt_stat svcraw_stat();
+static bool_t svcraw_getargs();
+static bool_t svcraw_reply();
+static bool_t svcraw_freeargs();
+static void svcraw_destroy();
+
+static struct xp_ops server_ops = {
+ svcraw_recv,
+ svcraw_stat,
+ svcraw_getargs,
+ svcraw_reply,
+ svcraw_freeargs,
+ svcraw_destroy
+};
+
+SVCXPRT *svcraw_create()
+{
+ register struct svcraw_private *srp = svcraw_private;
+
+ if (srp == 0) {
+ srp = (struct svcraw_private *) calloc(1, sizeof(*srp));
+ if (srp == 0)
+ return (0);
+ }
+ srp->server.xp_sock = 0;
+ srp->server.xp_port = 0;
+ srp->server.xp_ops = &server_ops;
+ srp->server.xp_verf.oa_base = srp->verf_body;
+ xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+ return (&srp->server);
+}
+
+static enum xprt_stat svcraw_stat()
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t svcraw_recv(xprt, msg)
+SVCXPRT *xprt;
+struct rpc_msg *msg;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (0);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (!xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t svcraw_reply(xprt, msg)
+SVCXPRT *xprt;
+struct rpc_msg *msg;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ if (!xdr_replymsg(xdrs, msg))
+ return (FALSE);
+ (void) XDR_GETPOS(xdrs); /* called just for overhead */
+ return (TRUE);
+}
+
+static bool_t svcraw_getargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+ register struct svcraw_private *srp = svcraw_private;
+
+ if (srp == 0)
+ return (FALSE);
+ return ((*xdr_args) (&srp->xdr_stream, args_ptr));
+}
+
+static bool_t svcraw_freeargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args) (xdrs, args_ptr));
+}
+
+static void svcraw_destroy()
+{
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_run.c b/mdk-stage1/dietlibc/librpc/svc_run.c
new file mode 100644
index 000000000..c7150e357
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_run.c
@@ -0,0 +1,71 @@
+/* @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * This is the rpc server side idle loop
+ * Wait for input, call server program.
+ */
+#include <rpc/rpc.h>
+#include <errno.h>
+#include <unistd.h>
+
+void svc_run()
+{
+#ifdef FD_SETSIZE
+ fd_set readfds;
+#else
+ int readfds;
+#endif /* def FD_SETSIZE */
+ extern int errno;
+
+ for (;;) {
+#ifdef FD_SETSIZE
+ readfds = svc_fdset;
+#else
+ readfds = svc_fds;
+#endif /* def FD_SETSIZE */
+ switch (select(_rpc_dtablesize(), &readfds, 0, 0, 0)) {
+ case -1:
+ if (errno == EINTR) {
+ continue;
+ }
+ perror("svc_run: - select failed");
+ return;
+ case 0:
+ continue;
+ default:
+ svc_getreqset(&readfds);
+ }
+ }
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_simple.c b/mdk-stage1/dietlibc/librpc/svc_simple.c
new file mode 100644
index 000000000..0bb9a19eb
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_simple.c
@@ -0,0 +1,144 @@
+/* @(#)svc_simple.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <rpc/pmap_clnt.h>
+#include <string.h>
+
+static struct proglst {
+ char *(*p_progname) ();
+ int p_prognum;
+ int p_procnum;
+ xdrproc_t p_inproc, p_outproc;
+ struct proglst *p_nxt;
+} *proglst;
+static void universal();
+static SVCXPRT *transp;
+struct proglst *pl;
+
+int registerrpc(int prognum, int versnum, int procnum, char *(*progname)(), xdrproc_t inproc, xdrproc_t outproc)
+{
+
+ if (procnum == NULLPROC) {
+ (void) fprintf(stderr,
+ "can't reassign procedure number %d\n", NULLPROC);
+ return (-1);
+ }
+ if (transp == 0) {
+ transp = svcudp_create(RPC_ANYSOCK);
+ if (transp == NULL) {
+ (void) fprintf(stderr, "couldn't create an rpc server\n");
+ return (-1);
+ }
+ }
+ (void) pmap_unset((u_long) prognum, (u_long) versnum);
+ if (!svc_register(transp, (u_long) prognum, (u_long) versnum,
+ universal, IPPROTO_UDP)) {
+ (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
+ prognum, versnum);
+ return (-1);
+ }
+ pl = (struct proglst *) malloc(sizeof(struct proglst));
+
+ if (pl == NULL) {
+ (void) fprintf(stderr, "registerrpc: out of memory\n");
+ return (-1);
+ }
+ pl->p_progname = progname;
+ pl->p_prognum = prognum;
+ pl->p_procnum = procnum;
+ pl->p_inproc = inproc;
+ pl->p_outproc = outproc;
+ pl->p_nxt = proglst;
+ proglst = pl;
+ return (0);
+}
+
+static void universal(rqstp, transp)
+struct svc_req *rqstp;
+SVCXPRT *transp;
+{
+ int prog, proc;
+ char *outdata;
+ char xdrbuf[UDPMSGSIZE];
+ struct proglst *pl;
+
+ /*
+ * enforce "procnum 0 is echo" convention
+ */
+ if (rqstp->rq_proc == NULLPROC) {
+ if (svc_sendreply(transp, (xdrproc_t)xdr_void, (char *) NULL) == FALSE) {
+ (void) fprintf(stderr, "xxx\n");
+ exit(1);
+ }
+ return;
+ }
+ prog = rqstp->rq_prog;
+ proc = rqstp->rq_proc;
+ for (pl = proglst; pl != NULL; pl = pl->p_nxt)
+ if (pl->p_prognum == prog && pl->p_procnum == proc) {
+ /* decode arguments into a CLEAN buffer */
+ bzero(xdrbuf, sizeof(xdrbuf)); /* required ! */
+ if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
+ svcerr_decode(transp);
+ return;
+ }
+ outdata = (*(pl->p_progname)) (xdrbuf);
+ if (outdata == NULL && pl->p_outproc != (xdrproc_t)xdr_void)
+ /* there was an error */
+ return;
+ if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
+ (void) fprintf(stderr,
+ "trouble replying to prog %d\n",
+ pl->p_prognum);
+ exit(1);
+ }
+ /* free the decoded arguments */
+ (void) svc_freeargs(transp, pl->p_inproc, xdrbuf);
+ return;
+ }
+ (void) fprintf(stderr, "never registered prog %d\n", prog);
+ exit(1);
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_tcp.c b/mdk-stage1/dietlibc/librpc/svc_tcp.c
new file mode 100644
index 000000000..6edafa1b1
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_tcp.c
@@ -0,0 +1,406 @@
+/* @(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_tcp.c, Server side for TCP/IP based RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Actually implements two flavors of transporter -
+ * a tcp rendezvouser (a listner and connection establisher)
+ * and a record/tcp stream.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Ops vector for TCP/IP based rpc service handle
+ */
+static bool_t svctcp_recv();
+static enum xprt_stat svctcp_stat();
+static bool_t svctcp_getargs();
+static bool_t svctcp_reply();
+static bool_t svctcp_freeargs();
+static void svctcp_destroy();
+
+static struct xp_ops svctcp_op = {
+ svctcp_recv,
+ svctcp_stat,
+ svctcp_getargs,
+ svctcp_reply,
+ svctcp_freeargs,
+ svctcp_destroy
+};
+
+/*
+ * Ops vector for TCP/IP rendezvous handler
+ */
+static bool_t rendezvous_request();
+static enum xprt_stat rendezvous_stat();
+
+static struct xp_ops svctcp_rendezvous_op = {
+ rendezvous_request,
+ rendezvous_stat,
+ (void*)abort,
+ (void*)abort,
+ (void*)abort,
+ svctcp_destroy
+};
+
+static int readtcp(), writetcp();
+static SVCXPRT *makefd_xprt();
+
+struct tcp_rendezvous { /* kept in xprt->xp_p1 */
+ u_int sendsize;
+ u_int recvsize;
+};
+
+struct tcp_conn { /* kept in xprt->xp_p1 */
+ enum xprt_stat strm_stat;
+ u_long x_id;
+ XDR xdrs;
+ char verf_body[MAX_AUTH_BYTES];
+};
+
+/*
+ * Usage:
+ * xprt = svctcp_create(sock, send_buf_size, recv_buf_size);
+ *
+ * Creates, registers, and returns a (rpc) tcp based transporter.
+ * Once *xprt is initialized, it is registered as a transporter
+ * see (svc.h, xprt_register). This routine returns
+ * a NULL if a problem occurred.
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svctcp_create
+ * binds it to an arbitrary port. The routine then starts a tcp
+ * listener on the socket's associated port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ *
+ * Since tcp streams do buffered io similar to stdio, the caller can specify
+ * how big the send and receive buffers are via the second and third parms;
+ * 0 => use the system default.
+ */
+SVCXPRT *svctcp_create(sock, sendsize, recvsize)
+register int sock;
+u_int sendsize;
+u_int recvsize;
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ int len = sizeof(struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("svc_tcp.c - tcp socket creation problem");
+ return ((SVCXPRT *) NULL);
+ }
+ madesock = TRUE;
+ }
+ bzero((char *) &addr, sizeof(addr));
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void) bind(sock, (struct sockaddr *) &addr, len);
+ }
+ if ((getsockname(sock, (struct sockaddr *) &addr, &len) != 0) ||
+ (listen(sock, 2) != 0)) {
+ perror("svctcp_.c - cannot getsockname or listen");
+ if (madesock)
+ (void) close(sock);
+ return ((SVCXPRT *) NULL);
+ }
+ r = (struct tcp_rendezvous *) mem_alloc(sizeof(*r));
+ if (r == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ r->sendsize = sendsize;
+ r->recvsize = recvsize;
+ xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t) r;
+ xprt->xp_verf = _null_auth;
+ xprt->xp_ops = &svctcp_rendezvous_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+/*
+ * Like svtcp_create(), except the routine takes any *open* UNIX file
+ * descriptor as its first input.
+ */
+SVCXPRT *svcfd_create(fd, sendsize, recvsize)
+int fd;
+u_int sendsize;
+u_int recvsize;
+{
+
+ return (makefd_xprt(fd, sendsize, recvsize));
+}
+
+static SVCXPRT *makefd_xprt(fd, sendsize, recvsize)
+int fd;
+u_int sendsize;
+u_int recvsize;
+{
+ register SVCXPRT *xprt;
+ register struct tcp_conn *cd;
+
+ xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
+ if (xprt == (SVCXPRT *) NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ goto done;
+ }
+ cd = (struct tcp_conn *) mem_alloc(sizeof(struct tcp_conn));
+
+ if (cd == (struct tcp_conn *) NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ mem_free((char *) xprt, sizeof(SVCXPRT));
+ xprt = (SVCXPRT *) NULL;
+ goto done;
+ }
+ cd->strm_stat = XPRT_IDLE;
+ xdrrec_create(&(cd->xdrs), sendsize, recvsize,
+ (caddr_t) xprt, readtcp, writetcp);
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t) cd;
+ xprt->xp_verf.oa_base = cd->verf_body;
+ xprt->xp_addrlen = 0;
+ xprt->xp_ops = &svctcp_op; /* truely deals with calls */
+ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */
+ xprt->xp_sock = fd;
+ xprt_register(xprt);
+ done:
+ return (xprt);
+}
+
+static bool_t rendezvous_request(xprt)
+register SVCXPRT *xprt;
+{
+ int sock;
+ struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ int len;
+
+ r = (struct tcp_rendezvous *) xprt->xp_p1;
+ again:
+ len = sizeof(struct sockaddr_in);
+
+ if ((sock = accept(xprt->xp_sock, (struct sockaddr *) &addr,
+ &len)) < 0) {
+ if (errno == EINTR)
+ goto again;
+ return (FALSE);
+ }
+ /*
+ * make a new transporter (re-uses xprt)
+ */
+ xprt = makefd_xprt(sock, r->sendsize, r->recvsize);
+ xprt->xp_raddr = addr;
+ xprt->xp_addrlen = len;
+ return (FALSE); /* there is never an rpc msg to be processed */
+}
+
+static enum xprt_stat rendezvous_stat()
+{
+
+ return (XPRT_IDLE);
+}
+
+static void svctcp_destroy(xprt)
+register SVCXPRT *xprt;
+{
+ register struct tcp_conn *cd = (struct tcp_conn *) xprt->xp_p1;
+
+ xprt_unregister(xprt);
+ (void) close(xprt->xp_sock);
+ if (xprt->xp_port != 0) {
+ /* a rendezvouser socket */
+ xprt->xp_port = 0;
+ } else {
+ /* an actual connection socket */
+ XDR_DESTROY(&(cd->xdrs));
+ }
+ mem_free((caddr_t) cd, sizeof(struct tcp_conn));
+
+ mem_free((caddr_t) xprt, sizeof(SVCXPRT));
+}
+
+/*
+ * All read operations timeout after 35 seconds.
+ * A timeout is fatal for the connection.
+ */
+static struct timeval wait_per_try = { 35, 0 };
+
+/*
+ * reads data from the tcp conection.
+ * any error is fatal and the connection is closed.
+ * (And a read of zero bytes is a half closed stream => error.)
+ */
+static int readtcp(xprt, buf, len)
+register SVCXPRT *xprt;
+caddr_t buf;
+register int len;
+{
+ register int sock = xprt->xp_sock;
+
+#ifdef FD_SETSIZE
+ fd_set mask;
+ fd_set readfds;
+
+ FD_ZERO(&mask);
+ FD_SET(sock, &mask);
+#else
+ register int mask = 1 << sock;
+ int readfds;
+#endif /* def FD_SETSIZE */
+ do {
+ readfds = mask;
+ if (select(_rpc_dtablesize(), &readfds, 0, 0, &wait_per_try) <= 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ goto fatal_err;
+ }
+#ifdef FD_SETSIZE
+ } while (!FD_ISSET(sock, &readfds));
+#else
+ } while (readfds != mask);
+#endif /* def FD_SETSIZE */
+ if ((len = read(sock, buf, len)) > 0) {
+ return (len);
+ }
+ fatal_err:
+ ((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
+ return (-1);
+}
+
+/*
+ * writes data to the tcp connection.
+ * Any error is fatal and the connection is closed.
+ */
+static int writetcp(xprt, buf, len)
+register SVCXPRT *xprt;
+caddr_t buf;
+int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = write(xprt->xp_sock, buf, cnt)) < 0) {
+ ((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
+ return (-1);
+ }
+ }
+ return (len);
+}
+
+static enum xprt_stat svctcp_stat(xprt)
+SVCXPRT *xprt;
+{
+ register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
+
+ if (cd->strm_stat == XPRT_DIED)
+ return (XPRT_DIED);
+ if (!xdrrec_eof(&(cd->xdrs)))
+ return (XPRT_MOREREQS);
+ return (XPRT_IDLE);
+}
+
+static bool_t svctcp_recv(xprt, msg)
+SVCXPRT *xprt;
+register struct rpc_msg *msg;
+{
+ register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+
+ xdrs->x_op = XDR_DECODE;
+ (void) xdrrec_skiprecord(xdrs);
+ if (xdr_callmsg(xdrs, msg)) {
+ cd->x_id = msg->rm_xid;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+static bool_t svctcp_getargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+
+ return ((*xdr_args)
+ (&(((struct tcp_conn *) (xprt->xp_p1))->xdrs), args_ptr));
+}
+
+static bool_t svctcp_freeargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+ register XDR *xdrs = &(((struct tcp_conn *) (xprt->xp_p1))->xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args) (xdrs, args_ptr));
+}
+
+static bool_t svctcp_reply(xprt, msg)
+SVCXPRT *xprt;
+register struct rpc_msg *msg;
+{
+ register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+ register bool_t stat;
+
+ xdrs->x_op = XDR_ENCODE;
+ msg->rm_xid = cd->x_id;
+ stat = xdr_replymsg(xdrs, msg);
+ (void) xdrrec_endofrecord(xdrs, TRUE);
+ return (stat);
+}
diff --git a/mdk-stage1/dietlibc/librpc/svc_udp.c b/mdk-stage1/dietlibc/librpc/svc_udp.c
new file mode 100644
index 000000000..1cdb5ce91
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/svc_udp.c
@@ -0,0 +1,467 @@
+/* @(#)svc_udp.c 2.2 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_udp.c,
+ * Server side for UDP/IP based RPC. (Does some caching in the hopes of
+ * achieving execute-at-most-once semantics.)
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+
+#define rpc_buffer(xprt) ((xprt)->xp_p1)
+#define MAX(a, b) ((a > b) ? a : b)
+
+static bool_t svcudp_recv();
+static bool_t svcudp_reply();
+static enum xprt_stat svcudp_stat();
+static bool_t svcudp_getargs();
+static bool_t svcudp_freeargs();
+static void svcudp_destroy();
+
+static struct xp_ops svcudp_op = {
+ svcudp_recv,
+ svcudp_stat,
+ svcudp_getargs,
+ svcudp_reply,
+ svcudp_freeargs,
+ svcudp_destroy
+};
+
+extern int errno;
+
+/*
+ * kept in xprt->xp_p2
+ */
+struct svcudp_data {
+ u_int su_iosz; /* byte size of send.recv buffer */
+ u_long su_xid; /* transaction id */
+ XDR su_xdrs; /* XDR handle */
+ char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
+ char *su_cache; /* cached data, NULL if no cache */
+};
+
+#define su_data(xprt) ((struct svcudp_data *)(xprt->xp_p2))
+
+static int cache_get(SVCXPRT* xprt, struct rpc_msg* msg, char** replyp, u_long* replylenp);
+static void cache_set(SVCXPRT* xprt, u_long replylen);
+
+/*
+ * Usage:
+ * xprt = svcudp_create(sock);
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svcudp_create
+ * binds it to an arbitrary port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ * Once *xprt is initialized, it is registered as a transporter;
+ * see (svc.h, xprt_register).
+ * The routines returns NULL if a problem occurred.
+ */
+SVCXPRT *svcudp_bufcreate(sock, sendsz, recvsz)
+register int sock;
+u_int sendsz, recvsz;
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct svcudp_data *su;
+ struct sockaddr_in addr;
+ int len = sizeof(struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("svcudp_create: socket creation problem");
+ return ((SVCXPRT *) NULL);
+ }
+ madesock = TRUE;
+ }
+ bzero((char *) &addr, sizeof(addr));
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void) bind(sock, (struct sockaddr *) &addr, len);
+ }
+ if (getsockname(sock, (struct sockaddr *) &addr, &len) != 0) {
+ perror("svcudp_create - cannot getsockname");
+ if (madesock)
+ (void) close(sock);
+ return ((SVCXPRT *) NULL);
+ }
+ xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void) fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su = (struct svcudp_data *) mem_alloc(sizeof(*su));
+ if (su == NULL) {
+ (void) fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
+ if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
+ (void) fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
+ XDR_DECODE);
+ su->su_cache = NULL;
+ xprt->xp_p2 = (caddr_t) su;
+ xprt->xp_verf.oa_base = su->su_verfbody;
+ xprt->xp_ops = &svcudp_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+SVCXPRT *svcudp_create(sock)
+int sock;
+{
+
+ return (svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum xprt_stat svcudp_stat(xprt)
+SVCXPRT *xprt;
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t svcudp_recv(xprt, msg)
+register SVCXPRT *xprt;
+struct rpc_msg *msg;
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int rlen;
+ char *reply;
+ u_long replylen;
+
+ again:
+ xprt->xp_addrlen = sizeof(struct sockaddr_in);
+
+ rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
+ 0, (struct sockaddr *) &(xprt->xp_raddr),
+ &(xprt->xp_addrlen));
+ if (rlen == -1 && errno == EINTR)
+ goto again;
+ if (rlen < 4 * sizeof(u_long))
+ return (FALSE);
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (!xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ su->su_xid = msg->rm_xid;
+ if (su->su_cache != NULL) {
+ if (cache_get(xprt, msg, &reply, &replylen)) {
+ (void) sendto(xprt->xp_sock, reply, (int) replylen, 0,
+ (struct sockaddr *) &xprt->xp_raddr,
+ xprt->xp_addrlen);
+ return (TRUE);
+ }
+ }
+ return (TRUE);
+}
+
+static bool_t svcudp_reply(xprt, msg)
+register SVCXPRT *xprt;
+struct rpc_msg *msg;
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int slen;
+ register bool_t stat = FALSE;
+
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ msg->rm_xid = su->su_xid;
+ if (xdr_replymsg(xdrs, msg)) {
+ slen = (int) XDR_GETPOS(xdrs);
+ if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0,
+ (struct sockaddr *) &(xprt->xp_raddr), xprt->xp_addrlen)
+ == slen) {
+ stat = TRUE;
+ if (su->su_cache && slen >= 0) {
+ cache_set(xprt, (u_long) slen);
+ }
+ }
+ }
+ return (stat);
+}
+
+static bool_t svcudp_getargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+
+ return ((*xdr_args) (&(su_data(xprt)->su_xdrs), args_ptr));
+}
+
+static bool_t svcudp_freeargs(xprt, xdr_args, args_ptr)
+SVCXPRT *xprt;
+xdrproc_t xdr_args;
+caddr_t args_ptr;
+{
+ register XDR *xdrs = &(su_data(xprt)->su_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args) (xdrs, args_ptr));
+}
+
+static void svcudp_destroy(xprt)
+register SVCXPRT *xprt;
+{
+ register struct svcudp_data *su = su_data(xprt);
+
+ xprt_unregister(xprt);
+ (void) close(xprt->xp_sock);
+ XDR_DESTROY(&(su->su_xdrs));
+ mem_free(rpc_buffer(xprt), su->su_iosz);
+ mem_free((caddr_t) su, sizeof(struct svcudp_data));
+
+ mem_free((caddr_t) xprt, sizeof(SVCXPRT));
+}
+
+
+/***********this could be a separate file*********************/
+
+/*
+ * Fifo cache for udp server
+ * Copies pointers to reply buffers into fifo cache
+ * Buffers are sent again if retransmissions are detected.
+ */
+
+#define SPARSENESS 4 /* 75% sparse */
+
+#define CACHE_PERROR(msg) \
+ (void) fprintf(stderr,"%s\n", msg)
+
+#define ALLOC(type, size) \
+ (type *) mem_alloc((unsigned) (sizeof(type) * (size)))
+
+#define BZERO(addr, type, size) \
+ bzero((char *) addr, sizeof(type) * (int) (size))
+
+/*
+ * An entry in the cache
+ */
+typedef struct cache_node *cache_ptr;
+struct cache_node {
+ /*
+ * Index into cache is xid, proc, vers, prog and address
+ */
+ u_long cache_xid;
+ u_long cache_proc;
+ u_long cache_vers;
+ u_long cache_prog;
+ struct sockaddr_in cache_addr;
+ /*
+ * The cached reply and length
+ */
+ char *cache_reply;
+ u_long cache_replylen;
+ /*
+ * Next node on the list, if there is a collision
+ */
+ cache_ptr cache_next;
+};
+
+
+
+/*
+ * The entire cache
+ */
+struct udp_cache {
+ u_long uc_size; /* size of cache */
+ cache_ptr *uc_entries; /* hash table of entries in cache */
+ cache_ptr *uc_fifo; /* fifo list of entries in cache */
+ u_long uc_nextvictim; /* points to next victim in fifo list */
+ u_long uc_prog; /* saved program number */
+ u_long uc_vers; /* saved version number */
+ u_long uc_proc; /* saved procedure number */
+ struct sockaddr_in uc_addr; /* saved caller's address */
+};
+
+
+/*
+ * the hashing function
+ */
+#define CACHE_LOC(transp, xid) \
+ (xid % (SPARSENESS*((struct udp_cache *) su_data(transp)->su_cache)->uc_size))
+
+
+/*
+ * Enable use of the cache.
+ * Note: there is no disable.
+ */
+int svcudp_enablecache(SVCXPRT* transp, u_long size)
+{
+ struct svcudp_data *su = su_data(transp);
+ struct udp_cache *uc;
+
+ if (su->su_cache != NULL) {
+ CACHE_PERROR("enablecache: cache already enabled");
+ return (0);
+ }
+ uc = ALLOC(struct udp_cache, 1);
+ if (uc == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache");
+ return (0);
+ }
+ uc->uc_size = size;
+ uc->uc_nextvictim = 0;
+ uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
+ if (uc->uc_entries == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache data");
+ return (0);
+ }
+ BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
+ uc->uc_fifo = ALLOC(cache_ptr, size);
+ if (uc->uc_fifo == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache fifo");
+ return (0);
+ }
+ BZERO(uc->uc_fifo, cache_ptr, size);
+ su->su_cache = (char *) uc;
+ return (1);
+}
+
+
+/*
+ * Set an entry in the cache
+ */
+static void cache_set(SVCXPRT* xprt, u_long replylen)
+{
+ register cache_ptr victim;
+ register cache_ptr *vicp;
+ register struct svcudp_data *su = su_data(xprt);
+ struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+ u_int loc;
+ char *newbuf;
+
+ /*
+ * Find space for the new entry, either by
+ * reusing an old entry, or by mallocing a new one
+ */
+ victim = uc->uc_fifo[uc->uc_nextvictim];
+ if (victim != NULL) {
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ for (vicp = &uc->uc_entries[loc];
+ *vicp != NULL && *vicp != victim;
+ vicp = &(*vicp)->cache_next);
+ if (*vicp == NULL) {
+ CACHE_PERROR("cache_set: victim not found");
+ return;
+ }
+ *vicp = victim->cache_next; /* remote from cache */
+ newbuf = victim->cache_reply;
+ } else {
+ victim = ALLOC(struct cache_node, 1);
+
+ if (victim == NULL) {
+ CACHE_PERROR("cache_set: victim alloc failed");
+ return;
+ }
+ newbuf = mem_alloc(su->su_iosz);
+ if (newbuf == NULL) {
+ CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
+ return;
+ }
+ }
+
+ /*
+ * Store it away
+ */
+ victim->cache_replylen = replylen;
+ victim->cache_reply = rpc_buffer(xprt);
+ rpc_buffer(xprt) = newbuf;
+ xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
+ XDR_ENCODE);
+ victim->cache_xid = su->su_xid;
+ victim->cache_proc = uc->uc_proc;
+ victim->cache_vers = uc->uc_vers;
+ victim->cache_prog = uc->uc_prog;
+ victim->cache_addr = uc->uc_addr;
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ victim->cache_next = uc->uc_entries[loc];
+ uc->uc_entries[loc] = victim;
+ uc->uc_fifo[uc->uc_nextvictim++] = victim;
+ uc->uc_nextvictim %= uc->uc_size;
+}
+
+/*
+ * Try to get an entry from the cache
+ * return 1 if found, 0 if not found
+ */
+static int cache_get(SVCXPRT* xprt, struct rpc_msg* msg, char** replyp, u_long* replylenp)
+{
+ u_int loc;
+ register cache_ptr ent;
+ register struct svcudp_data *su = su_data(xprt);
+ register struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+
+# define EQADDR(a1, a2) (bcmp((char*)&a1, (char*)&a2, sizeof(a1)) == 0)
+
+ loc = CACHE_LOC(xprt, su->su_xid);
+ for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
+ if (ent->cache_xid == su->su_xid &&
+ ent->cache_proc == uc->uc_proc &&
+ ent->cache_vers == uc->uc_vers &&
+ ent->cache_prog == uc->uc_prog &&
+ EQADDR(ent->cache_addr, uc->uc_addr)) {
+ *replyp = ent->cache_reply;
+ *replylenp = ent->cache_replylen;
+ return (1);
+ }
+ }
+ /*
+ * Failed to find entry
+ * Remember a few things so we can do a set later
+ */
+ uc->uc_proc = msg->rm_call.cb_proc;
+ uc->uc_vers = msg->rm_call.cb_vers;
+ uc->uc_prog = msg->rm_call.cb_prog;
+ uc->uc_addr = xprt->xp_raddr;
+ return (0);
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr.c b/mdk-stage1/dietlibc/librpc/xdr.c
new file mode 100644
index 000000000..864b47dea
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr.c
@@ -0,0 +1,536 @@
+/* @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)xdr.c 1.35 87/08/12";
+#endif
+
+/*
+ * xdr.c, Generic XDR routines implementation.
+ *
+ * Copyright (C) 1986, Sun Microsystems, Inc.
+ *
+ * These are the "generic" xdr routines used to serialize and de-serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <string.h>
+
+/*
+ * constants specific to the xdr "protocol"
+ */
+#define XDR_FALSE ((long) 0)
+#define XDR_TRUE ((long) 1)
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * for unit alignment
+ */
+static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
+
+/*
+ * Free a data structure using XDR
+ * Not a filter, but a convenient utility nonetheless
+ */
+void xdr_free(xdrproc_t proc, char* objp)
+{
+ XDR x;
+
+ x.x_op = XDR_FREE;
+ (*proc) (&x, objp);
+}
+
+/*
+ * XDR nothing
+ */
+bool_t xdr_void( /* xdrs, addr */ )
+ /* XDR *xdrs; */
+ /* caddr_t addr; */
+{
+
+ return (TRUE);
+}
+
+/*
+ * XDR integers
+ */
+bool_t xdr_int(XDR* xdrs, int* ip)
+{
+
+#ifdef lint
+ (void) (xdr_short(xdrs, (short *) ip));
+ return (xdr_long(xdrs, (long *) ip));
+#else
+ if (sizeof(int) == sizeof(long)) {
+ return (xdr_long(xdrs, (long *) ip));
+ } else {
+ return (xdr_short(xdrs, (short *) ip));
+ }
+#endif
+}
+
+/*
+ * XDR unsigned integers
+ */
+bool_t xdr_u_int(XDR* xdrs, unsigned int* up)
+{
+
+#ifdef lint
+ (void) (xdr_short(xdrs, (short *) up));
+ return (xdr_u_long(xdrs, (u_long *) up));
+#else
+ if (sizeof(u_int) == sizeof(u_long)) {
+ return (xdr_u_long(xdrs, (u_long *) up));
+ } else {
+ return (xdr_short(xdrs, (short *) up));
+ }
+#endif
+}
+
+/*
+ * XDR long integers
+ * same as xdr_u_long - open coded to save a proc call!
+ */
+bool_t xdr_long(XDR* xdrs, long* lp)
+{
+
+ if (xdrs->x_op == XDR_ENCODE)
+ return (XDR_PUTLONG(xdrs, lp));
+
+ if (xdrs->x_op == XDR_DECODE)
+ return (XDR_GETLONG(xdrs, lp));
+
+ if (xdrs->x_op == XDR_FREE)
+ return (TRUE);
+
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned long integers
+ * same as xdr_long - open coded to save a proc call!
+ */
+bool_t xdr_u_long(XDR* xdrs, unsigned long* ulp)
+{
+
+ if (xdrs->x_op == XDR_DECODE)
+ return (XDR_GETLONG(xdrs, (long *) ulp));
+ if (xdrs->x_op == XDR_ENCODE)
+ return (XDR_PUTLONG(xdrs, (long *) ulp));
+ if (xdrs->x_op == XDR_FREE)
+ return (TRUE);
+ return (FALSE);
+}
+
+/*
+ * XDR short integers
+ */
+bool_t xdr_short(XDR* xdrs, short* sp)
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *sp;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *sp = (short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned short integers
+ */
+bool_t xdr_u_short(XDR* xdrs, unsigned short* usp)
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) * usp;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *usp = (u_short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR a char
+ */
+bool_t xdr_char(XDR* xdrs, char* cp)
+{
+ int i;
+
+ i = (*cp);
+ if (!xdr_int(xdrs, &i)) {
+ return (FALSE);
+ }
+ *cp = i;
+ return (TRUE);
+}
+
+/*
+ * XDR an unsigned char
+ */
+bool_t xdr_u_char(XDR* xdrs, unsigned char* cp)
+{
+ u_int u;
+
+ u = (*cp);
+ if (!xdr_u_int(xdrs, &u)) {
+ return (FALSE);
+ }
+ *cp = u;
+ return (TRUE);
+}
+
+/*
+ * XDR booleans
+ */
+bool_t xdr_bool(xdrs, bp)
+register XDR *xdrs;
+bool_t *bp;
+{
+ long lb;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ lb = *bp ? XDR_TRUE : XDR_FALSE;
+ return (XDR_PUTLONG(xdrs, &lb));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &lb)) {
+ return (FALSE);
+ }
+ *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR enumerations
+ */
+bool_t xdr_enum(xdrs, ep)
+XDR *xdrs;
+enum_t *ep;
+{
+#ifndef lint
+ enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
+
+ /*
+ * enums are treated as ints
+ */
+ if (sizeof(enum sizecheck) == sizeof(long)) {
+ return (xdr_long(xdrs, (long *) ep));
+ } else if (sizeof(enum sizecheck) == sizeof(short)) {
+ return (xdr_short(xdrs, (short *) ep));
+ } else {
+ return (FALSE);
+ }
+#else
+ (void) (xdr_short(xdrs, (short *) ep));
+ return (xdr_long(xdrs, (long *) ep));
+#endif
+}
+
+/*
+ * XDR opaque data
+ * Allows the specification of a fixed size sequence of opaque bytes.
+ * cp points to the opaque object and cnt gives the byte length.
+ */
+bool_t xdr_opaque(xdrs, cp, cnt)
+register XDR *xdrs;
+caddr_t cp;
+register u_int cnt;
+{
+ register u_int rndup;
+ static char crud[BYTES_PER_XDR_UNIT];
+
+ /*
+ * if no data we are done
+ */
+ if (cnt == 0)
+ return (TRUE);
+
+ /*
+ * round byte count to full xdr units
+ */
+ rndup = cnt % BYTES_PER_XDR_UNIT;
+ if (rndup > 0)
+ rndup = BYTES_PER_XDR_UNIT - rndup;
+
+ if (xdrs->x_op == XDR_DECODE) {
+ if (!XDR_GETBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_GETBYTES(xdrs, crud, rndup));
+ }
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
+ }
+
+ if (xdrs->x_op == XDR_FREE) {
+ return (TRUE);
+ }
+
+ return (FALSE);
+}
+
+/*
+ * XDR counted bytes
+ * *cpp is a pointer to the bytes, *sizep is the count.
+ * If *cpp is NULL maxsize bytes are allocated
+ */
+bool_t xdr_bytes(xdrs, cpp, sizep, maxsize)
+register XDR *xdrs;
+char **cpp;
+register u_int *sizep;
+u_int maxsize;
+{
+ register char *sp = *cpp; /* sp is the actual string pointer */
+ register u_int nodesize;
+
+ /*
+ * first deal with the length since xdr bytes are counted
+ */
+ if (!xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ nodesize = *sizep;
+ if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL) {
+ *cpp = sp = (char *) mem_alloc(nodesize);
+ }
+ if (sp == NULL) {
+ (void) fprintf(stderr, "xdr_bytes: out of memory\n");
+ return (FALSE);
+ }
+ /* fall into ... */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, nodesize));
+
+ case XDR_FREE:
+ if (sp != NULL) {
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ }
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * Implemented here due to commonality of the object.
+ */
+bool_t xdr_netobj(xdrs, np)
+XDR *xdrs;
+struct netobj *np;
+{
+
+ return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
+}
+
+/*
+ * XDR a descriminated union
+ * Support routine for discriminated unions.
+ * You create an array of xdrdiscrim structures, terminated with
+ * an entry with a null procedure pointer. The routine gets
+ * the discriminant value and then searches the array of xdrdiscrims
+ * looking for that value. It calls the procedure given in the xdrdiscrim
+ * to handle the discriminant. If there is no specific routine a default
+ * routine may be called.
+ * If there is no specific or default routine an error is returned.
+ */
+bool_t xdr_union(XDR* xdrs, enum_t* dscmp, char* unp, const struct xdr_discrim* choices, xdrproc_t dfault)
+{
+ register enum_t dscm;
+
+ /*
+ * we deal with the discriminator; it's an enum
+ */
+ if (!xdr_enum(xdrs, dscmp)) {
+ return (FALSE);
+ }
+ dscm = *dscmp;
+
+ /*
+ * search choices for a value that matches the discriminator.
+ * if we find one, execute the xdr routine for that value.
+ */
+ for (; choices->proc != NULL_xdrproc_t; choices++) {
+ if (choices->value == dscm)
+ return ((*(choices->proc)) (xdrs, unp, LASTUNSIGNED));
+ }
+
+ /*
+ * no match - execute the default xdr routine if there is one
+ */
+ return ((dfault == NULL_xdrproc_t) ? FALSE :
+ (*dfault) (xdrs, unp, LASTUNSIGNED));
+}
+
+
+/*
+ * Non-portable xdr primitives.
+ * Care should be taken when moving these routines to new architectures.
+ */
+
+
+/*
+ * XDR null terminated ASCII strings
+ * xdr_string deals with "C strings" - arrays of bytes that are
+ * terminated by a NULL character. The parameter cpp references a
+ * pointer to storage; If the pointer is null, then the necessary
+ * storage is allocated. The last parameter is the max allowed length
+ * of the string as specified by a protocol.
+ */
+bool_t xdr_string(xdrs, cpp, maxsize)
+register XDR *xdrs;
+char **cpp;
+u_int maxsize;
+{
+ register char *sp = *cpp; /* sp is the actual string pointer */
+ u_int size;
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr strings are counted-strings
+ */
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ if (sp == NULL) {
+ return (TRUE); /* already free */
+ }
+ /* fall through... */
+ case XDR_ENCODE:
+ size = strlen(sp);
+ break;
+ }
+ if (!xdr_u_int(xdrs, &size)) {
+ return (FALSE);
+ }
+ if (size > maxsize) {
+ return (FALSE);
+ }
+ nodesize = size + 1;
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL)
+ *cpp = sp = (char *) mem_alloc(nodesize);
+ if (sp == NULL) {
+ (void) fprintf(stderr, "xdr_string: out of memory\n");
+ return (FALSE);
+ }
+ sp[size] = 0;
+ /* fall into ... */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, size));
+
+ case XDR_FREE:
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * Wrapper for xdr_string that can be called directly from
+ * routines like clnt_call
+ */
+bool_t xdr_wrapstring(xdrs, cpp)
+XDR *xdrs;
+char **cpp;
+{
+ if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr_array.c b/mdk-stage1/dietlibc/librpc/xdr_array.c
new file mode 100644
index 000000000..f8ae12b19
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_array.c
@@ -0,0 +1,152 @@
+/* @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * xdr_array.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * arrays. See xdr.h for more info on the interface to xdr.
+ */
+
+#include <stdio.h>
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <string.h>
+
+#define LASTUNSIGNED ((u_int)0-1)
+
+
+/*
+ * XDR an array of arbitrary elements
+ * *addrp is a pointer to the array, *sizep is the number of elements.
+ * If addrp is NULL (*sizep * elsize) bytes are allocated.
+ * elsize is the size (in bytes) of each element, and elproc is the
+ * xdr procedure to call to handle each element of the array.
+ */
+bool_t xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
+register XDR *xdrs;
+caddr_t *addrp; /* array pointer */
+u_int *sizep; /* number of elements */
+u_int maxsize; /* max numberof elements */
+u_int elsize; /* size in bytes of each element */
+xdrproc_t elproc; /* xdr routine to handle each element */
+{
+ register u_int i;
+ register caddr_t target = *addrp;
+ register u_int c; /* the actual element count */
+ register bool_t stat = TRUE;
+ register u_int nodesize;
+
+ /* like strings, arrays are really counted arrays */
+ if (!xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ c = *sizep;
+ if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+ nodesize = c * elsize;
+
+ /*
+ * if we are deserializing, we may need to allocate an array.
+ * We also save time by checking for a null array if we are freeing.
+ */
+ if (target == NULL)
+ switch (xdrs->x_op) {
+ case XDR_DECODE:
+ if (c == 0)
+ return (TRUE);
+ *addrp = target = mem_alloc(nodesize);
+ if (target == NULL) {
+ (void) fprintf(stderr, "xdr_array: out of memory\n");
+ return (FALSE);
+ }
+ bzero(target, nodesize);
+ break;
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+
+ /*
+ * now we xdr each element of array
+ */
+ for (i = 0; (i < c) && stat; i++) {
+ stat = (*elproc) (xdrs, target, LASTUNSIGNED);
+ target += elsize;
+ }
+
+ /*
+ * the array may need freeing
+ */
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(*addrp, nodesize);
+ *addrp = NULL;
+ }
+ return (stat);
+}
+
+/*
+ * xdr_vector():
+ *
+ * XDR a fixed length array. Unlike variable-length arrays,
+ * the storage of fixed length arrays is static and unfreeable.
+ * > basep: base of the array
+ * > size: size of the array
+ * > elemsize: size of each element
+ * > xdr_elem: routine to XDR each element
+ */
+bool_t xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
+register XDR *xdrs;
+register char *basep;
+register u_int nelem;
+register u_int elemsize;
+register xdrproc_t xdr_elem;
+{
+ register u_int i;
+ register char *elptr;
+
+ elptr = basep;
+ for (i = 0; i < nelem; i++) {
+ if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED)) {
+ return (FALSE);
+ }
+ elptr += elemsize;
+ }
+ return (TRUE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr_float.c b/mdk-stage1/dietlibc/librpc/xdr_float.c
new file mode 100644
index 000000000..f8eb5e99c
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_float.c
@@ -0,0 +1,284 @@
+/* @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * xdr_float.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "floating point" xdr routines used to (de)serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#include <stdio.h>
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+/*
+ * NB: Not portable.
+ * This routine works on Suns (Sky / 68000's) and Vaxen.
+ */
+
+#ifdef __linux__
+/* cheat big time */
+#define sparc
+#endif
+
+#ifdef vax
+
+/* What IEEE single precision floating point looks like on a Vax */
+struct ieee_single {
+ unsigned int mantissa:23;
+ unsigned int exp:8;
+ unsigned int sign:1;
+};
+
+/* Vax single precision floating point */
+struct vax_single {
+ unsigned int mantissa1:7;
+ unsigned int exp:8;
+ unsigned int sign:1;
+ unsigned int mantissa2:16;
+};
+
+#define VAX_SNG_BIAS 0x81
+#define IEEE_SNG_BIAS 0x7f
+
+static struct sgl_limits {
+ struct vax_single s;
+ struct ieee_single ieee;
+} sgl_limits[2] = {
+ { {
+ 0x7f, 0xff, 0x0, 0xffff}, /* Max Vax */
+ {
+ 0x0, 0xff, 0x0}}, /* Max IEEE */
+ { {
+ 0x0, 0x0, 0x0, 0x0}, /* Min Vax */
+ {
+ 0x0, 0x0, 0x0}} /* Min IEEE */
+};
+#endif /* vax */
+
+bool_t xdr_float(xdrs, fp)
+register XDR *xdrs;
+register float *fp;
+{
+#if !defined(mc68000) && !defined(sparc)
+ struct ieee_single is;
+ struct vax_single vs, *vsp;
+ struct sgl_limits *lim;
+ int i;
+#endif
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#if defined(mc68000) || defined(sparc)
+ return (XDR_PUTLONG(xdrs, (long *) fp));
+#else
+ vs = *((struct vax_single *) fp);
+ for (i = 0, lim = sgl_limits;
+
+ i < sizeof(sgl_limits) / sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((vs.mantissa2 == lim->s.mantissa2) &&
+ (vs.exp == lim->s.exp) &&
+ (vs.mantissa1 == lim->s.mantissa1)) {
+ is = lim->ieee;
+ goto shipit;
+ }
+ }
+ is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
+ is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
+ shipit:
+ is.sign = vs.sign;
+ return (XDR_PUTLONG(xdrs, (long *) &is));
+#endif
+
+ case XDR_DECODE:
+#if defined(mc68000) || defined(sparc)
+ return (XDR_GETLONG(xdrs, (long *) fp));
+#else
+ vsp = (struct vax_single *) fp;
+ if (!XDR_GETLONG(xdrs, (long *) &is))
+ return (FALSE);
+ for (i = 0, lim = sgl_limits;
+
+ i < sizeof(sgl_limits) / sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((is.exp == lim->ieee.exp) &&
+ (is.mantissa == lim->ieee.mantissa)) {
+ *vsp = lim->s;
+ goto doneit;
+ }
+ }
+ vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
+ vsp->mantissa2 = is.mantissa;
+ vsp->mantissa1 = (is.mantissa >> 16);
+ doneit:
+ vsp->sign = is.sign;
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * This routine works on Suns (Sky / 68000's) and Vaxen.
+ */
+
+#ifdef vax
+/* What IEEE double precision floating point looks like on a Vax */
+struct ieee_double {
+ unsigned int mantissa1:20;
+ unsigned int exp:11;
+ unsigned int sign:1;
+ unsigned int mantissa2:32;
+};
+
+/* Vax double precision floating point */
+struct vax_double {
+ unsigned int mantissa1:7;
+ unsigned int exp:8;
+ unsigned int sign:1;
+ unsigned int mantissa2:16;
+ unsigned int mantissa3:16;
+ unsigned int mantissa4:16;
+};
+
+#define VAX_DBL_BIAS 0x81
+#define IEEE_DBL_BIAS 0x3ff
+#define MASK(nbits) ((1 << nbits) - 1)
+
+static struct dbl_limits {
+ struct vax_double d;
+ struct ieee_double ieee;
+} dbl_limits[2] = {
+ { {
+ 0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff}, /* Max Vax */
+ {
+ 0x0, 0x7ff, 0x0, 0x0}}, /* Max IEEE */
+ { {
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* Min Vax */
+ {
+ 0x0, 0x0, 0x0, 0x0}} /* Min IEEE */
+};
+
+#endif /* vax */
+
+
+bool_t xdr_double(xdrs, dp)
+register XDR *xdrs;
+double *dp;
+{
+ register long *lp;
+
+#if !defined(mc68000) && !defined(sparc)
+ struct ieee_double id;
+ struct vax_double vd;
+ register struct dbl_limits *lim;
+ int i;
+#endif
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#if defined(mc68000) || defined(sparc)
+ lp = (long *) dp;
+#else
+ vd = *((struct vax_double *) dp);
+ for (i = 0, lim = dbl_limits;
+
+ i < sizeof(dbl_limits) / sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((vd.mantissa4 == lim->d.mantissa4) &&
+ (vd.mantissa3 == lim->d.mantissa3) &&
+ (vd.mantissa2 == lim->d.mantissa2) &&
+ (vd.mantissa1 == lim->d.mantissa1) &&
+ (vd.exp == lim->d.exp)) {
+ id = lim->ieee;
+ goto shipit;
+ }
+ }
+ id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
+ id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
+ id.mantissa2 = ((vd.mantissa2 & MASK(3)) << 29) |
+ (vd.mantissa3 << 13) | ((vd.mantissa4 >> 3) & MASK(13));
+ shipit:
+ id.sign = vd.sign;
+ lp = (long *) &id;
+#endif
+ return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
+
+ case XDR_DECODE:
+#if defined(mc68000) || defined(sparc)
+ lp = (long *) dp;
+ return (XDR_GETLONG(xdrs, lp++) && XDR_GETLONG(xdrs, lp));
+#else
+ lp = (long *) &id;
+ if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
+ return (FALSE);
+ for (i = 0, lim = dbl_limits;
+
+ i < sizeof(dbl_limits) / sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((id.mantissa2 == lim->ieee.mantissa2) &&
+ (id.mantissa1 == lim->ieee.mantissa1) &&
+ (id.exp == lim->ieee.exp)) {
+ vd = lim->d;
+ goto doneit;
+ }
+ }
+ vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
+ vd.mantissa1 = (id.mantissa1 >> 13);
+ vd.mantissa2 = ((id.mantissa1 & MASK(13)) << 3) |
+ (id.mantissa2 >> 29);
+ vd.mantissa3 = (id.mantissa2 >> 13);
+ vd.mantissa4 = (id.mantissa2 << 3);
+ doneit:
+ vd.sign = id.sign;
+ *dp = *((double *) &vd);
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr_mem.c b/mdk-stage1/dietlibc/librpc/xdr_mem.c
new file mode 100644
index 000000000..755f6abf1
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_mem.c
@@ -0,0 +1,180 @@
+/* @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * xdr_mem.h, XDR implementation using memory buffers.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * If you have some data to be interpreted as external data representation
+ * or to be converted to external data representation in a memory buffer,
+ * then this is the package for you.
+ *
+ */
+
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+#include <string.h>
+
+static bool_t xdrmem_getlong();
+static bool_t xdrmem_putlong();
+static bool_t xdrmem_getbytes();
+static bool_t xdrmem_putbytes();
+static u_int xdrmem_getpos();
+static bool_t xdrmem_setpos();
+static int32_t *xdrmem_inline();
+static void xdrmem_destroy();
+
+static struct xdr_ops xdrmem_ops = {
+ xdrmem_getlong,
+ xdrmem_putlong,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline,
+ xdrmem_destroy
+};
+
+/*
+ * The procedure xdrmem_create initializes a stream descriptor for a
+ * memory buffer.
+ */
+void xdrmem_create(xdrs, addr, size, op)
+register XDR *xdrs;
+caddr_t addr;
+u_int size;
+enum xdr_op op;
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrmem_ops;
+ xdrs->x_private = xdrs->x_base = addr;
+ xdrs->x_handy = size;
+}
+
+static void xdrmem_destroy( /*xdrs */ )
+ /*XDR *xdrs; */
+{
+}
+
+static bool_t xdrmem_getlong(xdrs, lp)
+register XDR *xdrs;
+long *lp;
+{
+
+ if ((xdrs->x_handy -= sizeof(long)) < 0)
+ return (FALSE);
+
+ *lp = (long) ntohl((u_long) (*((long *) (xdrs->x_private))));
+ xdrs->x_private += sizeof(long);
+
+ return (TRUE);
+}
+
+static bool_t xdrmem_putlong(xdrs, lp)
+register XDR *xdrs;
+long *lp;
+{
+
+ if ((xdrs->x_handy -= sizeof(long)) < 0)
+ return (FALSE);
+
+ *(long *) xdrs->x_private = (long) htonl((u_long) (*lp));
+ xdrs->x_private += sizeof(long);
+
+ return (TRUE);
+}
+
+static bool_t xdrmem_getbytes(xdrs, addr, len)
+register XDR *xdrs;
+caddr_t addr;
+register u_int len;
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ bcopy(xdrs->x_private, addr, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static bool_t xdrmem_putbytes(xdrs, addr, len)
+register XDR *xdrs;
+caddr_t addr;
+register u_int len;
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ bcopy(addr, xdrs->x_private, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static u_int xdrmem_getpos(xdrs)
+register XDR *xdrs;
+{
+
+ return ((u_int) xdrs->x_private - (u_int) xdrs->x_base);
+}
+
+static bool_t xdrmem_setpos(xdrs, pos)
+register XDR *xdrs;
+u_int pos;
+{
+ register caddr_t newaddr = xdrs->x_base + pos;
+ register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
+
+ if ((long) newaddr > (long) lastaddr)
+ return (FALSE);
+ xdrs->x_private = newaddr;
+ xdrs->x_handy = (int) lastaddr - (int) newaddr;
+ return (TRUE);
+}
+
+static int32_t *xdrmem_inline(xdrs, len)
+register XDR *xdrs;
+int len;
+{
+ int32_t *buf = 0;
+
+ if (xdrs->x_handy >= len) {
+ xdrs->x_handy -= len;
+ buf = (int32_t *) xdrs->x_private;
+ xdrs->x_private += len;
+ }
+ return (buf);
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr_rec.c b/mdk-stage1/dietlibc/librpc/xdr_rec.c
new file mode 100644
index 000000000..83e800f5e
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_rec.c
@@ -0,0 +1,573 @@
+/* @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
+ * layer above tcp (for rpc's use).
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These routines interface XDRSTREAMS to a tcp/ip connection.
+ * There is a record marking layer between the xdr stream
+ * and the tcp transport level. A record is composed on one or more
+ * record fragments. A record fragment is a thirty-two bit header followed
+ * by n bytes of data, where n is contained in the header. The header
+ * is represented as a htonl(u_long). Thegh order bit encodes
+ * whether or not the fragment is the last fragment of the record
+ * (1 => fragment is last, 0 => more fragments to follow.
+ * The other 31 bits encode the byte length of the fragment.
+ */
+
+#include <stdio.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+#include <string.h>
+
+extern long lseek();
+
+static u_int fix_buf_size();
+
+static bool_t xdrrec_getlong();
+static bool_t xdrrec_putlong();
+static bool_t xdrrec_getbytes();
+static bool_t xdrrec_putbytes();
+static u_int xdrrec_getpos();
+static bool_t xdrrec_setpos();
+static int32_t *xdrrec_inline();
+static void xdrrec_destroy();
+
+static struct xdr_ops xdrrec_ops = {
+ xdrrec_getlong,
+ xdrrec_putlong,
+ xdrrec_getbytes,
+ xdrrec_putbytes,
+ xdrrec_getpos,
+ xdrrec_setpos,
+ xdrrec_inline,
+ xdrrec_destroy
+};
+
+/*
+ * A record is composed of one or more record fragments.
+ * A record fragment is a two-byte header followed by zero to
+ * 2**32-1 bytes. The header is treated as a long unsigned and is
+ * encode/decoded to the network via htonl/ntohl. The low order 31 bits
+ * are a byte count of the fragment. The highest order bit is a boolean:
+ * 1 => this fragment is the last fragment of the record,
+ * 0 => this fragment is followed by more fragment(s).
+ *
+ * The fragment/record machinery is not general; it is constructed to
+ * meet the needs of xdr and rpc based on tcp.
+ */
+
+#define LAST_FRAG ((u_long)(1 << 31))
+
+typedef struct rec_strm {
+ caddr_t tcp_handle;
+ caddr_t the_buffer;
+ /*
+ * out-goung bits
+ */
+ int (*writeit) ();
+ caddr_t out_base; /* output buffer (points to frag header) */
+ caddr_t out_finger; /* next output position */
+ caddr_t out_boundry; /* data cannot up to this address */
+ u_long *frag_header; /* beginning of curren fragment */
+ bool_t frag_sent; /* true if buffer sent in middle of record */
+ /*
+ * in-coming bits
+ */
+ int (*readit) ();
+ u_long in_size; /* fixed size of the input buffer */
+ caddr_t in_base;
+ caddr_t in_finger; /* location of next byte to be had */
+ caddr_t in_boundry; /* can read up to this location */
+ long fbtbc; /* fragment bytes to be consumed */
+ bool_t last_frag;
+ u_int sendsize;
+ u_int recvsize;
+} RECSTREAM;
+
+
+/*
+ * Create an xdr handle for xdrrec
+ * xdrrec_create fills in xdrs. Sendsize and recvsize are
+ * send and recv buffer sizes (0 => use default).
+ * tcp_handle is an opaque handle that is passed as the first parameter to
+ * the procedures readit and writeit. Readit and writeit are read and
+ * write respectively. They are like the system
+ * calls expect that they take an opaque handle rather than an fd.
+ */
+void xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
+register XDR *xdrs;
+register u_int sendsize;
+register u_int recvsize;
+caddr_t tcp_handle;
+int (*readit) (); /* like read, but pass it a tcp_handle, not sock */
+int (*writeit) (); /* like write, but pass it a tcp_handle, not sock */
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) mem_alloc(sizeof(RECSTREAM));
+
+ if (rstrm == NULL) {
+ (void) fprintf(stderr, "xdrrec_create: out of memory\n");
+ /*
+ * This is bad. Should rework xdrrec_create to
+ * return a handle, and in this case return NULL
+ */
+ return;
+ }
+ /*
+ * adjust sizes and allocate buffer quad byte aligned
+ */
+ rstrm->sendsize = sendsize = fix_buf_size(sendsize);
+ rstrm->recvsize = recvsize = fix_buf_size(recvsize);
+ rstrm->the_buffer =
+ mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
+ if (rstrm->the_buffer == NULL) {
+ (void) fprintf(stderr, "xdrrec_create: out of memory\n");
+ return;
+ }
+ for (rstrm->out_base = rstrm->the_buffer;
+ (u_int) rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
+ rstrm->out_base++);
+ rstrm->in_base = rstrm->out_base + sendsize;
+ /*
+ * now the rest ...
+ */
+ xdrs->x_ops = &xdrrec_ops;
+ xdrs->x_private = (caddr_t) rstrm;
+ rstrm->tcp_handle = tcp_handle;
+ rstrm->readit = readit;
+ rstrm->writeit = writeit;
+ rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
+ rstrm->frag_header = (u_long *) rstrm->out_base;
+ rstrm->out_finger += sizeof(u_long);
+ rstrm->out_boundry += sendsize;
+ rstrm->frag_sent = FALSE;
+ rstrm->in_size = recvsize;
+ rstrm->in_boundry = rstrm->in_base;
+ rstrm->in_finger = (rstrm->in_boundry += recvsize);
+ rstrm->fbtbc = 0;
+ rstrm->last_frag = TRUE;
+}
+
+
+/*
+ * The reoutines defined below are the xdr ops which will go into the
+ * xdr handle filled in by xdrrec_create.
+ */
+
+static bool_t xdrrec_getlong(xdrs, lp)
+XDR *xdrs;
+long *lp;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+ register long *buflp = (long *) (rstrm->in_finger);
+ long mylong;
+
+ /* first try the inline, fast case */
+ if ((rstrm->fbtbc >= sizeof(long)) &&
+ (((int) rstrm->in_boundry - (int) buflp) >= sizeof(long))) {
+ *lp = (long) ntohl((u_long) (*buflp));
+ rstrm->fbtbc -= sizeof(long);
+ rstrm->in_finger += sizeof(long);
+ } else {
+ if (!xdrrec_getbytes(xdrs, (caddr_t) & mylong, sizeof(long)))
+ return (FALSE);
+
+ *lp = (long) ntohl((u_long) mylong);
+ }
+ return (TRUE);
+}
+
+/*
+ * Internal useful routines
+ */
+static bool_t flush_out(RECSTREAM* rstrm, bool_t eor)
+{
+ register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
+ register u_long len = (u_long) (rstrm->out_finger) -
+ (u_long) (rstrm->frag_header) - sizeof(u_long);
+
+ *(rstrm->frag_header) = htonl(len | eormask);
+ len = (u_long) (rstrm->out_finger) - (u_long) (rstrm->out_base);
+ if ((*(rstrm->writeit)) (rstrm->tcp_handle, rstrm->out_base, (int) len)
+ != (int) len)
+ return (FALSE);
+ rstrm->frag_header = (u_long *) rstrm->out_base;
+ rstrm->out_finger = (caddr_t) rstrm->out_base + sizeof(u_long);
+ return (TRUE);
+}
+
+static bool_t
+/* knows nothing about records! Only about input buffers */
+fill_input_buf(rstrm)
+register RECSTREAM *rstrm;
+{
+ register caddr_t where;
+ u_int i;
+ register int len;
+
+ where = rstrm->in_base;
+ i = (u_int) rstrm->in_boundry % BYTES_PER_XDR_UNIT;
+ where += i;
+ len = rstrm->in_size - i;
+ if ((len = (*(rstrm->readit)) (rstrm->tcp_handle, where, len)) == -1)
+ return (FALSE);
+ rstrm->in_finger = where;
+ where += len;
+ rstrm->in_boundry = where;
+ return (TRUE);
+}
+
+static bool_t
+/* knows nothing about records! Only about input buffers */
+get_input_bytes(rstrm, addr, len)
+register RECSTREAM *rstrm;
+register caddr_t addr;
+register int len;
+{
+ register int current;
+
+ while (len > 0) {
+ current = (int) rstrm->in_boundry - (int) rstrm->in_finger;
+ if (current == 0) {
+ if (!fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ bcopy(rstrm->in_finger, addr, current);
+ rstrm->in_finger += current;
+ addr += current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t
+/* next two bytes of the input stream are treated as a header */
+set_input_fragment(rstrm)
+register RECSTREAM *rstrm;
+{
+ u_long header;
+
+ if (!get_input_bytes(rstrm, (caddr_t) & header, sizeof(header)))
+ return (FALSE);
+ header = (long) ntohl(header);
+ rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
+ rstrm->fbtbc = header & (~LAST_FRAG);
+ return (TRUE);
+}
+
+static bool_t
+/* consumes input bytes; knows nothing about records! */
+skip_input_bytes(rstrm, cnt)
+register RECSTREAM *rstrm;
+long cnt;
+{
+ register int current;
+
+ while (cnt > 0) {
+ current = (int) rstrm->in_boundry - (int) rstrm->in_finger;
+ if (current == 0) {
+ if (!fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (cnt < current) ? cnt : current;
+ rstrm->in_finger += current;
+ cnt -= current;
+ }
+ return (TRUE);
+}
+
+static u_int fix_buf_size(s)
+register u_int s;
+{
+
+ if (s < 100)
+ s = 4000;
+ return (RNDUP(s));
+}
+static bool_t xdrrec_putlong(xdrs, lp)
+XDR *xdrs;
+long *lp;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+ register long *dest_lp = ((long *) (rstrm->out_finger));
+
+ if ((rstrm->out_finger += sizeof(long)) > rstrm->out_boundry) {
+ /*
+ * this case should almost never happen so the code is
+ * inefficient
+ */
+ rstrm->out_finger -= sizeof(long);
+
+ rstrm->frag_sent = TRUE;
+ if (!flush_out(rstrm, FALSE))
+ return (FALSE);
+ dest_lp = ((long *) (rstrm->out_finger));
+ rstrm->out_finger += sizeof(long);
+ }
+ *dest_lp = (long) htonl((u_long) (*lp));
+ return (TRUE);
+}
+
+static bool_t
+/* must manage buffers, fragments, and records */
+xdrrec_getbytes(xdrs, addr, len)
+XDR *xdrs;
+register caddr_t addr;
+register u_int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+ register int current;
+
+ while (len > 0) {
+ current = rstrm->fbtbc;
+ if (current == 0) {
+ if (rstrm->last_frag)
+ return (FALSE);
+ if (!set_input_fragment(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ if (!get_input_bytes(rstrm, addr, current))
+ return (FALSE);
+ addr += current;
+ rstrm->fbtbc -= current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t xdrrec_putbytes(xdrs, addr, len)
+XDR *xdrs;
+register caddr_t addr;
+register u_int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+ register int current;
+
+ while (len > 0) {
+ current = (u_int) rstrm->out_boundry - (u_int) rstrm->out_finger;
+ current = (len < current) ? len : current;
+ bcopy(addr, rstrm->out_finger, current);
+ rstrm->out_finger += current;
+ addr += current;
+ len -= current;
+ if (rstrm->out_finger == rstrm->out_boundry) {
+ rstrm->frag_sent = TRUE;
+ if (!flush_out(rstrm, FALSE))
+ return (FALSE);
+ }
+ }
+ return (TRUE);
+}
+
+static u_int xdrrec_getpos(xdrs)
+register XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ register long pos;
+
+ pos = lseek((int) rstrm->tcp_handle, (long) 0, 1);
+ if (pos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ pos += rstrm->out_finger - rstrm->out_base;
+ break;
+
+ case XDR_DECODE:
+ pos -= rstrm->in_boundry - rstrm->in_finger;
+ break;
+
+ default:
+ pos = (u_int) - 1;
+ break;
+ }
+ return ((u_int) pos);
+}
+
+static bool_t xdrrec_setpos(xdrs, pos)
+register XDR *xdrs;
+u_int pos;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ u_int currpos = xdrrec_getpos(xdrs);
+ int delta = currpos - pos;
+ caddr_t newpos;
+
+ if ((int) currpos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ newpos = rstrm->out_finger - delta;
+ if ((newpos > (caddr_t) (rstrm->frag_header)) &&
+ (newpos < rstrm->out_boundry)) {
+ rstrm->out_finger = newpos;
+ return (TRUE);
+ }
+ break;
+
+ case XDR_DECODE:
+ newpos = rstrm->in_finger - delta;
+ if ((delta < (int) (rstrm->fbtbc)) &&
+ (newpos <= rstrm->in_boundry) &&
+ (newpos >= rstrm->in_base)) {
+ rstrm->in_finger = newpos;
+ rstrm->fbtbc -= delta;
+ return (TRUE);
+ }
+ break;
+ }
+ return (FALSE);
+}
+
+static int32_t *xdrrec_inline(xdrs, len)
+register XDR *xdrs;
+int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+ int32_t *buf = NULL;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
+ buf = (int32_t *) rstrm->out_finger;
+ rstrm->out_finger += len;
+ }
+ break;
+
+ case XDR_DECODE:
+ if ((len <= rstrm->fbtbc) &&
+ ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
+ buf = (int32_t *) rstrm->in_finger;
+ rstrm->fbtbc -= len;
+ rstrm->in_finger += len;
+ }
+ break;
+ }
+ return (buf);
+}
+
+static void xdrrec_destroy(xdrs)
+register XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
+
+ mem_free(rstrm->the_buffer,
+ rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
+ mem_free((caddr_t) rstrm, sizeof(RECSTREAM));
+}
+
+
+/*
+ * Exported routines to manage xdr records
+ */
+
+/*
+ * Before reading (deserializing from the stream, one should always call
+ * this procedure to guarantee proper record alignment.
+ */
+bool_t xdrrec_skiprecord(xdrs)
+XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (!rstrm->last_frag)) {
+ if (!skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (FALSE);
+ rstrm->fbtbc = 0;
+ if ((!rstrm->last_frag) && (!set_input_fragment(rstrm)))
+ return (FALSE);
+ }
+ rstrm->last_frag = FALSE;
+ return (TRUE);
+}
+
+/*
+ * Look ahead fuction.
+ * Returns TRUE iff there is no more input in the buffer
+ * after consuming the rest of the current record.
+ */
+bool_t xdrrec_eof(xdrs)
+XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (!rstrm->last_frag)) {
+ if (!skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (TRUE);
+ rstrm->fbtbc = 0;
+ if ((!rstrm->last_frag) && (!set_input_fragment(rstrm)))
+ return (TRUE);
+ }
+ if (rstrm->in_finger == rstrm->in_boundry)
+ return (TRUE);
+ return (FALSE);
+}
+
+/*
+ * The client must tell the package when an end-of-record has occurred.
+ * The second paraemters tells whether the record should be flushed to the
+ * (output) tcp stream. (This let's the package support batched or
+ * pipelined procedure calls.) TRUE => immmediate flush to tcp connection.
+ */
+bool_t xdrrec_endofrecord(xdrs, sendnow)
+XDR *xdrs;
+bool_t sendnow;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
+ register u_long len; /* fragment length */
+
+ if (sendnow || rstrm->frag_sent ||
+ ((u_long) rstrm->out_finger + sizeof(u_long) >=
+ (u_long) rstrm->out_boundry)) {
+ rstrm->frag_sent = FALSE;
+ return (flush_out(rstrm, TRUE));
+ }
+ len = (u_long) (rstrm->out_finger) - (u_long) (rstrm->frag_header) -
+ sizeof(u_long);
+ *(rstrm->frag_header) = htonl((u_long) len | LAST_FRAG);
+ rstrm->frag_header = (u_long *) rstrm->out_finger;
+ rstrm->out_finger += sizeof(u_long);
+ return (TRUE);
+}
+
+
diff --git a/mdk-stage1/dietlibc/librpc/xdr_reference.c b/mdk-stage1/dietlibc/librpc/xdr_reference.c
new file mode 100644
index 000000000..7715d821c
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_reference.c
@@ -0,0 +1,130 @@
+/* @(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)xdr_reference.c 1.11 87/08/11 SMI";
+#endif
+
+/*
+ * xdr_reference.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * "pointers". See xdr.h for more info on the interface to xdr.
+ */
+
+#include <stdio.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <string.h>
+
+#define LASTUNSIGNED ((u_int)0-1)
+
+/*
+ * XDR an indirect pointer
+ * xdr_reference is for recursively translating a structure that is
+ * referenced by a pointer inside the structure that is currently being
+ * translated. pp references a pointer to storage. If *pp is null
+ * the necessary storage is allocated.
+ * size is the sizeof the referneced structure.
+ * proc is the routine to handle the referenced structure.
+ */
+bool_t xdr_reference(xdrs, pp, size, proc)
+register XDR *xdrs;
+caddr_t *pp; /* the pointer to work on */
+u_int size; /* size of the object pointed to */
+xdrproc_t proc; /* xdr routine to handle the object */
+{
+ register caddr_t loc = *pp;
+ register bool_t stat;
+
+ if (loc == NULL)
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ return (TRUE);
+
+ case XDR_DECODE:
+ *pp = loc = (caddr_t) mem_alloc(size);
+ if (loc == NULL) {
+ (void) fprintf(stderr, "xdr_reference: out of memory\n");
+ return (FALSE);
+ }
+ bzero(loc, (int) size);
+ break;
+ }
+
+ stat = (*proc) (xdrs, loc, LASTUNSIGNED);
+
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(loc, size);
+ *pp = NULL;
+ }
+ return (stat);
+}
+
+
+/*
+ * xdr_pointer():
+ *
+ * XDR a pointer to a possibly recursive data structure. This
+ * differs with xdr_reference in that it can serialize/deserialiaze
+ * trees correctly.
+ *
+ * What's sent is actually a union:
+ *
+ * union object_pointer switch (boolean b) {
+ * case TRUE: object_data data;
+ * case FALSE: void nothing;
+ * }
+ *
+ * > objpp: Pointer to the pointer to the object.
+ * > obj_size: size of the object.
+ * > xdr_obj: routine to XDR an object.
+ *
+ */
+bool_t xdr_pointer(xdrs, objpp, obj_size, xdr_obj)
+register XDR *xdrs;
+char **objpp;
+u_int obj_size;
+xdrproc_t xdr_obj;
+{
+
+ bool_t more_data;
+
+ more_data = (*objpp != NULL);
+ if (!xdr_bool(xdrs, &more_data)) {
+ return (FALSE);
+ }
+ if (!more_data) {
+ *objpp = NULL;
+ return (TRUE);
+ }
+ return (xdr_reference(xdrs, objpp, obj_size, xdr_obj));
+}
diff --git a/mdk-stage1/dietlibc/librpc/xdr_stdio.c b/mdk-stage1/dietlibc/librpc/xdr_stdio.c
new file mode 100644
index 000000000..e3190e0a9
--- /dev/null
+++ b/mdk-stage1/dietlibc/librpc/xdr_stdio.c
@@ -0,0 +1,187 @@
+/* @(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC */
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] =
+
+ "@(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * xdr_stdio.c, XDR implementation on standard i/o file.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements a XDR on a stdio stream.
+ * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
+ * from the stream.
+ */
+
+#include <rpc/types.h>
+#include <stdio.h>
+#include <rpc/xdr.h>
+
+static bool_t xdrstdio_getlong();
+static bool_t xdrstdio_putlong();
+static bool_t xdrstdio_getbytes();
+static bool_t xdrstdio_putbytes();
+static u_int xdrstdio_getpos();
+static bool_t xdrstdio_setpos();
+static int32_t *xdrstdio_inline();
+static void xdrstdio_destroy();
+
+/*
+ * Ops vector for stdio type XDR
+ */
+static struct xdr_ops xdrstdio_ops = {
+ xdrstdio_getlong, /* deseraialize a long int */
+ xdrstdio_putlong, /* seraialize a long int */
+ xdrstdio_getbytes, /* deserialize counted bytes */
+ xdrstdio_putbytes, /* serialize counted bytes */
+ xdrstdio_getpos, /* get offset in the stream */
+ xdrstdio_setpos, /* set offset in the stream */
+ xdrstdio_inline, /* prime stream for inline macros */
+ xdrstdio_destroy /* destroy stream */
+};
+
+/*
+ * Initialize a stdio xdr stream.
+ * Sets the xdr stream handle xdrs for use on the stream file.
+ * Operation flag is set to op.
+ */
+void xdrstdio_create(xdrs, file, op)
+register XDR *xdrs;
+FILE *file;
+enum xdr_op op;
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrstdio_ops;
+ xdrs->x_private = (caddr_t) file;
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+}
+
+/*
+ * Destroy a stdio xdr stream.
+ * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
+ */
+static void xdrstdio_destroy(xdrs)
+register XDR *xdrs;
+{
+ (void) fflush((FILE *) xdrs->x_private);
+ /* xx should we close the file ?? */
+};
+
+static bool_t xdrstdio_getlong(xdrs, lp)
+XDR *xdrs;
+register long *lp;
+{
+
+ if (fread((caddr_t) lp, sizeof(long), 1, (FILE *) xdrs->x_private) !=
+ 1) return (FALSE);
+
+#ifndef mc68000
+ *lp = ntohl(*lp);
+#endif
+ return (TRUE);
+}
+
+static bool_t xdrstdio_putlong(xdrs, lp)
+XDR *xdrs;
+long *lp;
+{
+
+#ifndef mc68000
+ long mycopy = htonl(*lp);
+
+ lp = &mycopy;
+#endif
+ if (fwrite((caddr_t) lp, sizeof(long), 1, (FILE *) xdrs->x_private) !=
+ 1) return (FALSE);
+
+ return (TRUE);
+}
+
+static bool_t xdrstdio_getbytes(xdrs, addr, len)
+XDR *xdrs;
+caddr_t addr;
+u_int len;
+{
+
+ if ((len != 0)
+ && (fread(addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t xdrstdio_putbytes(xdrs, addr, len)
+XDR *xdrs;
+caddr_t addr;
+u_int len;
+{
+
+ if ((len != 0)
+ && (fwrite(addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static u_int xdrstdio_getpos(xdrs)
+XDR *xdrs;
+{
+
+ return ((u_int) ftell((FILE *) xdrs->x_private));
+}
+
+static bool_t xdrstdio_setpos(xdrs, pos)
+XDR *xdrs;
+u_int pos;
+{
+
+ return ((fseek((FILE *) xdrs->x_private, (long) pos, 0) < 0) ?
+ FALSE : TRUE);
+}
+
+static int32_t *xdrstdio_inline(xdrs, len)
+XDR *xdrs;
+u_int len;
+{
+
+ /*
+ * Must do some work to implement this: must insure
+ * enough data in the underlying stdio buffer,
+ * that the buffer is aligned so that we can indirect through a
+ * long *, and stuff this pointer in xdrs->x_buf. Doing
+ * a fread or fwrite to a scratch buffer would defeat
+ * most of the gains to be had here and require storage
+ * management on this buffer, so we don't do this.
+ */
+ return (NULL);
+}
diff --git a/mdk-stage1/dietlibc/libshell/fnmatch.c b/mdk-stage1/dietlibc/libshell/fnmatch.c
new file mode 100644
index 000000000..4e7664510
--- /dev/null
+++ b/mdk-stage1/dietlibc/libshell/fnmatch.c
@@ -0,0 +1,74 @@
+#include <ctype.h>
+#include <fnmatch.h>
+
+#define NOTFIRST 128
+
+static int match(char c,char d,int flags) {
+ if (flags&FNM_CASEFOLD)
+ return (tolower(c)==tolower(d));
+ else
+ return (c==d);
+}
+
+int fnmatch(const char *pattern, const char *string, int flags) {
+ if (*string==0) {
+ while (*pattern=='*') ++pattern;
+ return (!!*pattern);
+ }
+ if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) {
+ /* don't match if FNM_PERIOD and this is the first char */
+ if ((flags&FNM_PERIOD) && (!(flags&NOTFIRST)))
+ return 1;
+ /* don't match if FNM_PERIOD and FNM_FILE_NAME and previous was '/' */
+ if ((flags&(FNM_FILE_NAME|FNM_PERIOD)) && string[-1]=='/')
+ return 1;
+ }
+ flags|=NOTFIRST;
+ switch (*pattern) {
+ case '[':
+ ++pattern;
+ while (*pattern && *pattern!=']') {
+ if (flags&FNM_PATHNAME || *string!='/') {
+ int res=0;
+ if (pattern[1]=='-') {
+ if (*string>=*pattern && *string<=pattern[2]) res=1;
+ if (flags&FNM_CASEFOLD) {
+ if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1;
+ }
+ } else
+ res=match(*pattern,*string,flags);
+ if (res) {
+ while (*pattern && *pattern!=']') ++pattern;
+ return fnmatch(pattern+1,string+1,flags);
+ }
+ }
+ ++pattern;
+ }
+ break;
+ case '\\':
+ if (flags&FNM_NOESCAPE) {
+ if (*string=='\\')
+ return fnmatch(pattern+1,string+1,flags);
+ } else {
+ if (*string==pattern[1])
+ return fnmatch(pattern+2,string+1,flags);
+ }
+ break;
+ case '*':
+ if (!pattern[1] || fnmatch(pattern+1,string,flags)==0)
+ return 0;
+ else
+ if (*string!='/')
+ return fnmatch(pattern,string+1,flags);
+ break;
+ case 0:
+ if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR)))
+ return 0;
+ break;
+ default:
+ if (match(*pattern,*string,flags))
+ return fnmatch(pattern+1,string+1,flags);
+ break;
+ }
+ return 1;
+}
diff --git a/mdk-stage1/dietlibc/libshell/glob.c b/mdk-stage1/dietlibc/libshell/glob.c
new file mode 100644
index 000000000..3d8c6d52f
--- /dev/null
+++ b/mdk-stage1/dietlibc/libshell/glob.c
@@ -0,0 +1,356 @@
+/*
+ * dietlibc/libshell/glob.c
+ *
+ * Copyright 2001 Guillaume Cottenceau <gc@mandrakesoft.com>
+ *
+ * This is free software, licensed under the Gnu General Public License.
+ *
+ */
+
+/*
+ * unsupported: GLOB_BRACE GLOB_ALTDIRFUNC GLOB_MAGCHAR
+ */
+
+#define DEBUG(x)
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <fnmatch.h>
+#include <dirent.h>
+#include <pwd.h>
+
+#include <glob.h>
+
+
+
+/* If i18n, should be using strcoll */
+static int cmp_func(const void * a, const void * b)
+{
+ const char *const s1 = *(const char *const * const) a;
+ const char *const s2 = *(const char *const * const) b;
+ if (s1 == NULL)
+ return 1;
+ if (s2 == NULL)
+ return -1;
+ return strcmp(s1, s2);
+}
+
+
+/* Like `glob', but PATTERN is a final pathname component,
+ and matches are searched for in DIRECTORY.
+ The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done.
+ The GLOB_APPEND flag is assumed to be set (always appends).
+ Prepends DIRECTORY in constructed PGLOB. */
+static int glob_in_dir(const char *pattern, const char *directory, int flags,
+ int errfunc(const char * epath, int eerrno),
+ glob_t *pglob)
+{
+ DIR *dp = opendir(directory);
+ int nfound = 0;
+
+ int i;
+ char * ptr;
+
+ void close_dir_keep_errno(void) {
+ int save = errno;
+ if (dp)
+ closedir (dp);
+ __set_errno(save);
+ }
+ int add_entry(const char * name) {
+ pglob->gl_pathv = (char **) realloc(pglob->gl_pathv,
+ (pglob->gl_pathc + pglob->gl_offs + 2)
+ * sizeof (char *));
+ if (pglob->gl_pathv == NULL)
+ return 1;
+ pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = strdup(name);
+ pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL;
+ pglob->gl_pathc++;
+ nfound++;
+ return 0;
+ }
+ void build_fullname(char * fullname, int fullnamesize, const char * directory, const char * filename) {
+ if (!strcmp(directory, "/"))
+ snprintf(fullname, fullnamesize, "/%s", filename);
+ else if (!strcmp(directory, "."))
+ snprintf(fullname, fullnamesize, "%s", filename);
+ else
+ snprintf(fullname, fullnamesize, "%s/%s", directory, filename);
+ }
+
+ if (!dp) {
+ if (errno != ENOTDIR
+ && ((errfunc != NULL && (*errfunc) (directory, errno))
+ || (flags & GLOB_ERR)))
+ return GLOB_ABORTED;
+ } else {
+ int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
+ | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0));
+ struct dirent *ep;
+ while ((ep = readdir(dp))) {
+ i = strlen(directory) + strlen(ep->d_name) + 2;
+ ptr = (char *) alloca(i);
+ build_fullname(ptr, i, directory, ep->d_name);
+ if (flags & GLOB_ONLYDIR) {
+ struct stat statr;
+ if (stat(ptr, &statr) || !S_ISDIR(statr.st_mode))
+ continue;
+ }
+ if (fnmatch(pattern, ep->d_name, fnm_flags) == 0)
+ if (add_entry(ptr))
+ goto memory_error;
+ }
+ }
+
+ close_dir_keep_errno();
+
+ if (nfound != 0)
+ pglob->gl_flags = flags;
+ else if (flags & GLOB_NOCHECK) {
+ /* nfound == 0 */
+ i = strlen(directory) + strlen(pattern) + 2;
+ ptr = (char *) alloca(i);
+ build_fullname(ptr, i, directory, pattern);
+ if (add_entry(ptr))
+ goto memory_error;
+ }
+
+ return (nfound == 0) ? GLOB_NOMATCH : 0;
+
+ memory_error:
+ /* We're in trouble since we can't free the already allocated memory. [allocated from strdup(filame)]
+ * Well, after all, when malloc returns NULL we're already in a bad mood, and no doubt the
+ * program will manage to segfault by itself very soon :-). */
+ close_dir_keep_errno();
+ return GLOB_NOSPACE;
+}
+
+
+
+int glob(const char *pattern, int flags, int errfunc(const char * epath, int eerrno), glob_t *pglob)
+{
+ char * pattern_;
+ char * filename;
+ char * dirname;
+ size_t oldcount;
+ struct stat statr;
+
+ size_t i; /* tmp variables are declared here to save a bit of object space */
+ int j, k; /* */
+ char * ptr, * ptr2;
+
+ if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (!(flags & GLOB_DOOFFS))
+ pglob->gl_offs = 0;
+
+
+ /* Duplicate pattern so I can make modif to it later (to handle
+ TILDE stuff replacing old contents, and to null-terminate the
+ directory) */
+ pattern_ = alloca(strlen(pattern) + 1);
+ strcpy(pattern_, pattern);
+
+ /* Check for TILDE stuff */
+ if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern_[0] == '~') {
+ char * home_dir = NULL;
+ if (pattern_[1] == '\0' || pattern_[1] == '/') {
+ /* She's asking for ~, her homedir */
+ home_dir = getenv("HOME");
+ } else {
+ /* She's asking for another one's homedir */
+ struct passwd * p;
+ ptr2 = alloca(strlen(pattern_) + 1);
+ strcpy(ptr2, pattern_ + 1);
+ ptr = strchr(ptr2, '/');
+ if (ptr != NULL)
+ *ptr = '\0';
+ setpwent();
+ while (((p = getpwent()) != NULL)) {
+ if (!strcmp(p->pw_name, ptr2)) {
+ home_dir = p->pw_dir;
+ break;
+ }
+ }
+ entpwent();
+ }
+ if (home_dir != NULL) {
+ i = strlen(home_dir) + strlen(pattern_); /* pessimistic (the ~ case) */
+ ptr = alloca(i);
+ strncpy(ptr, home_dir, i);
+ ptr2 = pattern_ + 1;
+ while (*ptr2 != '/' && *ptr2 != '\0')
+ ptr2++;
+ strncat(ptr, ptr2, i);
+ pattern_ = ptr;
+ } else if (flags & GLOB_TILDE_CHECK)
+ return GLOB_NOMATCH;
+ }
+
+ /* Find the filename */
+ filename = strrchr(pattern_, '/');
+
+ if (filename == NULL) {
+ /* We have no '/' in the pattern */
+ filename = pattern_;
+ dirname = ".";
+ } else if (filename == pattern_) {
+ /* "/pattern". */
+ dirname = "/";
+ filename++;
+ } else {
+ dirname = pattern_;
+ filename++;
+ /* allow dirname to be null terminated */
+ *(filename-1) = '\0';
+
+ if (filename[0] == '\0' && strcmp(pattern_, "/")) {
+ /* "pattern/". Expand "pattern", appending slashes. */
+ j = glob(dirname, flags | GLOB_MARK, errfunc, pglob);
+ if (j == 0)
+ pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK)
+ | (flags & GLOB_MARK));
+ return j;
+ }
+ }
+
+
+ /* Reserve memory for pglob */
+ if (!(flags & GLOB_APPEND)) {
+ pglob->gl_pathc = 0;
+ if (!(flags & GLOB_DOOFFS))
+ pglob->gl_pathv = NULL;
+ else {
+ pglob->gl_pathv = (char **) malloc((pglob->gl_offs + 1) * sizeof (char *));
+ if (pglob->gl_pathv == NULL)
+ return GLOB_NOSPACE;
+ for (i = 0; i <= pglob->gl_offs; i++)
+ pglob->gl_pathv[i] = NULL;
+ }
+ }
+
+
+ oldcount = pglob->gl_pathc + pglob->gl_offs;
+
+
+ /* Begin real work */
+ if (!strcmp(dirname, "/") || !strcmp(dirname, ".")
+ || (!strchr(dirname, '*') && !strchr(dirname, '?') && !strchr(dirname, '['))) {
+ /* Approx of a terminal state, glob directly in dir. */
+ j = glob_in_dir(filename, dirname, flags, errfunc, pglob);
+ if (j != 0)
+ return j;
+ } else {
+ /* We are not in a terminal state, so we have to glob for
+ the directory, and then glob for the pattern in each
+ directory found. */
+ glob_t dirs;
+
+ j = glob(dirname, ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ALTDIRFUNC))
+ | GLOB_NOSORT | GLOB_ONLYDIR),
+ errfunc, &dirs);
+ if (j != 0)
+ return j;
+
+ /* We have successfully globbed the directory name.
+ For each name we found, call glob_in_dir on it and FILENAME,
+ appending the results to PGLOB. */
+ for (i = 0; i < dirs.gl_pathc; i++) {
+ j = glob_in_dir(filename, dirs.gl_pathv[i], ((flags | GLOB_APPEND) & ~GLOB_NOCHECK),
+ errfunc, pglob);
+ if (j == GLOB_NOMATCH)
+ /* No matches in this directory. Try the next. */
+ continue;
+ if (j != 0) {
+ globfree(&dirs);
+ globfree(pglob);
+ return j;
+ }
+ }
+
+ /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
+ But if we have not found any matching entry and the GLOB_NOCHECK
+ flag was set we must return the list consisting of the disrectory
+ names followed by the filename. */
+ if (pglob->gl_pathc + pglob->gl_offs == oldcount)
+ {
+ /* No matches. */
+ if (flags & GLOB_NOCHECK)
+ {
+ for (i = 0; i < dirs.gl_pathc; i++) {
+ if (stat(dirs.gl_pathv[i], &statr) || !S_ISDIR(statr.st_mode))
+ continue;
+
+ /* stat is okay, we will add the entry, but before let's resize the pathv */
+ j = pglob->gl_pathc + pglob->gl_offs;
+ pglob->gl_pathv = (char **) realloc(pglob->gl_pathv, (j + 2) * sizeof (char *));
+ if (pglob->gl_pathv == NULL) {
+ globfree (&dirs);
+ return GLOB_NOSPACE;
+ }
+
+ /* okay now we add the new entry */
+ k = strlen(dirs.gl_pathv[i]) + 1 + strlen(filename) + 1;
+ if ((pglob->gl_pathv[j] = malloc(k)) == NULL) {
+ globfree(&dirs);
+ globfree(pglob);
+ return GLOB_NOSPACE;
+ }
+ snprintf(pglob->gl_pathv[j], k, "%s/%s", dirs.gl_pathv[i], filename);
+ pglob->gl_pathc++;
+ pglob->gl_pathv[j+1] = NULL;
+ }
+ } else {
+ globfree(&dirs);
+ return GLOB_NOMATCH;
+ }
+ }
+
+ globfree (&dirs);
+ }
+
+
+ if (flags & GLOB_MARK) {
+ for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; i++)
+ if (!stat(pglob->gl_pathv[i], &statr) && S_ISDIR(statr.st_mode)) {
+ size_t len = strlen(pglob->gl_pathv[i]) + 2;
+ ptr = realloc(pglob->gl_pathv[i], len);
+ if (ptr == NULL) {
+ globfree(pglob);
+ return GLOB_NOSPACE;
+ }
+ strcpy(&ptr[len - 2], "/");
+ pglob->gl_pathv[i] = ptr;
+ }
+ }
+
+ if (!(flags & GLOB_NOSORT)) {
+ qsort(&pglob->gl_pathv[oldcount],
+ pglob->gl_pathc + pglob->gl_offs - oldcount,
+ sizeof(char *), cmp_func);
+ }
+
+ return 0;
+}
+
+
+/* Free storage allocated in PGLOB by a previous `glob' call. */
+void globfree (glob_t * pglob)
+{
+ if (pglob->gl_pathv != NULL) {
+ size_t i;
+ for (i = 0; i < pglob->gl_pathc; i++)
+ if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
+ free((void *) pglob->gl_pathv[pglob->gl_offs + i]);
+ free((void *) pglob->gl_pathv);
+ }
+}
diff --git a/mdk-stage1/dietlibc/libshell/realpath.c b/mdk-stage1/dietlibc/libshell/realpath.c
new file mode 100644
index 000000000..1377018e5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libshell/realpath.c
@@ -0,0 +1,31 @@
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include "dietfeatures.h"
+
+char *realpath(const char *path, char *resolved_path) {
+ int fd=open(".",O_RDONLY);
+ char *tmp="";
+ if (chdir(path)) {
+#ifdef WANT_THREAD_SAFE
+ if (*__errno_location()==ENOTDIR)
+#else
+ if (errno==ENOTDIR)
+#endif
+ {
+ if ((tmp=strrchr(path,'/'))) {
+ memmove(resolved_path,path,tmp-path);
+ resolved_path[tmp-path]=0;
+ if (chdir(resolved_path)) { resolved_path=0; goto abort; }
+ }
+ }
+ }
+ if (!getcwd(resolved_path,PATH_MAX)) { resolved_path=0; goto abort; }
+ strcat(resolved_path,tmp);
+abort:
+ fchdir(fd);
+ close(fd);
+ return resolved_path;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/clearerr.c b/mdk-stage1/dietlibc/libstdio/clearerr.c
new file mode 100644
index 000000000..8bde8c702
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/clearerr.c
@@ -0,0 +1,5 @@
+#include "dietstdio.h"
+
+void clearerr( FILE *stream) {
+ stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fclose.c b/mdk-stage1/dietlibc/libstdio/fclose.c
new file mode 100644
index 000000000..6958a48e7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fclose.c
@@ -0,0 +1,24 @@
+#include "dietstdio.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+int fclose(FILE *stream) {
+ int res;
+#ifdef WANT_BUFFERED_STDIO
+ FILE *f,*fl;
+#endif
+ fflush(stream);
+ res=close(stream->fd);
+#ifdef WANT_BUFFERED_STDIO
+ for (fl=0,f=__stdio_root; f; fl=f,f=f->next)
+ if (f==stream) {
+ if (fl)
+ fl->next=f->next;
+ else
+ __stdio_root=f->next;
+ break;
+ }
+#endif
+ free(stream);
+ return res;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fdglue.c b/mdk-stage1/dietlibc/libstdio/fdglue.c
new file mode 100644
index 000000000..eeedd513d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fdglue.c
@@ -0,0 +1,49 @@
+#include "dietstdio.h"
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#ifdef WANT_BUFFERED_STDIO
+extern int __stdio_atexit;
+extern void __stdio_flushall();
+#endif
+
+int __stdio_parse_mode(const char *mode) {
+ int f=0;
+ for (;;) {
+ switch (*mode) {
+ case 0: return f;
+ case 'b': break;
+ case 'r': f=O_RDONLY; break;
+ case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
+ case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
+ case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
+ }
+ ++mode;
+ }
+}
+
+FILE* __stdio_init_file(int fd) {
+ FILE *tmp=(FILE*)malloc(sizeof(FILE));
+ if (!tmp) {
+ close(fd);
+ errno=ENOMEM;
+ return 0;
+ }
+ tmp->fd=fd;
+#ifdef WANT_BUFFERED_STDIO
+ tmp->bm=0;
+ tmp->bs=0;
+#endif
+ tmp->flags=0;
+#ifdef WANT_BUFFERED_STDIO
+ if (__stdio_atexit==0) {
+ __stdio_atexit=1;
+ atexit(__stdio_flushall);
+ }
+ tmp->next=__stdio_root;
+ __stdio_root=tmp;
+#endif
+ return tmp;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fdopen.c b/mdk-stage1/dietlibc/libstdio/fdopen.c
new file mode 100644
index 000000000..aee14fb0c
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fdopen.c
@@ -0,0 +1,21 @@
+#include <sys/types.h>
+#include <dietstdio.h>
+#include <unistd.h>
+
+#define SEEK_END 2
+
+int __stdio_parse_mode(const char *mode);
+FILE* __stdio_init_file(int fd);
+
+FILE *fdopen (int filedes, const char *mode) {
+ int f=0; /* O_RDONLY, O_WRONLY or O_RDWR */
+ int fd;
+
+ f=__stdio_parse_mode(mode);
+ if ((fd=filedes)<0) return 0;
+ {
+ FILE * ret = __stdio_init_file(fd);
+ ret->flags |= UNSEEKABLE;
+ return ret;
+ }
+}
diff --git a/mdk-stage1/dietlibc/libstdio/feof.c b/mdk-stage1/dietlibc/libstdio/feof.c
new file mode 100644
index 000000000..b7e86fe3b
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/feof.c
@@ -0,0 +1,9 @@
+#include <dietstdio.h>
+
+int feof(FILE *stream) {
+#ifdef WANT_UNGETC
+ /* yuck!!! */
+ if (stream->ungotten) return 0;
+#endif
+ return (stream->flags&EOFINDICATOR);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/ferror.c b/mdk-stage1/dietlibc/libstdio/ferror.c
new file mode 100644
index 000000000..e86873be0
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/ferror.c
@@ -0,0 +1,5 @@
+#include <dietstdio.h>
+
+int ferror(FILE *stream) {
+ return (stream->flags&ERRORINDICATOR);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fflush.c b/mdk-stage1/dietlibc/libstdio/fflush.c
new file mode 100644
index 000000000..7078e04f4
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fflush.c
@@ -0,0 +1,62 @@
+#include "dietstdio.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include "dietwarning.h"
+
+FILE *__stdio_root;
+
+#ifdef WANT_BUFFERED_STDIO
+int __stdio_atexit=0;
+
+void __stdio_flushall() {
+ fflush(0);
+}
+
+extern int __fflush_stdin();
+extern int __fflush_stdout();
+extern int __fflush_stderr();
+
+int fflush(FILE *stream) {
+ if (stream==0) {
+ int res;
+ FILE *f;
+ __fflush_stdin();
+ __fflush_stdout();
+ __fflush_stderr();
+ for (res=0, f=__stdio_root; f; f=f->next)
+ if (fflush(f))
+ res=-1;
+ return res;
+ }
+ if (stream->flags&BUFINPUT) {
+ register int tmp;
+ if ((tmp=stream->bm-stream->bs)) lseek(stream->fd,tmp,SEEK_CUR);
+ } else
+ if (stream->bm && write(stream->fd,stream->buf,stream->bm)!=stream->bm) {
+ stream->flags|=ERRORINDICATOR;
+ return -1;
+ }
+ stream->bm=0;
+ return 0;
+}
+
+int __fflush4(FILE *stream,int next) {
+ if (!__stdio_atexit) {
+ __stdio_atexit=1;
+ atexit(__stdio_flushall);
+ }
+ if ((stream->flags&BUFINPUT)!=next) {
+ int res=fflush(stream);
+ stream->flags=(stream->flags&~BUFINPUT)|next;
+ return res;
+ }
+ return 0;
+}
+
+#else
+int fflush(FILE *stream) {
+ return 0;
+}
+#endif
+
+link_warning("fflush","warning: your code uses stdio (several kilobytes of bloat).")
diff --git a/mdk-stage1/dietlibc/libstdio/fgetc.c b/mdk-stage1/dietlibc/libstdio/fgetc.c
new file mode 100644
index 000000000..90d83961a
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fgetc.c
@@ -0,0 +1,40 @@
+#include "dietstdio.h"
+#include <unistd.h>
+
+extern int feof(FILE *stream);
+
+int fgetc(FILE *stream) {
+ unsigned char c;
+#ifdef WANT_UNGETC
+ if (stream->ungotten) {
+ stream->ungotten=0;
+ return stream->ungetbuf;
+ }
+#endif
+ if (feof(stream))
+ return EOF;
+#ifdef WANT_BUFFERED_STDIO
+ if (__fflush4(stream,BUFINPUT)) return EOF;
+ if (stream->bm>=stream->bs) {
+ int len=read(stream->fd,stream->buf,BUFSIZE);
+ if (len==0) {
+ stream->flags|=EOFINDICATOR;
+ return EOF;
+ } else if (len<0) {
+ stream->flags|=ERRORINDICATOR;
+ return EOF;
+ }
+ stream->bm=0;
+ stream->bs=len;
+ }
+ c=stream->buf[stream->bm];
+ ++stream->bm;
+ return c;
+#else
+ if (read(stream->fd,&c,1)!=1) {
+ stream->flags|=ERRORINDICATOR;
+ return EOF;
+ }
+ return c;
+#endif
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fgets.c b/mdk-stage1/dietlibc/libstdio/fgets.c
new file mode 100644
index 000000000..c613d452d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fgets.c
@@ -0,0 +1,20 @@
+#include "dietstdio.h"
+
+extern int ferror(FILE *stream);
+
+char *fgets(char *s, int size, FILE *stream) {
+ char *orig=s;
+ int l;
+ for (l=size; l>0;) {
+ int c=fgetc(stream);
+ if (c==EOF) break;
+ *s=c;
+ ++s;
+ --l;
+ if (c=='\n') break;
+ }
+ if (l==size || ferror(stream))
+ return 0;
+ *s=0;
+ return orig;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fileno.c b/mdk-stage1/dietlibc/libstdio/fileno.c
new file mode 100644
index 000000000..f021d3881
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fileno.c
@@ -0,0 +1,5 @@
+#include <dietstdio.h>
+
+int fileno(FILE *stream) {
+ return stream->fd;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fopen.c b/mdk-stage1/dietlibc/libstdio/fopen.c
new file mode 100644
index 000000000..aac17be42
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fopen.c
@@ -0,0 +1,21 @@
+#include <sys/types.h>
+#include <dietstdio.h>
+#include <unistd.h>
+
+#define SEEK_END 2
+
+extern int __stdio_atexit;
+extern void __stdio_flushall();
+
+extern int __stdio_parse_mode(const char *mode);
+extern FILE* __stdio_init_file(int fd);
+
+FILE *fopen (const char *path, const char *mode) {
+ int f=0; /* O_RDONLY, O_WRONLY or O_RDWR */
+ int fd;
+
+ f=__stdio_parse_mode(mode);
+ if ((fd=open(path,f,0666))<0)
+ return 0;
+ return __stdio_init_file(fd);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fprintf.c b/mdk-stage1/dietlibc/libstdio/fprintf.c
new file mode 100644
index 000000000..237fd1e51
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fprintf.c
@@ -0,0 +1,23 @@
+#include <stdarg.h>
+#include <linux/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+extern int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr);
+
+int fprintf(FILE *f,const char *format,...) {
+ int n;
+ char *printf_buf;
+/* char printf_buf[1024]; */
+ va_list arg_ptr;
+ va_start(arg_ptr, format);
+ n=vsnprintf(0,1000000,format,arg_ptr);
+/* write(1,printf_buf,strlen(printf_buf)); */
+ va_end (arg_ptr);
+ va_start (arg_ptr, format);
+ printf_buf=alloca(n+2);
+ n=vsnprintf(printf_buf,n+1,format,arg_ptr);
+ va_end (arg_ptr);
+ fwrite(printf_buf,n,1,f);
+ return n;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fputc.c b/mdk-stage1/dietlibc/libstdio/fputc.c
new file mode 100644
index 000000000..b816f7c4d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fputc.c
@@ -0,0 +1,19 @@
+#include <dietstdio.h>
+#ifndef WANT_BUFFERED_STDIO
+#include <unistd.h>
+#endif
+
+int fputc(int c, FILE *stream) {
+#ifdef WANT_BUFFERED_STDIO
+ if (__fflush4(stream,0)) return EOF;
+ if (stream->bm>=BUFSIZE-1)
+ if (fflush(stream)) return EOF;
+ stream->buf[stream->bm]=c;
+ ++stream->bm;
+ if ((stream->flags&BUFLINEWISE) && c=='\n') /* puke */
+ if (fflush(stream)) return EOF;
+#else
+ write(stream->fd,&c,1);
+#endif
+ return 0;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fputs.c b/mdk-stage1/dietlibc/libstdio/fputs.c
new file mode 100644
index 000000000..51ee9a96e
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fputs.c
@@ -0,0 +1,6 @@
+#include "dietstdio.h"
+#include <string.h>
+
+int fputs(const char *s, FILE *stream) {
+ return fwrite(s,strlen(s),1,stream);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fread.c b/mdk-stage1/dietlibc/libstdio/fread.c
new file mode 100644
index 000000000..29afa1489
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fread.c
@@ -0,0 +1,51 @@
+#include <sys/types.h>
+#include "dietstdio.h"
+#include <unistd.h>
+
+size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ int res;
+#ifdef WANT_BUFFERED_STDIO
+ unsigned long i,j;
+ j=size*nmemb;
+#ifdef WANT_UNGETC
+ if (stream->ungotten) {
+ *(char*)ptr=stream->ungetbuf;
+ ptr=((char*)ptr)+1;
+ --j;
+ }
+ if (!j) return 1;
+#endif
+ for (i=0; i<j; ++i) {
+ res=fgetc(stream);
+ if (res==EOF)
+ return i/size;
+ else
+ ((unsigned char*)ptr)[i]=(unsigned char)res;
+ }
+ return nmemb;
+#else
+#ifdef WANT_UNGETC
+ unsigned long j=size*nmemb;
+#endif
+ fflush(stream);
+#ifdef WANT_UNGETC
+ if (stream->ungotten) {
+ *(char*)ptr=stream->ungetbuf;
+ ptr=((char*)ptr)+1;
+ --j;
+ }
+ if (!j) return 1;
+ res=read(stream->fd,ptr,j);
+#else
+ res=read(stream->fd,ptr,size*nmemb);
+#endif
+ if (res<0) {
+ stream->flags|=ERRORINDICATOR;
+ return 0;
+ } else if (res<size*nmemb)
+ if (!(stream->flags & UNSEEKABLE)
+ || ((stream->flags & UNSEEKABLE) && res == 0))
+ stream->flags|=EOFINDICATOR;
+ return res/size;
+#endif
+}
diff --git a/mdk-stage1/dietlibc/libstdio/freopen.c b/mdk-stage1/dietlibc/libstdio/freopen.c
new file mode 100644
index 000000000..8d4644a10
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/freopen.c
@@ -0,0 +1,9 @@
+#include <sys/types.h>
+#include <dietstdio.h>
+#include <unistd.h>
+
+FILE *freopen (const char *path, const char *mode, FILE *stream) {
+ fclose(stream);
+ stream=fopen(path,mode);
+ return stream;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fseek.c b/mdk-stage1/dietlibc/libstdio/fseek.c
new file mode 100644
index 000000000..5bb96bc6e
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fseek.c
@@ -0,0 +1,11 @@
+#include <dietstdio.h>
+#include <unistd.h>
+
+long fseek(FILE *stream, long offset, int whence) {
+ fflush(stream);
+#ifdef WANT_BUFFERED_STDIO
+ stream->bm=0; stream->bs=0;
+#endif
+ stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
+ return (lseek(stream->fd,offset,whence));
+}
diff --git a/mdk-stage1/dietlibc/libstdio/ftell.c b/mdk-stage1/dietlibc/libstdio/ftell.c
new file mode 100644
index 000000000..42d2c9f26
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/ftell.c
@@ -0,0 +1,7 @@
+#include <dietstdio.h>
+#include <unistd.h>
+
+long ftell(FILE *stream) {
+ fflush(stream);
+ return (lseek(stream->fd,0,SEEK_CUR));
+}
diff --git a/mdk-stage1/dietlibc/libstdio/fwrite.c b/mdk-stage1/dietlibc/libstdio/fwrite.c
new file mode 100644
index 000000000..5691661a5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/fwrite.c
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include "dietstdio.h"
+#include <unistd.h>
+
+size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ int res;
+#ifdef WANT_BUFFERED_STDIO
+ long len=size*nmemb;
+ long i;
+ if (len>BUFSIZE || (stream->flags&NOBUF)) {
+ if (!(stream->flags&NOBUF)) fflush(stream);
+ res=write(stream->fd,ptr,size*nmemb);
+ } else {
+ register const unsigned char *c=ptr;
+ for (i=size*nmemb; i>0; --i,++c)
+ if (fputc(*c,stream)) {
+ res=-1;
+ break;
+ }
+ res=size*nmemb;
+ }
+#else
+ res=write(stream->fd,ptr,size*nmemb);
+#endif
+ if (res<0) {
+ stream->flags|=ERRORINDICATOR;
+ return 0;
+ }
+ return size?res/size:0;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/printf.c b/mdk-stage1/dietlibc/libstdio/printf.c
new file mode 100644
index 000000000..571420dc3
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/printf.c
@@ -0,0 +1,29 @@
+#include <stdarg.h>
+#include <linux/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "dietstdio.h"
+
+int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr);
+
+int printf(const char *format,...)
+{
+ int n;
+ char *printf_buf;
+/* char printf_buf[1024]; */
+ va_list arg_ptr;
+ va_start(arg_ptr, format);
+ n=vsnprintf(0,1000000,format,arg_ptr);
+/* write(1,printf_buf,strlen(printf_buf)); */
+ va_end (arg_ptr);
+ va_start (arg_ptr, format);
+ printf_buf=alloca(n+2);
+ n=vsnprintf(printf_buf,n+1,format,arg_ptr);
+#ifdef WANT_BUFFERED_STDIO
+ fwrite(printf_buf,n,1,stdout);
+#else
+ write(1,printf_buf,n);
+#endif
+ va_end (arg_ptr);
+ return n;
+}
diff --git a/mdk-stage1/dietlibc/libstdio/putchar.c b/mdk-stage1/dietlibc/libstdio/putchar.c
new file mode 100644
index 000000000..7e5285a48
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/putchar.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+#undef putchar
+int putchar(int c) {
+ return fputc(c,stdout);
+}
diff --git a/mdk-stage1/dietlibc/libstdio/setvbuf.c b/mdk-stage1/dietlibc/libstdio/setvbuf.c
new file mode 100644
index 000000000..d0b1b7640
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/setvbuf.c
@@ -0,0 +1,18 @@
+#include <sys/types.h>
+#include "dietstdio.h"
+#include <unistd.h>
+#include "dietwarning.h"
+
+int setvbuf(FILE *stream, char *buf, int flags , size_t size) {
+#ifdef WANT_BUFFERED_STDIO
+ switch (flags) {
+ case _IONBF: stream->flags = (stream->flags & ~(BUFLINEWISE)) | NOBUF; break;
+ case _IOLBF: stream->flags = (stream->flags & ~(BUFLINEWISE|NOBUF)) | BUFLINEWISE; break;
+ case _IOFBF: stream->flags = stream->flags & ~(NOBUF | BUFLINEWISE); break;
+ default: return -1;
+ }
+#endif
+ return 0;
+}
+
+link_warning("setvbuf","setvbuf does not implement changing the buffer in diet libc.")
diff --git a/mdk-stage1/dietlibc/libstdio/stderr.c b/mdk-stage1/dietlibc/libstdio/stderr.c
new file mode 100644
index 000000000..a82b1b727
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/stderr.c
@@ -0,0 +1,13 @@
+#include <dietstdio.h>
+
+#ifdef WANT_BUFFERED_STDIO
+static FILE __stderr = { 2, NOBUF, 0, 0 };
+
+int __fflush_stderr() {
+ return fflush(stderr);
+}
+#else
+static FILE __stderr = { 2, 0 };
+#endif
+
+FILE *stderr=&__stderr;
diff --git a/mdk-stage1/dietlibc/libstdio/stdin.c b/mdk-stage1/dietlibc/libstdio/stdin.c
new file mode 100644
index 000000000..2db82f9ab
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/stdin.c
@@ -0,0 +1,13 @@
+#include <dietstdio.h>
+
+#ifdef WANT_BUFFERED_STDIO
+static FILE __stdin = { 0, BUFINPUT, 0, 0 };
+
+int __fflush_stdin() {
+ return fflush(stdin);
+}
+#else
+static FILE __stdin = { 0, 0 };
+#endif
+
+FILE *stdin=&__stdin;
diff --git a/mdk-stage1/dietlibc/libstdio/stdout.c b/mdk-stage1/dietlibc/libstdio/stdout.c
new file mode 100644
index 000000000..481fb1014
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/stdout.c
@@ -0,0 +1,14 @@
+#include <dietstdio.h>
+
+#ifdef WANT_BUFFERED_STDIO
+static FILE __stdout = { 1, BUFLINEWISE, 0, 0 };
+
+int __fflush_stdout() {
+ return fflush(stdout);
+}
+#else
+static FILE __stdout = { 1, 0 };
+#endif
+
+FILE *stdout=&__stdout;
+
diff --git a/mdk-stage1/dietlibc/libstdio/ungetc.c b/mdk-stage1/dietlibc/libstdio/ungetc.c
new file mode 100644
index 000000000..ae03e9381
--- /dev/null
+++ b/mdk-stage1/dietlibc/libstdio/ungetc.c
@@ -0,0 +1,11 @@
+#include "dietstdio.h"
+
+#ifdef WANT_UNGETC
+int ungetc(int c, FILE *stream) {
+ if (stream->ungotten)
+ return EOF;
+ stream->ungotten=1;
+ stream->ungetbuf=(char)(unsigned char)c;
+ return c;
+}
+#endif
diff --git a/mdk-stage1/dietlibc/libugly/asctime.c b/mdk-stage1/dietlibc/libugly/asctime.c
new file mode 100644
index 000000000..e1fcc8706
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/asctime.c
@@ -0,0 +1,7 @@
+#include <time.h>
+
+static char buf[25];
+
+char *asctime(const struct tm *timeptr) {
+ return asctime_r(timeptr,buf);
+}
diff --git a/mdk-stage1/dietlibc/libugly/asctime_r.c b/mdk-stage1/dietlibc/libugly/asctime_r.c
new file mode 100644
index 000000000..46325927c
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/asctime_r.c
@@ -0,0 +1,29 @@
+#include <time.h>
+
+static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
+static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
+
+static void num2str(char *c,int i) {
+ c[0]=i/10+'0';
+ c[1]=i%10+'0';
+}
+
+char *asctime_r(const struct tm *t, char *buf) {
+ /* "Wed Jun 30 21:49:08 1993\n" */
+ *(int*)buf=*(int*)(days+(t->tm_wday<<2));
+ *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
+ num2str(buf+8,t->tm_mday);
+ if (buf[8]=='0') buf[8]=' ';
+ buf[10]=' ';
+ num2str(buf+11,t->tm_hour);
+ if (buf[11]=='0') buf[11]=' ';
+ buf[13]=':';
+ num2str(buf+14,t->tm_min);
+ buf[16]=':';
+ num2str(buf+17,t->tm_sec);
+ buf[19]=' ';
+ num2str(buf+20,(t->tm_year+1900)/100);
+ num2str(buf+22,(t->tm_year+1900)%100);
+ buf[24]='\n';
+ return buf;
+}
diff --git a/mdk-stage1/dietlibc/libugly/asprintf.c b/mdk-stage1/dietlibc/libugly/asprintf.c
new file mode 100644
index 000000000..d10c20b4a
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/asprintf.c
@@ -0,0 +1,22 @@
+#include <stdarg.h>
+#include <linux/types.h>
+#include <stdlib.h>
+#include "dietwarning.h"
+
+extern int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr);
+
+int asprintf(char **s, const char *format,...)
+{
+ int n;
+ va_list arg_ptr;
+ va_start(arg_ptr, format);
+ n=vsnprintf(0,1000000,format,arg_ptr);
+ va_end (arg_ptr);
+ va_start (arg_ptr, format);
+ if ((*s=malloc(n+2))) {
+ n=vsnprintf(*s,n+1,format,arg_ptr);
+ va_end(arg_ptr);
+ return n;
+ }
+ return -1;
+}
diff --git a/mdk-stage1/dietlibc/libugly/ctime.c b/mdk-stage1/dietlibc/libugly/ctime.c
new file mode 100644
index 000000000..a0e12d673
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/ctime.c
@@ -0,0 +1,5 @@
+#include <time.h>
+
+char *ctime(const time_t *timep) {
+ return asctime(localtime(timep));
+}
diff --git a/mdk-stage1/dietlibc/libugly/daemon.c b/mdk-stage1/dietlibc/libugly/daemon.c
new file mode 100644
index 000000000..6748cc3c9
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/daemon.c
@@ -0,0 +1,35 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <paths.h>
+
+#include "daemon.h"
+
+int daemon (int nochdir,int noclose)
+{
+ int fd;
+ switch (fork ())
+ {
+ case -1:
+ return (-1);
+ case 0:
+ break;
+ default:
+ _exit (0);
+ }
+ if (setsid () == -1)
+ return (-1);
+ if (!nochdir) chdir ("/");
+ if (!noclose)
+ {
+ fd = open (_PATH_DEVNULL,O_RDWR,0);
+ if (fd == -1) return (-1);
+ dup2 (fd,STDIN_FILENO);
+ dup2 (fd,STDOUT_FILENO);
+ dup2 (fd,STDERR_FILENO);
+ close (fd);
+ }
+ return (0);
+}
+
diff --git a/mdk-stage1/dietlibc/libugly/endmntent.c b/mdk-stage1/dietlibc/libugly/endmntent.c
new file mode 100644
index 000000000..00ade38e5
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/endmntent.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <mntent.h>
+
+int endmntent(FILE *filep) {
+ return fclose(filep);
+}
+
diff --git a/mdk-stage1/dietlibc/libugly/facilitynames.c b/mdk-stage1/dietlibc/libugly/facilitynames.c
new file mode 100644
index 000000000..8b0e1f21f
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/facilitynames.c
@@ -0,0 +1,32 @@
+#include <sys/syslog.h>
+
+#ifndef INTERNAL_MARK
+#define INTERNAL_MARK 0x300
+#endif
+
+CODE facilitynames[] =
+ {
+ { "auth", LOG_AUTH },
+ { "authpriv", LOG_AUTHPRIV },
+ { "cron", LOG_CRON },
+ { "daemon", LOG_DAEMON },
+ { "ftp", LOG_FTP },
+ { "kern", LOG_KERN },
+ { "lpr", LOG_LPR },
+ { "mail", LOG_MAIL },
+ { "mark", INTERNAL_MARK }, /* INTERNAL */
+ { "news", LOG_NEWS },
+ { "security", LOG_AUTH }, /* DEPRECATED */
+ { "syslog", LOG_SYSLOG },
+ { "user", LOG_USER },
+ { "uucp", LOG_UUCP },
+ { "local0", LOG_LOCAL0 },
+ { "local1", LOG_LOCAL1 },
+ { "local2", LOG_LOCAL2 },
+ { "local3", LOG_LOCAL3 },
+ { "local4", LOG_LOCAL4 },
+ { "local5", LOG_LOCAL5 },
+ { "local6", LOG_LOCAL6 },
+ { "local7", LOG_LOCAL7 },
+ { 0, -1 }
+ };
diff --git a/mdk-stage1/dietlibc/libugly/getmntent.c b/mdk-stage1/dietlibc/libugly/getmntent.c
new file mode 100644
index 000000000..250a77b7f
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/getmntent.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <mntent.h>
+#include <string.h>
+
+struct mntent *getmntent(FILE *filep) {
+ static struct mntent m;
+ char buf[1024];
+ do {
+ char *tmp=buf;
+ int num;
+ fgets(buf,1024,filep);
+/* "/dev/ide/host0/bus0/target0/lun0/part2 / reiserfs defaults 1 1" */
+ for (num=0; num<6; ++num) {
+ switch (num) {
+ case 0: m.mnt_fsname=tmp; break;
+ case 1: m.mnt_dir=tmp; break;
+ case 2: m.mnt_type=tmp; break;
+ case 3: m.mnt_opts=tmp; break;
+ case 4: m.mnt_freq=strtol(tmp,&tmp,0); if (*tmp!=' ') continue; break;
+ case 5: m.mnt_passno=strtol(tmp,&tmp,0); if (*tmp=='\n') return &m; break;
+ }
+ if ((tmp=strchr(tmp,' '))) {
+ if (num<4) *tmp++=0;
+ while (*tmp==' ') ++tmp;
+ } else
+ continue;
+ }
+ } while (1);
+}
diff --git a/mdk-stage1/dietlibc/libugly/getprotoent.c b/mdk-stage1/dietlibc/libugly/getprotoent.c
new file mode 100644
index 000000000..a648e2307
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/getprotoent.c
@@ -0,0 +1,130 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <ctype.h>
+
+static int protofd=-1;
+static char* protomap;
+static unsigned int protolen;
+
+static char* aliases[10];
+
+static char *cur;
+
+/* ip 0 IP # internet protocol, pseudo protocol number */
+struct protoent *getprotoent(void) {
+ static struct protoent pe;
+ char *last;
+ int aliasidx;
+ if (protofd<0) {
+ protofd=open(_PATH_SERVICES,O_RDONLY);
+ if (protofd<0) return 0;
+ protolen=lseek(protofd,0,SEEK_END);
+ protomap=mmap(0,protolen,PROT_READ|PROT_WRITE,MAP_PRIVATE,protofd,0);
+ if ((long)protomap==(-1)) goto error;
+ cur=protomap;
+ }
+ last=protomap+protolen;
+again:
+ pe.p_name=0;
+ pe.p_aliases=aliases; aliases[0]=0;
+ pe.p_proto=0;
+ if (cur>=last) return 0;
+ if (*cur=='#' || *cur=='\n') goto parseerror;
+ /* first, the primary name */
+ if (!isalpha(*cur)) goto parseerror;
+ pe.p_name=cur;
+ pe.p_aliases=aliases;
+ while (cur<last && isalnum(*cur)) cur++;
+ if (cur>=last) return 0;
+ if (*cur=='\n') goto parseerror;
+ *cur=0; cur++;
+ /* second, the protocol number */
+ while (cur<last && isblank(*cur)) cur++;
+ while (cur<last && isdigit(*cur)) {
+ pe.p_proto=pe.p_proto*10+*cur-'0';
+ cur++;
+ }
+/* pe.p_proto=htons(pe.s_proto); */
+ if (cur>=last) return 0;
+ if (*cur=='\n') { *cur++=0; return &pe; }
+ *cur=0; cur++;
+ /* now the aliases */
+ for (aliasidx=0;aliasidx<10;++aliasidx) {
+ while (cur<last && isblank(*cur)) ++cur;
+ aliases[aliasidx]=cur;
+ while (cur<last && isalpha(*cur)) ++cur;
+ if (*cur=='\n') { *cur++=0; ++aliasidx; break; }
+ if (cur>=last || !isblank(*cur)) break;
+ *cur++=0;
+ }
+ aliases[aliasidx]=0;
+ return &pe;
+parseerror:
+ while (cur<last && *cur!='\n') cur++;
+ cur++;
+ goto again;
+error:
+ if (protomap!=(char*)-1) munmap(protomap,protolen);
+ if (protofd!=-1) close(protofd);
+ protomap=(char*)-1;
+ protofd=-1;
+ errno=ENOMEM;
+ return 0;
+}
+
+void setprotoent(int stayopen) {
+ cur=protomap;
+}
+
+struct protoent *getprotobyname(const char *name) {
+ struct protoent *s;
+ setprotoent(0);
+ for (s=getprotoent(); s; s=getprotoent()) {
+ char **tmp;
+#if 0
+ write(1,"found ",6);
+ write(1,s->p_name,strlen(s->p_name));
+ write(1,"/",1);
+ write(1,s->p_proto,strlen(s->p_proto));
+ write(1,"\n",1);
+ if (!strcmp(name,"auth")) {
+ tmp=s->p_aliases;
+ write(1," aka ",5);
+ while (*tmp) {
+ write(1,*tmp,strlen(*tmp));
+ write(1,", ",2);
+ ++tmp;
+ }
+ write(1,"\n",1);
+ }
+#endif
+ if (!strcmp(name,s->p_name))
+ return s;
+ tmp=s->p_aliases;
+ while (*tmp)
+ if (!strcmp(name,*tmp++)) return s;
+ }
+ return 0;
+}
+
+struct protoent *getprotobynumber(int proto) {
+ struct protoent *s;
+ for (s=getprotoent(); s; s=getprotoent()) {
+ if (proto==s->p_proto)
+ return s;
+ }
+ return 0;
+}
+
+void endprotoent(void) {
+ if (protomap!=(char*)-1) munmap(protomap,protolen);
+ if (protofd!=-1) close(protofd);
+ protomap=(char*)-1;
+ protofd=-1;
+}
+
diff --git a/mdk-stage1/dietlibc/libugly/gmtime.c b/mdk-stage1/dietlibc/libugly/gmtime.c
new file mode 100644
index 000000000..d33af7972
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/gmtime.c
@@ -0,0 +1,6 @@
+#include <time.h>
+
+struct tm* gmtime(const time_t *t) {
+ static struct tm tmp;
+ return gmtime_r(t,&tmp);
+}
diff --git a/mdk-stage1/dietlibc/libugly/gmtime_r.c b/mdk-stage1/dietlibc/libugly/gmtime_r.c
new file mode 100644
index 000000000..c102d10fa
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/gmtime_r.c
@@ -0,0 +1,35 @@
+#include <time.h>
+
+/* seconds per day */
+#define SPD 24*60*60
+
+extern unsigned int __spm[];
+
+struct tm *gmtime_r(const time_t *timep, struct tm *r) {
+ time_t i;
+ register time_t work=*timep%(SPD);
+ r->tm_sec=work%60; work/=60;
+ r->tm_min=work%60; r->tm_hour=work/60;
+ work=*timep/(SPD);
+ r->tm_wday=(4+work)%7;
+ for (i=1970; ; ++i) {
+ register time_t k=__isleap(i)?366:365;
+ if (work>k)
+ work-=k;
+ else
+ break;
+ }
+ r->tm_year=i-1900;
+ r->tm_yday=work;
+
+ r->tm_mday=1;
+ if (__isleap(i) && (work>58)) {
+ if (work==59) r->tm_mday=2; /* 29.2. */
+ work-=1;
+ }
+
+ for (i=11; i && __spm[i]>work; --i) ;
+ r->tm_mon=i;
+ r->tm_mday+=work-__spm[i];
+ return r;
+}
diff --git a/mdk-stage1/dietlibc/libugly/isleap.c b/mdk-stage1/dietlibc/libugly/isleap.c
new file mode 100644
index 000000000..dcfa1ced6
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/isleap.c
@@ -0,0 +1,6 @@
+int __isleap(int year) {
+ /* every fourth year is a leap year except for century years that are
+ * not divisible by 400. */
+/* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
+ return (!(year%4) && ((year%100) || !(year%400)));
+}
diff --git a/mdk-stage1/dietlibc/libugly/localtime.c b/mdk-stage1/dietlibc/libugly/localtime.c
new file mode 100644
index 000000000..6fa6acf8a
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/localtime.c
@@ -0,0 +1,6 @@
+#include <time.h>
+
+struct tm* localtime(const time_t* t) {
+ static struct tm tmp;
+ return localtime_r(t,&tmp);
+}
diff --git a/mdk-stage1/dietlibc/libugly/localtime_r.c b/mdk-stage1/dietlibc/libugly/localtime_r.c
new file mode 100644
index 000000000..d4bc073ce
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/localtime_r.c
@@ -0,0 +1,21 @@
+#include "dietfeatures.h"
+#include <time.h>
+#include <sys/time.h>
+
+#ifdef WANT_TZFILE_PARSER
+extern void __maplocaltime();
+extern time_t __tzfile_map(time_t t, int *isdst);
+#endif
+
+struct tm* localtime_r(const time_t* t, struct tm* r) {
+ time_t tmp;
+#ifdef WANT_TZFILE_PARSER
+ __maplocaltime();
+ tmp=__tzfile_map(*t,&r->tm_isdst);
+#else
+ struct timezone tz;
+ gettimeofday(0, &tz);
+ tmp=*t-tz.tz_minuteswest*60L;
+#endif
+ return gmtime_r(&tmp,r);
+}
diff --git a/mdk-stage1/dietlibc/libugly/logging.c b/mdk-stage1/dietlibc/libugly/logging.c
new file mode 100644
index 000000000..69c2c2337
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/logging.c
@@ -0,0 +1,211 @@
+#include "dietfeatures.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <unistd.h>
+#include <asm/socket.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <string.h>
+#include <time.h>
+#include <sys/socket.h>
+#include <signal.h>
+
+#define _PATH_CONSOLE "/dev/console"
+#define BUF_SIZE 512 /* messagebuffer size (>= 200) */
+
+#define MAX_LOGTAG 80
+
+/* those have to be global *sigh* */
+static volatile int connected = 0; /* have done connect */
+static volatile int LogMask = 0xff; /* mask of priorities to be logged */
+static char LogTag[MAX_LOGTAG]; /* string to tag the entry with */
+static int LogFile = -1; /* fd for log */
+static int LogType = SOCK_DGRAM; /* type of socket connection */
+static int LogFacility = LOG_USER; /* default facility code */
+static int LogStat; /* status bits, set by openlog() */
+extern char *__progname; /* Program name, from crt0. */
+static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
+
+static void closelog_intern(void)
+{
+ if (!connected) return;
+ close(LogFile);
+ LogFile = -1;
+ connected = 0;
+}
+
+void closelog(void)
+{
+ closelog_intern();
+
+ LogTag[0]=0;
+ LogType = SOCK_DGRAM;
+}
+
+static void openlog_intern(int option, int facility)
+{
+ LogStat = option;
+ if (facility && ((facility & ~LOG_FACMASK) == 0))
+ LogFacility = facility;
+
+ /* yep, there is a continue inside ;) */
+ while(1) {
+ if (LogFile == -1) {
+ SyslogAddr.sa_family = AF_UNIX;
+ strncpy(SyslogAddr.sa_data, _PATH_LOG, sizeof(SyslogAddr.sa_data));
+ if (LogStat & LOG_NDELAY)
+ {
+ if ((LogFile = socket(AF_UNIX, LogType, 0)) == -1) return;
+ fcntl(LogFile, F_SETFD, 1);
+ }
+ }
+ if ((LogFile != -1) && !connected) {
+#ifdef WANT_THREAD_SAFE
+ int old_errno = (*(__errno_location()));
+#else
+ int old_errno=errno;
+#endif
+ if(connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
+#ifdef WANT_THREAD_SAFE
+ int saved_errno = (*(__errno_location()));
+#else
+ int saved_errno=errno;
+#endif
+ close(LogFile);
+ LogFile = -1;
+ if((LogType == SOCK_DGRAM) && (saved_errno == EPROTOTYPE)) {
+ /* retry with SOCK_STREAM instead of SOCK_DGRAM */
+ LogType = SOCK_STREAM;
+#ifdef WANT_THREAD_SAFE
+ (*(__errno_location()))=old_errno;
+#else
+ errno=old_errno;
+#endif
+ continue;
+ }
+ }
+ else connected = 1;
+ }
+ break;
+ }
+}
+
+/* has to be secured against multiple, simultanious call's in threaded environment */
+void openlog(const char *ident, int option, int facility)
+{
+ if (ident) {
+ strncpy(LogTag,ident,MAX_LOGTAG);
+ LogTag[MAX_LOGTAG-1]=0;
+ }
+ openlog_intern(option, facility);
+}
+
+int setlogmask(int mask)
+{
+ int old = LogMask;
+ if (mask) LogMask = mask;
+ return old;
+}
+
+void vsyslog(int priority, const char *format, va_list arg_ptr)
+{
+ char buffer[BUF_SIZE];
+ char time_buf[20];
+ int buflen, headerlen;
+ time_t now;
+ struct tm now_tm;
+ pid_t pid;
+ int fd;
+ int sigpipe;
+ struct sigaction action, oldaction;
+ struct sigaction *oldaction_ptr = NULL;
+#ifdef WANT_THREAD_SAFE
+ int saved_errno = (*(__errno_location()));
+#else
+ int saved_errno = errno;
+#endif
+
+ /* check for invalid priority/facility bits */
+ if (priority & ~(LOG_PRIMASK|LOG_FACMASK)) {
+ syslog(LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID, "syslog: unknown facility/priorityority: %x", priority);
+ priority &= LOG_PRIMASK|LOG_FACMASK;
+ }
+
+ /* check priority against setlogmask */
+ if ((LOG_MASK(LOG_PRI(priority)) && LogMask) == 0) return;
+
+ /* Set default facility if none specified. */
+ if ((priority & LOG_FACMASK) == 0) priority |= LogFacility;
+
+ pid = getpid();
+ time(&now);
+ strftime(time_buf, 20, "%h %e %T", localtime_r (&now, &now_tm));
+
+ if (LogStat & LOG_PID)
+ headerlen = snprintf(buffer, 130, "<%d>%s %s[%d]: ", priority, time_buf, LogTag, pid);
+ else
+ headerlen = snprintf(buffer, 130, "<%d>%s %s: ", priority, time_buf, LogTag);
+
+ if (!LogTag[0]) {
+ if ((LogStat & LOG_PID) != LOG_PID)
+ headerlen = snprintf(buffer, 130, "<%d>%s (unknown)[%d]: ", priority, time_buf, pid);
+ strcat(buffer+headerlen, "syslog without openlog w/ ident, please check code!");
+ buflen = 41;
+ }
+ else {
+#ifdef WANT_THREAD_SAFE
+ (*(__errno_location()))=saved_errno;
+#else
+ errno=saved_errno;
+#endif
+ buflen = vsnprintf(buffer+headerlen, BUF_SIZE - headerlen, format, arg_ptr);
+ }
+ if (LogStat & LOG_PERROR) {
+ write(1, buffer+headerlen, buflen);
+ if (buffer[headerlen+buflen] != '\n') write(1,"\n", 1);
+ }
+
+ /* prepare for broken connection */
+ memset(&action, 0, sizeof(action));
+ action.sa_handler = SIG_IGN;
+ sigemptyset(&action.sa_mask);
+
+ if ((sigpipe = sigaction (SIGPIPE, &action, &oldaction))==0)
+ oldaction_ptr = &oldaction;
+
+ if (!connected) openlog_intern(LogStat | LOG_NDELAY, 0);
+
+ /* If we have a SOCK_STREAM connection, also send ASCII NUL as a
+ * record terminator. */
+ if (LogType == SOCK_STREAM) buflen++;
+
+ if (!connected || (send(LogFile, buffer, buflen+headerlen, 0) != buflen+headerlen)) {
+ if (LogType == SOCK_STREAM) buflen--;
+ closelog_intern();
+ /*
+ * Output the message to the console; don't worry about blocking,
+ * if console blocks everything will. Make sure the error reported
+ * is the one from the syslogd failure.
+ */
+ if ((LogStat & LOG_CONS) &&
+ ((fd = open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY, 0)) >= 0))
+ {
+ write(fd, buffer, buflen+headerlen);
+ write(fd, "\r\n", 2);
+ }
+ }
+
+ if (sigpipe == 0)
+ sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL);
+}
+
+void syslog(int priority, const char *format, ...)
+{
+ va_list arg_ptr;
+ va_start(arg_ptr, format);
+ vsyslog(priority, format, arg_ptr);
+ va_end(arg_ptr);
+}
diff --git a/mdk-stage1/dietlibc/libugly/mktime.c b/mdk-stage1/dietlibc/libugly/mktime.c
new file mode 100644
index 000000000..ee4dab6c1
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/mktime.c
@@ -0,0 +1,21 @@
+#include <time.h>
+
+/* seconds per day */
+#define SPD 24*60*60
+
+extern unsigned int __spm[];
+
+time_t mktime(struct tm *t) {
+ time_t x=0;
+ unsigned int i;
+ if (t->tm_year<70) return (time_t)(-1);
+ for (i=70; i<t->tm_year; ++i) {
+ x+=__isleap(i+1900)?366:365;
+ }
+ t->tm_yday=__spm[t->tm_mon] + t->tm_mday-1 + ((t->tm_mon>2) && __isleap(t->tm_year)?1:0);
+ x+=t->tm_yday;
+ /* x is now the number of days since Jan 1 1970 */
+ t->tm_wday=(4+x)%7;
+ x = x*SPD + t->tm_hour*60*60 + t->tm_min*60 + t->tm_sec;
+ return x;
+}
diff --git a/mdk-stage1/dietlibc/libugly/pclose.c b/mdk-stage1/dietlibc/libugly/pclose.c
new file mode 100644
index 000000000..e33076c19
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/pclose.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "dietstdio.h"
+
+int pclose(FILE *f) {
+ int status;
+ fclose(f);
+ if (waitpid(f->popen_kludge,&status,0)>=0)
+ return status;
+ return -1;
+}
diff --git a/mdk-stage1/dietlibc/libugly/popen.c b/mdk-stage1/dietlibc/libugly/popen.c
new file mode 100644
index 000000000..e0e441495
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/popen.c
@@ -0,0 +1,32 @@
+#include "dietstdio.h"
+#include <unistd.h>
+
+extern char **environ;
+
+FILE *popen(const char *command, const char *type) {
+ int pfd[2];
+ int fd0;
+ pid_t pid;
+ if (pipe(pfd)<0) return 0;
+ fd0=(*type=='r');
+ if ((pid=vfork())<0) {
+ close(pfd[0]);
+ close(pfd[1]);
+ return 0;
+ }
+ if (!pid) { /* child */
+ char *argv[]={"sh","-c",0,0};
+ close(pfd[!fd0]); close(fd0);
+ dup2(pfd[fd0],fd0); close(pfd[fd0]);
+ argv[2]=(char*)command;
+ execve("/bin/sh",argv,environ);
+ _exit(255);
+ }
+ close(pfd[fd0]);
+ {
+ register FILE* f;
+ if ((f=fdopen(pfd[!fd0],type)))
+ f->popen_kludge=pid;
+ return f;
+ }
+}
diff --git a/mdk-stage1/dietlibc/libugly/prioritynames.c b/mdk-stage1/dietlibc/libugly/prioritynames.c
new file mode 100644
index 000000000..87a99b76d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/prioritynames.c
@@ -0,0 +1,22 @@
+#include <sys/syslog.h>
+
+#ifndef INTERNAL_NOPRI
+#define INTERNAL_NOPRI 0x10
+#endif
+
+CODE prioritynames[] =
+ {
+ { "alert", LOG_ALERT },
+ { "crit", LOG_CRIT },
+ { "debug", LOG_DEBUG },
+ { "emerg", LOG_EMERG },
+ { "err", LOG_ERR },
+ { "error", LOG_ERR }, /* DEPRECATED */
+ { "info", LOG_INFO },
+ { "none", INTERNAL_NOPRI }, /* INTERNAL */
+ { "notice", LOG_NOTICE },
+ { "panic", LOG_EMERG }, /* DEPRECATED */
+ { "warn", LOG_WARNING }, /* DEPRECATED */
+ { "warning", LOG_WARNING },
+ { 0, -1 }
+ };
diff --git a/mdk-stage1/dietlibc/libugly/setenv.c b/mdk-stage1/dietlibc/libugly/setenv.c
new file mode 100644
index 000000000..bf47cdb79
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/setenv.c
@@ -0,0 +1,17 @@
+#include <string.h>
+#include <stdlib.h>
+
+#include <dietwarning.h>
+link_warning("setenv","setenv calls malloc. Avoid it in small programs.");
+
+int setenv(const char *name, const char *value, int overwrite) {
+ char *c=malloc(strlen(name)+strlen(value)+3);
+ if (getenv(name)) {
+ if (!overwrite) return 0;
+ unsetenv(name);
+ }
+ strcpy(c,name);
+ strcat(c,"=");
+ strcat(c,value);
+ return putenv(c);
+}
diff --git a/mdk-stage1/dietlibc/libugly/setmntent.c b/mdk-stage1/dietlibc/libugly/setmntent.c
new file mode 100644
index 000000000..a91d3902b
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/setmntent.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <mntent.h>
+
+FILE *setmntent(const char *filename, const char *type) {
+ return fopen(filename,type);
+}
+
diff --git a/mdk-stage1/dietlibc/libugly/strftime.c b/mdk-stage1/dietlibc/libugly/strftime.c
new file mode 100644
index 000000000..b7e750ab1
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/strftime.c
@@ -0,0 +1,182 @@
+#include <sys/types.h>
+#include <time.h>
+
+static char *sweekdays[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
+static char *weekdays[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
+static char *smonths[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
+static char *months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
+static char *ampm[]={"am","pm","AM","PM"};
+
+static int i2a(char* dest,unsigned int x) {
+ register unsigned int tmp=x;
+ register int len=0;
+ *dest++=tmp/10+'0'; tmp=tmp%10; ++len;
+ *dest++=tmp+'0';
+ return 2;
+}
+
+static int i2as(char* dest,unsigned int x) {
+ int len=i2a(dest,x);
+ if (*dest=='0') *dest=' ';
+ return len;
+}
+
+size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) {
+ char *t=s;
+ const char *src;
+ char buf[5];
+ while (*format) {
+ switch (*format) {
+ case 0: break;
+ case '%':
+ switch (*++format) {
+ case '%': *t='%'; ++t; break;
+ case 'a': src=sweekdays[tm->tm_wday]; goto append;
+ case 'A': src=weekdays[tm->tm_wday]; goto append;
+ case 'h':
+ case 'b': src=smonths[tm->tm_mon]; goto append;
+ case 'B': src=months[tm->tm_mon]; goto append;
+ case 'c': t+=strftime(t,max-(t-s),"%b %a %d %k:%M:%S %Z %Y",tm); break;
+ case 'C': buf[i2a(buf,(tm->tm_year+1900)/100)]=0; src=buf; goto append;
+ case 'd': buf[i2a(buf,tm->tm_mday)]=0; src=buf; goto append;
+ case 'e': buf[i2as(buf,tm->tm_mday)]=0; src=buf; goto append;
+ case 'H': buf[i2a(buf,tm->tm_hour)]=0; src=buf; goto append;
+ case 'I': buf[i2a(buf,tm->tm_hour%12)]=0; src=buf; goto append;
+ case 'j': buf[i2a(buf,tm->tm_yday)]=0; src=buf; goto append;
+ case 'k': buf[i2as(buf,tm->tm_hour)]=0; src=buf; goto append;
+ case 'l': buf[i2as(buf,tm->tm_hour%12)]=0; src=buf; goto append;
+ case 'm': buf[i2a(buf,tm->tm_mon+1)]=0; src=buf; goto append;
+ case 'M': buf[i2a(buf,tm->tm_min)]=0; src=buf; goto append;
+ case 'n': *t='\n'; break;
+ case 'p': src=ampm[tm->tm_hour>11?3:2]; goto append;
+ case 'P': src=ampm[tm->tm_hour>11?1:0]; goto append;
+ case 'r': t+=strftime(t,max-(t-s),"%I:%M:%S %p",tm); break;
+ case 'R': t+=strftime(t,max-(t-s),"%H:%M",tm); break;
+ case 'S': buf[i2a(buf,tm->tm_sec)]=0; src=buf; goto append;
+ case 't': *t='\t'; break;
+ case 'T': t+=strftime(t,max-(t-s),"%H:%M:%S",tm); break;
+ case 'u': buf[i2a(buf,tm->tm_wday?tm->tm_wday:7)]=0; src=buf; goto append;
+ case 'w': buf[i2a(buf,tm->tm_wday)]=0; src=buf; goto append;
+ case 'x': t+=strftime(t,max-(t-s),"%b %a %d",tm); break;
+ case 'X': t+=strftime(t,max-(t-s),"%k:%M:%S",tm); break;
+ case 'y': buf[i2a(buf,tm->tm_year%100)]=0; src=buf; goto append;
+ case 'Y': i2a(buf,(tm->tm_year+1900)/100); buf[i2a(buf+2,(tm->tm_year%100))+2]=0; src=buf; goto append;
+ case 'Z': src="GMT"; goto append; /* hehe */
+append:
+ while (*src && t<s+max) { *t=*src; ++t; ++src; }
+ };
+ break;
+ default:
+ *t=*format; ++t;
+ }
+ ++format;
+ if (t>=s+max) break;
+ continue;
+ }
+ *t=0; return t-s;
+}
+
+
+
+/*
+ %u The day of the week as a decimal, range 1 to 7,
+ Monday being 1. See also %w. (SU)
+
+ %U The week number of the current year as a decimal
+ number, range 00 to 53, starting with the first
+ Sunday as the first day of week 01. See also %V and
+ %W.
+
+ %V The ISO 8601:1988 week number of the current year
+ as a decimal number, range 01 to 53, where week 1
+ is the first week that has at least 4 days in the
+ current year, and with Monday as the first day of
+ the week. See also %U and %W. (SU)
+
+ %w The day of the week as a decimal, range 0 to 6,
+ Sunday being 0. See also %u.
+
+ %W The week number of the current year as a decimal
+ number, range 00 to 53, starting with the first
+ Monday as the first day of week 01.
+
+ %x The preferred date representation for the current
+ locale without the time.
+
+ %X The preferred time representation for the current
+ locale without the date.
+
+ %y The year as a decimal number without a century
+ (range 00 to 99).
+
+ %Y The year as a decimal number including the century.
+
+ %z The time-zone as hour offset from GMT. Required to
+ emit RFC822-conformant dates (using "%a, %d %b %Y
+ %H:%M:%S %z"). (GNU)
+
+ %Z The time zone or name or abbreviation.
+
+ %+ The date and time in date(1) format. (TZ)
+
+ %% A literal `%' character.
+
+ Some conversion specifiers can be modified by preceding
+ them by the E or O modifier to indicate that an alterna­
+ tive format should be used. If the alternative format or
+ specification does not exist for the current locale, the
+ behaviour will be as if the unmodified conversion specifi­
+ cation were used. (SU) The Single Unix Specification men­
+ tions %Ec, %EC, %Ex, %EX, %Ry, %EY, %Od, %Oe, %OH, %OI,
+ %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy, where the
+ effect of the O modifier is to use alternative numeric
+ symbols (say, roman numerals), and that of the E modifier
+
+
+
+GNU 29 March 1999 3
+
+
+
+
+
+STRFTIME(3) Linux Programmer's Manual STRFTIME(3)
+
+
+ is to use a locale-dependent alternative representation.
+
+ The broken-down time structure tm is defined in <time.h>.
+ See also ctime(3).
+
+
+RETURN VALUE
+ The strftime() function returns the number of characters
+ placed in the array s, not including the terminating NUL
+ character, provided the string, including the terminating
+ NUL, fits. Otherwise, it returns 0, and the contents of
+ the array is undefined. (Thus at least since libc 4.4.4;
+ very old versions of libc, such as libc 4.4.1, would
+ return max if the array was too small.)
+
+ Note that the return value 0 does not necessarily indicate
+ an error; for example, in many locales %p yields an empty
+ string.
+
+ENVIRONMENT
+ The environment variables TZ and LC_TIME are used.
+
+CONFORMING TO
+ ANSI C, SVID 3, ISO 9899. There are strict inclusions
+ between the set of conversions given in ANSI C (unmarked),
+ those given in the Single Unix Specification (marked SU),
+ those given in Olson's timezone package (marked TZ), and
+ those given in glibc (marked GNU), except that %+ is not
+ supported in glibc2. On the other hand glibc2 has several
+ more extensions. POSIX.1 only refers to ANSI C; POSIX.2
+ describes under date(1) several extensions that could
+ apply to strftime as well.
+
+SEE ALSO
+ date(1), time(2), ctime(3), setlocale(3), sprintf(3)
+
+*/
diff --git a/mdk-stage1/dietlibc/libugly/strsignal.c b/mdk-stage1/dietlibc/libugly/strsignal.c
new file mode 100644
index 000000000..54314d2c7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/strsignal.c
@@ -0,0 +1,92 @@
+#include <signal.h>
+/* F....ng Kernel haeder is damn broken... */
+#ifndef _NSIG
+#define _NSIG 64
+#endif
+#include <asm/signal.h>
+
+char * strsignal(int sig) {
+ if (sig==SIGHUP)
+ return "Hangup";
+ else if (sig==SIGINT)
+ return "Interrupt";
+ else if (sig==SIGQUIT)
+ return "Quit";
+ else if (sig==SIGILL)
+ return "Illegal instruction";
+ else if (sig==SIGTRAP)
+ return "Trace/breakpoint trap";
+ else if (sig==SIGABRT)
+ return "Aborted";
+ else if (sig==SIGFPE)
+ return "Floating point exception";
+ else if (sig==SIGKILL)
+ return "Killed";
+ else if (sig==SIGBUS)
+ return "Bus error";
+ else if (sig==SIGSEGV)
+ return "Segmentation fault";
+ else if (sig==SIGPIPE)
+ return "Broken pipe";
+ else if (sig==SIGALRM)
+ return "Alarm clock";
+ else if (sig==SIGTERM)
+ return "Terminated";
+ else if (sig==SIGURG)
+ return "Urgent I/O condition";
+ else if (sig==SIGSTOP)
+ return "Stopped (signal)";
+ else if (sig==SIGTSTP)
+ return "Stopped";
+ else if (sig==SIGCONT)
+ return "Continue";
+ else if (sig==SIGCHLD)
+ return "Child exited";
+ else if (sig==SIGTTIN)
+ return "Stopped (tty input)";
+ else if (sig==SIGTTOU)
+ return "Stopped (tty output)";
+ else if (sig==SIGIO)
+ return "I/O possible";
+ else if (sig==SIGXCPU)
+ return "CPU time limit exceeded";
+ else if (sig==SIGXFSZ)
+ return "File size limit exceeded";
+ else if (sig==SIGVTALRM)
+ return "Virtual timer expired";
+ else if (sig==SIGPROF)
+ return "Profiling timer expired";
+ else if (sig==SIGWINCH)
+ return "Window changed";
+ else if (sig==SIGUSR1)
+ return "User defined signal 1";
+ else if (sig==SIGUSR2)
+ return "User defined signal 1";
+#ifdef SIGEMT
+ else if (sig==SIGEMT)
+ return "EMT trap";
+#endif
+#ifdef SIGSYS
+ else if (sig==SIGSYS)
+ return "Bad system call";
+#endif
+#ifdef SIGSTKFLT
+ else if (sig==SIGSTKFLT)
+ return "Stack fault";
+#endif
+#ifdef SIGINFO
+ else if (sig==SIGINFO)
+ return "Information request";
+#elif defined(SIGPWR) && (!defined(SIGLOST) || (SIGPWR!=SIGLOST))
+ else if (sig==SIGPWR)
+ return "Power falure";
+#endif
+#ifdef SIGLOST
+ else if (sig==SIGLOST)
+ return "Resource lost";
+#endif
+ else if ((sig>=SIGRTMIN)&&(sig<=SIGRTMAX))
+ return "Real time signal";
+ else
+ return "(unknown signal)";
+}
diff --git a/mdk-stage1/dietlibc/libugly/system.c b/mdk-stage1/dietlibc/libugly/system.c
new file mode 100644
index 000000000..b9eea20eb
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/system.c
@@ -0,0 +1,69 @@
+#include <signal.h>
+#include <asm/errno.h>
+#include <errno.h>
+#include <unistd.h>
+#include "dietwarning.h"
+
+#define SHELL_PATH "/bin/sh" /* Path of the shell. */
+#define SHELL_NAME "sh" /* Name to give it. */
+
+extern char **environ;
+
+int __libc_fork();
+int __libc_waitpid(int pid, int *status, int options);
+int execve(const char*filename, char *const argv[], char *const envp[]);
+void __set_errno(int errno);
+int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
+
+int __libc_system (const char *line)
+{
+ struct sigaction sa, intr, quit;
+ int save,pid,ret=-1;
+
+ if (line == 0) return __libc_system("exit 0") == 0;
+
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = 0;
+ sigemptyset (&sa.sa_mask);
+
+ if (sigaction(SIGINT, &sa, &intr)<0) return -1;
+ if (sigaction(SIGQUIT, &sa, &quit)<0) {
+ save = errno;
+ sigaction (SIGINT, &intr, (struct sigaction*)0);
+ __set_errno (save);
+ return -1;
+ }
+
+ pid=__libc_fork();
+ if (pid>0)
+ { /* parent */
+ int n;
+ do
+ n=__libc_waitpid(pid, &ret, 0);
+ while ((n==-1) && (errno==EINTR));
+ if (n!=pid) ret=-1;
+ }
+ else if (!pid)
+ { /* child */
+ const char *nargs[4];
+ nargs[0] = SHELL_NAME;
+ nargs[1] = "-c";
+ nargs[2] = line;
+ nargs[3] = 0;
+
+ sigaction(SIGINT, &intr, (struct sigaction*)0);
+ sigaction(SIGQUIT, &quit, (struct sigaction*)0);
+
+ execve(SHELL_PATH,(char *const *)nargs, environ);
+ _exit(127);
+ }
+ save = errno;
+ sigaction (SIGINT, &intr, (struct sigaction *)0);
+ sigaction (SIGQUIT, &quit, (struct sigaction *)0);
+ __set_errno(save);
+ return ret;
+}
+
+int system (const char *line) __attribute__((weak,alias("__libc_system")));
+
+link_warning("system","warning: system() is a security risk. Use fork and execvp instead!")
diff --git a/mdk-stage1/dietlibc/libugly/time_table_spd.c b/mdk-stage1/dietlibc/libugly/time_table_spd.c
new file mode 100644
index 000000000..bfe1cf86d
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/time_table_spd.c
@@ -0,0 +1,17 @@
+
+/* seconds per month -- nonleap! */
+const unsigned int __spm[12] =
+ { 0,
+ (31),
+ (31+28),
+ (31+28+31),
+ (31+28+31+30),
+ (31+28+31+30+31),
+ (31+28+31+30+31+30),
+ (31+28+31+30+31+30+31),
+ (31+28+31+30+31+30+31+31),
+ (31+28+31+30+31+30+31+31+30),
+ (31+28+31+30+31+30+31+31+30+31),
+ (31+28+31+30+31+30+31+31+30+31+30),
+ };
+
diff --git a/mdk-stage1/dietlibc/libugly/tzfile.c b/mdk-stage1/dietlibc/libugly/tzfile.c
new file mode 100644
index 000000000..5702d4bea
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/tzfile.c
@@ -0,0 +1,86 @@
+#include "dietfeatures.h"
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <netinet/in.h>
+
+#include <stdio.h>
+
+#ifdef WANT_TZFILE_PARSER
+static char *tzfile=0;
+static int tzlen=-1;
+
+void __maplocaltime() {
+ int fd;
+ unsigned int len;
+ if (tzlen>=0) return;
+ tzlen=0;
+ if ((fd=open("/etc/localtime",O_RDONLY))<0) return;
+ len=lseek(fd,0,SEEK_END);
+ if ((tzfile=mmap(0,len,PROT_READ,MAP_SHARED,fd,0))==MAP_FAILED) return;
+ close(fd);
+ if (ntohl(*(int*)tzfile) != 0x545a6966) return;
+ tzlen=len;
+}
+
+char *tzset(void) __attribute__((weak,alias("__maplocaltime")));
+
+static unsigned long __myntohl(const unsigned char* c) {
+ return (((unsigned long)c[0])<<24) +
+ (((unsigned long)c[1])<<16) +
+ (((unsigned long)c[2])<<8) +
+ ((unsigned long)c[3]);
+}
+
+time_t __tzfile_map(time_t t, int *isdst) {
+ /* "TZif" plus 16 reserved bytes. */
+ char *tmp;
+ int i;
+ int tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt;
+ *isdst=0;
+ if (!tzfile) return t;
+ tzh_ttisgmtcnt=ntohl(*(int*)(tzfile+20));
+ tzh_ttisstdcnt=ntohl(*(int*)(tzfile+24));
+ tzh_leapcnt=ntohl(*(int*)(tzfile+28));
+ tzh_timecnt=ntohl(*(int*)(tzfile+32));
+ tzh_typecnt=ntohl(*(int*)(tzfile+36));
+ tzh_charcnt=ntohl(*(int*)(tzfile+40));
+
+#if 0
+ tmp=tzfile+20+6*4;
+ printf("ttisgmtcnt %d ttisstdcnt %d leapcnt %d timecnt %d typecnt %d charcnt %d\n",tzh_ttisgmtcnt,tzh_ttisstdcnt, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt);
+ printf("transition times: ");
+ for (i=0; i<tzh_timecnt; ++i) {
+ printf("%s%lu",i?", ":"",ntohl(*(int*)tmp)); tmp+=4;
+ }
+ printf("\n");
+ printf("indices: ");
+ for (i=0; i<tzh_timecnt; ++i) {
+ printf("%s%d",i?", ":"",*tmp); ++tmp;
+ }
+ printf("\n");
+ printf("transition times: ");
+ for (i=0; i<tzh_typecnt; ++i) {
+ printf("%s(%lu,%d,%d)",i?", ":"",ntohl(*(int*)tmp),tmp[4],tmp[5]); tmp+=6;
+ }
+ printf("\n");
+#endif
+
+ tmp=tzfile+20+6*4;
+ for (i=0; i<tzh_timecnt; ++i)
+ if ((time_t)__myntohl(tmp+i*4) >= t) {
+/* printf("match at %d\n",i); */
+ tmp+=tzh_timecnt*4;
+ i=tmp[i-1];
+/* printf("using index %d\n",i); */
+ tmp+=tzh_timecnt;
+ tmp+=i*6;
+/* printf("(%lu,%d,%d)\n",ntohl(*(int*)tmp),tmp[4],tmp[5]); */
+ *isdst=tmp[4];
+ return t+__myntohl(tmp);
+ }
+ return t;
+}
+#else
+void tzset(void) __attribute__((weak,alias("return0")));
+#endif
diff --git a/mdk-stage1/dietlibc/libugly/unsetenv.c b/mdk-stage1/dietlibc/libugly/unsetenv.c
new file mode 100644
index 000000000..46e880271
--- /dev/null
+++ b/mdk-stage1/dietlibc/libugly/unsetenv.c
@@ -0,0 +1,6 @@
+#include <stdlib.h>
+
+void unsetenv(const char *name) {
+ putenv(name);
+}
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/_llseek.c b/mdk-stage1/dietlibc/syscalls.c/_llseek.c
new file mode 100644
index 000000000..fdf49eba5
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/_llseek.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include "syscalls.h"
+
+_syscall5(int,_llseek,uint,fd,ulong,hi,ulong,lo,loff_t*,res,uint,wh);
diff --git a/mdk-stage1/dietlibc/syscalls.c/_newselect.c b/mdk-stage1/dietlibc/syscalls.c/_newselect.c
new file mode 100644
index 000000000..cb42193bd
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/_newselect.c
@@ -0,0 +1,6 @@
+#include <linux/types.h>
+#include <linux/time.h>
+#include "syscalls.h"
+
+_syscall5(int,_newselect,int,n,fd_set *,rd,fd_set *,wr,fd_set *,ex,struct timeval *,timeval);
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/access.c b/mdk-stage1/dietlibc/syscalls.c/access.c
new file mode 100644
index 000000000..80944733a
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/access.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,access,const char*,pathname,int,mode)
diff --git a/mdk-stage1/dietlibc/syscalls.c/chdir.c b/mdk-stage1/dietlibc/syscalls.c/chdir.c
new file mode 100644
index 000000000..a679f528d
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/chdir.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,chdir,void*,path)
diff --git a/mdk-stage1/dietlibc/syscalls.c/chmod.c b/mdk-stage1/dietlibc/syscalls.c/chmod.c
new file mode 100644
index 000000000..80ad33b40
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/chmod.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,chmod,const char * ,path,mode_t,mode)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/chown.c b/mdk-stage1/dietlibc/syscalls.c/chown.c
new file mode 100644
index 000000000..5a9352684
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/chown.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,chown,char*,path,uid_t,owner,gid_t,group)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/chroot.c b/mdk-stage1/dietlibc/syscalls.c/chroot.c
new file mode 100644
index 000000000..ab39f7ebe
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/chroot.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall1(int,chroot,void*,path)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/clone.c b/mdk-stage1/dietlibc/syscalls.c/clone.c
new file mode 100644
index 000000000..985eee4c8
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/clone.c
@@ -0,0 +1 @@
+#warning "No CLONE support yet"
diff --git a/mdk-stage1/dietlibc/syscalls.c/close.c b/mdk-stage1/dietlibc/syscalls.c/close.c
new file mode 100644
index 000000000..a7d7f0076
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/close.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,close,int,fd)
diff --git a/mdk-stage1/dietlibc/syscalls.c/dup.c b/mdk-stage1/dietlibc/syscalls.c/dup.c
new file mode 100644
index 000000000..9c28f0bd6
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/dup.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall1(int,dup,int,fd)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/dup2.c b/mdk-stage1/dietlibc/syscalls.c/dup2.c
new file mode 100644
index 000000000..399314aa8
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/dup2.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,dup2,int,one,int,two)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/execve.c b/mdk-stage1/dietlibc/syscalls.c/execve.c
new file mode 100644
index 000000000..c2bac0117
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/execve.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,execve,const char *,fn,void *,argv,void *,envp)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/exit.c b/mdk-stage1/dietlibc/syscalls.c/exit.c
new file mode 100644
index 000000000..87087c939
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/exit.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,exit,int,exitcode)
diff --git a/mdk-stage1/dietlibc/syscalls.c/fchdir.c b/mdk-stage1/dietlibc/syscalls.c/fchdir.c
new file mode 100644
index 000000000..b3a41dc7a
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fchdir.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,fchdir,int,fd)
diff --git a/mdk-stage1/dietlibc/syscalls.c/fchmod.c b/mdk-stage1/dietlibc/syscalls.c/fchmod.c
new file mode 100644
index 000000000..09e52b6c7
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fchmod.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,fchmod,int,filedes,mode_t,mode)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/fchown.c b/mdk-stage1/dietlibc/syscalls.c/fchown.c
new file mode 100644
index 000000000..58923a137
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fchown.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,fchown,int,fd,uid_t,owner,gid_t,group)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/fcntl.c b/mdk-stage1/dietlibc/syscalls.c/fcntl.c
new file mode 100644
index 000000000..b21be9531
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fcntl.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,fcntl,int,fd,int,cmd,long,arg)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/flock.c b/mdk-stage1/dietlibc/syscalls.c/flock.c
new file mode 100644
index 000000000..6fcb336ef
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/flock.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,flock,int,fd,int,op)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/fork.c b/mdk-stage1/dietlibc/syscalls.c/fork.c
new file mode 100644
index 000000000..1d4b892b6
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fork.c
@@ -0,0 +1,6 @@
+#include "syscalls.h"
+
+#ifndef __sparc__
+
+_syscall0(int,fork)
+#endif
diff --git a/mdk-stage1/dietlibc/syscalls.c/fsync.c b/mdk-stage1/dietlibc/syscalls.c/fsync.c
new file mode 100644
index 000000000..db6198b8a
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/fsync.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall1(int,fsync,int,fd)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/ftruncate.c b/mdk-stage1/dietlibc/syscalls.c/ftruncate.c
new file mode 100644
index 000000000..5f002a899
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/ftruncate.c
@@ -0,0 +1,4 @@
+#include <sys/types.h>
+#include "syscalls.h"
+
+_syscall2(int,ftruncate,int,fd,off_t,length)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getcwd.c b/mdk-stage1/dietlibc/syscalls.c/getcwd.c
new file mode 100644
index 000000000..9e5e4a3e2
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getcwd.c
@@ -0,0 +1,5 @@
+#include "syscalls.h"
+
+/* this syscall exists since Linux 2.1.92 */
+
+_syscall2(int,getcwd,char*,buf,unsigned long,size)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getdents.c b/mdk-stage1/dietlibc/syscalls.c/getdents.c
new file mode 100644
index 000000000..be941b21e
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getdents.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int, getdents, unsigned int, fd, void *, dirp, unsigned int, count);
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/getegid.c b/mdk-stage1/dietlibc/syscalls.c/getegid.c
new file mode 100644
index 000000000..3213d640c
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getegid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall0(gid_t,getegid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/geteuid.c b/mdk-stage1/dietlibc/syscalls.c/geteuid.c
new file mode 100644
index 000000000..5b31a3cca
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/geteuid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall0(uid_t,geteuid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getgid.c b/mdk-stage1/dietlibc/syscalls.c/getgid.c
new file mode 100644
index 000000000..2f7d96286
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getgid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall0(gid_t,getgid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getgroups.c b/mdk-stage1/dietlibc/syscalls.c/getgroups.c
new file mode 100644
index 000000000..3e4d6797a
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getgroups.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,getgroups,int,size,int*,list)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getpgid.c b/mdk-stage1/dietlibc/syscalls.c/getpgid.c
new file mode 100644
index 000000000..0b4ff528b
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getpgid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(pid_t,getpgid,pid_t,pid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getpid.c b/mdk-stage1/dietlibc/syscalls.c/getpid.c
new file mode 100644
index 000000000..d60a8db9a
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getpid.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall0(int,getpid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getppid.c b/mdk-stage1/dietlibc/syscalls.c/getppid.c
new file mode 100644
index 000000000..ee87a8eae
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getppid.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall0(int,getppid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getpriority.c b/mdk-stage1/dietlibc/syscalls.c/getpriority.c
new file mode 100644
index 000000000..6f94bcf42
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getpriority.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,getpriority,int,which,int,who)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/getresgid.c b/mdk-stage1/dietlibc/syscalls.c/getresgid.c
new file mode 100644
index 000000000..264ec7dce
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getresgid.c
@@ -0,0 +1,8 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+#ifdef __NR_getresgid
+
+_syscall3(int,getresgid,gid_t*,rgid,gid_t*,egid,gid_t*,sgid)
+
+#endif
diff --git a/mdk-stage1/dietlibc/syscalls.c/getresuid.c b/mdk-stage1/dietlibc/syscalls.c/getresuid.c
new file mode 100644
index 000000000..74e2daec2
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getresuid.c
@@ -0,0 +1,8 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+#ifdef __getresuid
+
+_syscall3(int,getresuid,uid_t*,ruid,uid_t*,euid,uid_t*,suid)
+
+#endif
diff --git a/mdk-stage1/dietlibc/syscalls.c/getrlimit.c b/mdk-stage1/dietlibc/syscalls.c/getrlimit.c
new file mode 100644
index 000000000..635b2baf4
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getrlimit.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,getrlimit,int,resource,void*,rlim)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getrusage.c b/mdk-stage1/dietlibc/syscalls.c/getrusage.c
new file mode 100644
index 000000000..815d3e617
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getrusage.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,getrusage,int,who,void*,rusage)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getsid.c b/mdk-stage1/dietlibc/syscalls.c/getsid.c
new file mode 100644
index 000000000..69974c36c
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getsid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(pid_t,getsid,pid_t,pid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/gettimeofday.c b/mdk-stage1/dietlibc/syscalls.c/gettimeofday.c
new file mode 100644
index 000000000..5f4931a0c
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/gettimeofday.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include <linux/time.h>
+#include "syscalls.h"
+
+_syscall2(int,gettimeofday,struct timeval *,tv,void *,tz)
diff --git a/mdk-stage1/dietlibc/syscalls.c/getuid.c b/mdk-stage1/dietlibc/syscalls.c/getuid.c
new file mode 100644
index 000000000..bf38447a6
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/getuid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall0(uid_t,getuid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/ioctl.c b/mdk-stage1/dietlibc/syscalls.c/ioctl.c
new file mode 100644
index 000000000..1612109d3
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/ioctl.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,ioctl,int,fd,int,request,void *,argp)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/kill.c b/mdk-stage1/dietlibc/syscalls.c/kill.c
new file mode 100644
index 000000000..e56b0ac1b
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/kill.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,kill,pid_t,pid,int,sig)
diff --git a/mdk-stage1/dietlibc/syscalls.c/lchown.c b/mdk-stage1/dietlibc/syscalls.c/lchown.c
new file mode 100644
index 000000000..976d2ee1f
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/lchown.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,lchown,char*,path,uid_t,owner,gid_t,group)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/link.c b/mdk-stage1/dietlibc/syscalls.c/link.c
new file mode 100644
index 000000000..ab9b427d9
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/link.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,link,const char *,a,const char *,b)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/lseek.c b/mdk-stage1/dietlibc/syscalls.c/lseek.c
new file mode 100644
index 000000000..9925a2185
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/lseek.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(unsigned long,lseek,int,fd,unsigned long,offset,int,whence)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/mkdir.c b/mdk-stage1/dietlibc/syscalls.c/mkdir.c
new file mode 100644
index 000000000..aac682c99
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/mkdir.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,mkdir,void*,path,mode_t,mode)
diff --git a/mdk-stage1/dietlibc/syscalls.c/mknod.c b/mdk-stage1/dietlibc/syscalls.c/mknod.c
new file mode 100644
index 000000000..00e836b73
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/mknod.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,mknod,const char*,pathname,mode_t,mode,dev_t,dev)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/mount.c b/mdk-stage1/dietlibc/syscalls.c/mount.c
new file mode 100644
index 000000000..2d71ee812
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/mount.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall5(int,mount,const char *,spec,const char *,dir,const char *,type,unsigned long,rwflag,const void *,data);
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/mprotect.c b/mdk-stage1/dietlibc/syscalls.c/mprotect.c
new file mode 100644
index 000000000..634a12089
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/mprotect.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,mprotect,const void *,addr, size_t, len, int, prot)
diff --git a/mdk-stage1/dietlibc/syscalls.c/mremap.c b/mdk-stage1/dietlibc/syscalls.c/mremap.c
new file mode 100644
index 000000000..37d066bac
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/mremap.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall4(int,mremap,void*,old_address,size_t,old_size,size_t,new_size,unsigned long,flags)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/munmap.c b/mdk-stage1/dietlibc/syscalls.c/munmap.c
new file mode 100644
index 000000000..40bc98270
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/munmap.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,munmap,void*,start,size_t,len)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/nanosleep.c b/mdk-stage1/dietlibc/syscalls.c/nanosleep.c
new file mode 100644
index 000000000..71aca1f09
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/nanosleep.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include <linux/time.h>
+#include "syscalls.h"
+
+_syscall2(int,nanosleep,struct timeval *,in,struct timeval *,out)
diff --git a/mdk-stage1/dietlibc/syscalls.c/open.c b/mdk-stage1/dietlibc/syscalls.c/open.c
new file mode 100644
index 000000000..8b3ccfcc3
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/open.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,open,const char *,fn,int,flags,mode_t,mode)
diff --git a/mdk-stage1/dietlibc/syscalls.c/pipe.c b/mdk-stage1/dietlibc/syscalls.c/pipe.c
new file mode 100644
index 000000000..42197c881
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/pipe.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(int,pipe,int *,filedes)
diff --git a/mdk-stage1/dietlibc/syscalls.c/poll.c b/mdk-stage1/dietlibc/syscalls.c/poll.c
new file mode 100644
index 000000000..10d0d1f78
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/poll.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,poll,void *,ufds,int,nfds,int,timeout)
diff --git a/mdk-stage1/dietlibc/syscalls.c/read.c b/mdk-stage1/dietlibc/syscalls.c/read.c
new file mode 100644
index 000000000..f5532054e
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/read.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall3(int,read,int,fd,const char *,buf,unsigned long,count)
diff --git a/mdk-stage1/dietlibc/syscalls.c/readlink.c b/mdk-stage1/dietlibc/syscalls.c/readlink.c
new file mode 100644
index 000000000..482f8fe27
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/readlink.c
@@ -0,0 +1,5 @@
+#include "syscalls.h"
+#include <linux/types.h>
+
+_syscall3(int,readlink,char*,path,char*,buf,size_t,bufsiz)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/reboot.c b/mdk-stage1/dietlibc/syscalls.c/reboot.c
new file mode 100644
index 000000000..0ad474894
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/reboot.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,reboot,int,magic,int,magic_too,int,flag)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/rename.c b/mdk-stage1/dietlibc/syscalls.c/rename.c
new file mode 100644
index 000000000..f86d50728
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/rename.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,rename,char*,oldpath,char*,newpath)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/rmdir.c b/mdk-stage1/dietlibc/syscalls.c/rmdir.c
new file mode 100644
index 000000000..303885264
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/rmdir.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,rmdir,void*,path)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setdomainname.c b/mdk-stage1/dietlibc/syscalls.c/setdomainname.c
new file mode 100644
index 000000000..83d3aa8b8
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setdomainname.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,setdomainname,const char *,name,int,len)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/setgid.c b/mdk-stage1/dietlibc/syscalls.c/setgid.c
new file mode 100644
index 000000000..1f7263aeb
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setgid.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,setgid,int,gid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setgroups.c b/mdk-stage1/dietlibc/syscalls.c/setgroups.c
new file mode 100644
index 000000000..fed3b85c1
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setgroups.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,setgroups,int,size,const int*,list)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/sethostname.c b/mdk-stage1/dietlibc/syscalls.c/sethostname.c
new file mode 100644
index 000000000..e4b736f87
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sethostname.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall2(int,sethostname,const char *,name,int,len)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/setitimer.c b/mdk-stage1/dietlibc/syscalls.c/setitimer.c
new file mode 100644
index 000000000..28935cab7
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setitimer.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,setitimer,int,which,void *,value,void *,ovalue)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/setpgid.c b/mdk-stage1/dietlibc/syscalls.c/setpgid.c
new file mode 100644
index 000000000..66fbf82dd
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setpgid.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,setpgid,int,name,int,len)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setpriority.c b/mdk-stage1/dietlibc/syscalls.c/setpriority.c
new file mode 100644
index 000000000..bc04227d2
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setpriority.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall3(int,setpriority,int,which,int,who,int,prio)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/setregid.c b/mdk-stage1/dietlibc/syscalls.c/setregid.c
new file mode 100644
index 000000000..c6911aca8
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setregid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,setregid,gid_t,rgid,gid_t,egid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setresgid.c b/mdk-stage1/dietlibc/syscalls.c/setresgid.c
new file mode 100644
index 000000000..817fd2942
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setresgid.c
@@ -0,0 +1,8 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+#ifdef __NR_setresgid
+
+_syscall3(int,setresgid,gid_t*,rgid,gid_t*,egid,gid_t*,sgid)
+
+#endif
diff --git a/mdk-stage1/dietlibc/syscalls.c/setresuid.c b/mdk-stage1/dietlibc/syscalls.c/setresuid.c
new file mode 100644
index 000000000..7073d8ac2
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setresuid.c
@@ -0,0 +1,8 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+#ifdef __NR_setresuid
+
+_syscall3(int,setresuid,uid_t*,ruid,uid_t*,euid,uid_t*,suid)
+
+#endif
diff --git a/mdk-stage1/dietlibc/syscalls.c/setreuid.c b/mdk-stage1/dietlibc/syscalls.c/setreuid.c
new file mode 100644
index 000000000..c0c23a12d
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setreuid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,setreuid,uid_t,ruid,uid_t,euid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setrlimit.c b/mdk-stage1/dietlibc/syscalls.c/setrlimit.c
new file mode 100644
index 000000000..213234282
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setrlimit.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,setrlimit,int,resource,void*,rlim)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setsid.c b/mdk-stage1/dietlibc/syscalls.c/setsid.c
new file mode 100644
index 000000000..4b35a1316
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setsid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall0(pid_t,setsid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/setuid.c b/mdk-stage1/dietlibc/syscalls.c/setuid.c
new file mode 100644
index 000000000..620876c9f
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/setuid.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,setuid,int,uid)
diff --git a/mdk-stage1/dietlibc/syscalls.c/sigaction.c b/mdk-stage1/dietlibc/syscalls.c/sigaction.c
new file mode 100644
index 000000000..cfa5c683f
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sigaction.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall3(int,sigaction,int,signum,void*,act,void*,oldact)
diff --git a/mdk-stage1/dietlibc/syscalls.c/signal.c b/mdk-stage1/dietlibc/syscalls.c/signal.c
new file mode 100644
index 000000000..1a913be45
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/signal.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,signal,int,num,void *,len)
diff --git a/mdk-stage1/dietlibc/syscalls.c/sigpending.c b/mdk-stage1/dietlibc/syscalls.c/sigpending.c
new file mode 100644
index 000000000..08fb23991
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sigpending.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,sigpending,void*,set)
diff --git a/mdk-stage1/dietlibc/syscalls.c/sigprocmask.c b/mdk-stage1/dietlibc/syscalls.c/sigprocmask.c
new file mode 100644
index 000000000..e9dcc2d67
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sigprocmask.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall3(int,sigprocmask,int,how,void*,set,void*,oldset)
diff --git a/mdk-stage1/dietlibc/syscalls.c/sigsuspend.c b/mdk-stage1/dietlibc/syscalls.c/sigsuspend.c
new file mode 100644
index 000000000..0fe90e623
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sigsuspend.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,sigsuspend,void*,mask)
diff --git a/mdk-stage1/dietlibc/syscalls.c/socketcall.c b/mdk-stage1/dietlibc/syscalls.c/socketcall.c
new file mode 100644
index 000000000..eee1ae86d
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/socketcall.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,socketcall,int,code,unsigned long *, args)
diff --git a/mdk-stage1/dietlibc/syscalls.c/swapoff.c b/mdk-stage1/dietlibc/syscalls.c/swapoff.c
new file mode 100644
index 000000000..e1daa89a9
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/swapoff.c
@@ -0,0 +1,4 @@
+#include "syscalls.h"
+
+_syscall1(int,swapoff,const char *,fn)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/swapon.c b/mdk-stage1/dietlibc/syscalls.c/swapon.c
new file mode 100644
index 000000000..543e41e79
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/swapon.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,swapon,const char*,path,int,swapflags)
diff --git a/mdk-stage1/dietlibc/syscalls.c/symlink.c b/mdk-stage1/dietlibc/syscalls.c/symlink.c
new file mode 100644
index 000000000..b3f4d0b1c
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/symlink.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,symlink,const char *,a,const char *,b)
diff --git a/mdk-stage1/dietlibc/syscalls.c/sync.c b/mdk-stage1/dietlibc/syscalls.c/sync.c
new file mode 100644
index 000000000..cca17461f
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/sync.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall0(int,sync)
diff --git a/mdk-stage1/dietlibc/syscalls.c/syslog.c b/mdk-stage1/dietlibc/syscalls.c/syslog.c
new file mode 100644
index 000000000..aace870ea
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/syslog.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall3(int,syslog,int, type, char *, buf, int, len);
diff --git a/mdk-stage1/dietlibc/syscalls.c/time.c b/mdk-stage1/dietlibc/syscalls.c/time.c
new file mode 100644
index 000000000..dc15b28f9
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/time.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(time_t,time,time_t*,path)
diff --git a/mdk-stage1/dietlibc/syscalls.c/truncate.c b/mdk-stage1/dietlibc/syscalls.c/truncate.c
new file mode 100644
index 000000000..721bd7134
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/truncate.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall2(int,truncate,const char*,path,off_t,length)
diff --git a/mdk-stage1/dietlibc/syscalls.c/umask.c b/mdk-stage1/dietlibc/syscalls.c/umask.c
new file mode 100644
index 000000000..506038243
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/umask.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(int,umask,mode_t,mask)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/umount.c b/mdk-stage1/dietlibc/syscalls.c/umount.c
new file mode 100644
index 000000000..4d3ef7637
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/umount.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,umount,const char *,dir)
diff --git a/mdk-stage1/dietlibc/syscalls.c/uname.c b/mdk-stage1/dietlibc/syscalls.c/uname.c
new file mode 100644
index 000000000..68f135007
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/uname.c
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall1(int,uname,void *,utsname)
+
diff --git a/mdk-stage1/dietlibc/syscalls.c/unlink.c b/mdk-stage1/dietlibc/syscalls.c/unlink.c
new file mode 100644
index 000000000..860ccebbf
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/unlink.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall1(int,unlink,const char *,fn)
diff --git a/mdk-stage1/dietlibc/syscalls.c/utime.c b/mdk-stage1/dietlibc/syscalls.c/utime.c
new file mode 100644
index 000000000..185bdf9e8
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/utime.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall2(int,utime,void*,filename,void*,buf)
diff --git a/mdk-stage1/dietlibc/syscalls.c/vhangup.c b/mdk-stage1/dietlibc/syscalls.c/vhangup.c
new file mode 100644
index 000000000..bb0669765
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/vhangup.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall0(int,vhangup)
diff --git a/mdk-stage1/dietlibc/syscalls.c/wait4.c b/mdk-stage1/dietlibc/syscalls.c/wait4.c
new file mode 100644
index 000000000..4ae7eabcd
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/wait4.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall4(int,wait4,pid_t,pid,int *,status,int,opts,void *,rusage)
diff --git a/mdk-stage1/dietlibc/syscalls.c/waitpid.c b/mdk-stage1/dietlibc/syscalls.c/waitpid.c
new file mode 100644
index 000000000..b7167f9ce
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/waitpid.c
@@ -0,0 +1,4 @@
+#include <linux/types.h>
+#include "syscalls.h"
+
+_syscall3(int,waitpid,int,pid,int *,status,int,options)
diff --git a/mdk-stage1/dietlibc/syscalls.c/write.c b/mdk-stage1/dietlibc/syscalls.c/write.c
new file mode 100644
index 000000000..d1f7347d5
--- /dev/null
+++ b/mdk-stage1/dietlibc/syscalls.c/write.c
@@ -0,0 +1,3 @@
+#include "syscalls.h"
+
+_syscall3(int,write,int,fd,const char *,buf,unsigned long,count)