From: brian Date: Thu, 1 Jul 2004 01:13:48 +0000 (-0700) Subject: use newlib/libc/unix X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=commitdiff_plain;h=b0b715081de3e55b4d60b18a277b73ebaedd4a6f use newlib/libc/unix darcs-hash:20040701011348-24bed-d0ce15da4df323ecb8890cd9c24c326f1066f3a9.gz --- diff --git a/src/org/ibex/nestedvm/support_aux.c b/src/org/ibex/nestedvm/support_aux.c index 603f6ee..51251e7 100644 --- a/src/org/ibex/nestedvm/support_aux.c +++ b/src/org/ibex/nestedvm/support_aux.c @@ -193,16 +193,6 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) { return 0; } -int sigfillset(sigset_t *set) { - *set = ~((sigset_t)0); - return 0; -} - -int sigemptyset(sigset_t *set) { - *set = (sigset_t) 0; - return 0; -} - DIR *opendir(const char *path) { struct stat sb; int fd; @@ -345,6 +335,189 @@ struct hostent *gethostbyname(const char *hostname) { return &hostent; } +static struct passwd pw_passwd; +static struct group gr_group; +static FILE *passwd_fp; +static FILE *group_fp; +static char pw_name[1024]; +static char pw_password[1024]; +static char pw_gecos[1024]; +static char pw_dir[1024]; +static char pw_shell[1024]; +static char gr_name[1024]; +static char gr_passwd[1024]; +static char *gr_mem[1]; + +static int gr_parse_body(const char *buf) { + if(sscanf(buf,"%[^:]:%[^:]:%hu",gr_name,gr_passwd,&gr_group.gr_gid) < 3) return -1; + gr_group.gr_name = gr_name; + gr_group.gr_passwd = gr_passwd; + gr_group.gr_mem = gr_mem; + gr_mem[0] = NULL; + return 0; +} + +static int pw_parse_body(const char *buf) { + int pos; + if(sscanf(buf,"%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",pw_name,pw_password,&pw_passwd.pw_uid,&pw_passwd.pw_gid,pw_gecos,pw_dir,pw_shell) < 7) return -1; + pw_passwd.pw_name = pw_name; + pw_passwd.pw_passwd = pw_password; + pw_passwd.pw_gecos = pw_gecos; + pw_passwd.pw_dir = pw_dir; + pw_passwd.pw_shell = pw_shell; + pw_passwd.pw_comment = ""; + return 0; +} + +struct group *getgrnam(const char *name) { + FILE *fp; + char buf[1024]; + + if((fp=fopen("/etc/group","r"))==NULL) return NULL; + while(fgets(buf,sizeof(buf),fp)) { + if(buf[0] == '#') continue; + if(gr_parse_body(buf) < 0) { + fclose(fp); + return NULL; + } + if(strcmp(name,gr_name)==0) { + fclose(fp); + return &gr_group; + } + } + fclose(fp); + return NULL; +} + +struct group *getgrgid(gid_t gid) { + FILE *fp; + char buf[1024]; + + if((fp=fopen("/etc/group","r"))==NULL) return NULL; + while(fgets(buf,sizeof(buf),fp)) { + if(buf[0] == '#') continue; + if(gr_parse_body(buf) < 0) { + fclose(fp); + return NULL; + } + if(gid == gr_group.gr_gid) { + fclose(fp); + return &gr_group; + } + } + fclose(fp); + return NULL; +} + +struct group *getgrent() { + char buf[1024]; + if(group_fp == NULL) return NULL; + if(fgets(buf,sizeof(buf),group_fp) == NULL) return NULL; + if(buf[0] == '#') return getgrent(); + if(gr_parse_body(buf) < 0) return NULL; + return &gr_group; +} + +void setgrent() { + if(group_fp != NULL) fclose(group_fp); + group_fp = fopen("/etc/group","r"); +} + +void endgrent() { + if(group_fp != NULL) fclose(group_fp); + group_fp = NULL; +} + +struct passwd *getpwnam(const char *name) { + FILE *fp; + char buf[1024]; + + if((fp=fopen("/etc/passwd","r"))==NULL) return NULL; + while(fgets(buf,sizeof(buf),fp)) { + if(buf[0] == '#') continue; + if(pw_parse_body(buf) < 0) { + fclose(fp); + return NULL; + } + if(strcmp(name,pw_name)==0) { + fclose(fp); + return &pw_passwd; + } + } + fclose(fp); + return NULL; +} + +struct passwd *getpwuid(uid_t uid) { + FILE *fp; + char buf[1024]; + + if((fp=fopen("/etc/passwd","r"))==NULL) return NULL; + while(fgets(buf,sizeof(buf),fp)) { + if(buf[0] == '#') continue; + if(pw_parse_body(buf) < 0) { + fclose(fp); + return NULL; + } + if(uid == pw_passwd.pw_uid) { + fclose(fp); + return &pw_passwd; + } + } + fclose(fp); + return NULL; +} + +struct passwd *getpwent() { + char buf[1024]; + if(passwd_fp == NULL) return NULL; + if(fgets(buf,sizeof(buf),passwd_fp) == NULL) return NULL; + if(buf[0] == '#') return getpwent(); + if(pw_parse_body(buf) < 0) return NULL; + return &pw_passwd; +} + +void setpwent() { + if(passwd_fp != NULL) fclose(passwd_fp); + passwd_fp = fopen("/etc/group","r"); +} + +void endpwent() { + if(passwd_fp != NULL) fclose(passwd_fp); + passwd_fp = NULL; +} + +char *getpass(const char *prompt) { + static char buf[1024]; + int len = 0; + fputs(prompt,stderr); + fflush(stdout); + if(fgets(buf,sizeof(buf),stdin)!=NULL) { + len = strlen(buf); + if(buf[len-1] == '\n') len--; + } + fputc('\n',stderr); + buf[len] = '\0'; + return buf; +} + +/* Argh... newlib's asprintf is totally broken... */ +int vasprintf(char **ret, const char *fmt, va_list ap) { + int n; + char *p; + *ret = malloc(128); /* just guess for now */ + if(!*ret) return -1; + n = vsnprintf(*ret,128,fmt,ap); + if(n < 128) { + return n; + } else { + p = realloc(*ret,n+1); + if(!p) { free(*ret); return -1; } + return vsprintf(*ret = p,fmt,ap); + } +} + + /* * Other People's Code */ diff --git a/upstream/Makefile b/upstream/Makefile index 4ba354d..194c05a 100644 --- a/upstream/Makefile +++ b/upstream/Makefile @@ -23,7 +23,7 @@ configure_binutils = --target=mips-unknown-elf version_newlib = 1.11.0 url_newlib = http://mirrors.rcn.net/pub/sourceware/newlib/newlib-$(version_newlib).tar.gz -patches_newlib = newlib-mips.patch newlib-tzset.patch newlib-malloc.patch newlib-vasprintf.patch newlib-nomemcpy.patch +patches_newlib = newlib-mips.patch newlib-tzset.patch newlib-malloc.patch newlib-nomemcpy.patch newlib-unix.patch configure_newlib = --enable-multilib --target=mips-unknown-elf url_openbsdglob = http://www.brianweb.net/xwt/openbsdglob.tar.gz diff --git a/upstream/patches/busybox.patch b/upstream/patches/busybox.patch index 0e23b8f..3d13b5f 100644 --- a/upstream/patches/busybox.patch +++ b/upstream/patches/busybox.patch @@ -954,7 +954,7 @@ diff -ur ../busybox-1.00-pre9.orig/util-linux/more.c ./util-linux/more.c +# +# Login/Password Management Utilities +# -+CONFIG_USE_BB_PWD_GRP=y ++# CONFIG_USE_BB_PWD_GRP=y +# CONFIG_ADDGROUP is not set +# CONFIG_DELGROUP is not set +# CONFIG_ADDUSER is not set diff --git a/upstream/patches/newlib-mips.patch b/upstream/patches/newlib-mips.patch index 3cca991..fda257c 100644 --- a/upstream/patches/newlib-mips.patch +++ b/upstream/patches/newlib-mips.patch @@ -95,7 +95,7 @@ diff -urN ../newlib-1.11.0.orig/newlib/configure.host ./newlib/configure.host sys_dir=decstation ;; + mips-unknown-elf*) -+ posix_dir=posix ++ posix_dir=posix; unix_dir=unix + ;; mmix-knuth-mmixware) sys_dir=mmixware diff --git a/upstream/patches/newlib-vasprintf.patch b/upstream/patches/newlib-vasprintf.patch deleted file mode 100644 index dfdf393..0000000 --- a/upstream/patches/newlib-vasprintf.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- newlib/libc/stdio/Makefile.in~ 2004-05-07 03:54:24.000000000 -0400 -+++ newlib/libc/stdio/Makefile.in 2004-05-07 03:54:24.000000000 -0400 -@@ -183,6 +183,7 @@ - @ELIX_LEVEL_1_TRUE@LIB_OBJS = - @ELIX_LEVEL_1_FALSE@LIB_OBJS = @ELIX_LEVEL_1_FALSE@\ - @ELIX_LEVEL_1_FALSE@ asprintf.$(oext) \ -+@ELIX_LEVEL_1_FALSE@ vasprintf.$(oext) \ - @ELIX_LEVEL_1_FALSE@ fcloseall.$(oext) \ - @ELIX_LEVEL_1_FALSE@ fseeko.$(oext) \ - @ELIX_LEVEL_1_FALSE@ ftello.$(oext) \