diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:47:09 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:47:09 +0000 |
commit | c46806bf74c2618daa398cb7c3e4b1c47509a105 (patch) | |
tree | 0b429074ffc365e7eba2391cf00d7f4eecf372ab /mdk-stage1/dietlibc/lib/getservent.c | |
parent | 7b14ca284d598e7748f6f7a831389525c84890ba (diff) | |
download | drakx-c46806bf74c2618daa398cb7c3e4b1c47509a105.tar drakx-c46806bf74c2618daa398cb7c3e4b1c47509a105.tar.gz drakx-c46806bf74c2618daa398cb7c3e4b1c47509a105.tar.bz2 drakx-c46806bf74c2618daa398cb7c3e4b1c47509a105.tar.xz drakx-c46806bf74c2618daa398cb7c3e4b1c47509a105.zip |
even more removals
Diffstat (limited to 'mdk-stage1/dietlibc/lib/getservent.c')
-rw-r--r-- | mdk-stage1/dietlibc/lib/getservent.c | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/mdk-stage1/dietlibc/lib/getservent.c b/mdk-stage1/dietlibc/lib/getservent.c deleted file mode 100644 index bf25d046b..000000000 --- a/mdk-stage1/dietlibc/lib/getservent.c +++ /dev/null @@ -1,137 +0,0 @@ -#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 servicesfd=-1; -static char* servicesmap; -static unsigned int serviceslen; - -static char* aliases[10]; - -static char *cur; - -/* nameserver 42/tcp name # IEN 116 */ -struct servent *getservent(void) { - static struct servent se; - char *last; - int aliasidx; - if (servicesfd<0) { - servicesfd=open(_PATH_SERVICES,O_RDONLY); - if (servicesfd<0) return 0; - serviceslen=lseek(servicesfd,0,SEEK_END); - servicesmap=mmap(0,serviceslen,PROT_READ|PROT_WRITE,MAP_PRIVATE,servicesfd,0); - if ((long)servicesmap==(-1)) goto error; - cur=servicesmap; - } - last=servicesmap+serviceslen; -again: - se.s_name=0; - se.s_aliases=aliases; aliases[0]=0; - se.s_port=0; - se.s_proto=0; - if (cur>=last) return 0; - if (*cur=='#' || *cur=='\n') goto parseerror; - /* first, the primary name */ - if (!isalpha(*cur)) goto parseerror; - se.s_name=cur; - se.s_aliases=aliases; - while (cur<last && isalnum(*cur)) cur++; - if (cur>=last) return 0; - if (*cur=='\n') goto parseerror; - *cur=0; cur++; - /* second, the port */ - while (cur<last && isblank(*cur)) cur++; - while (cur<last && isdigit(*cur)) { - se.s_port=se.s_port*10+*cur-'0'; - cur++; - } - se.s_port=htons(se.s_port); - if (cur>=last) return 0; - /* third, "/tcp" or "/udp" */ - if (*cur!='/') goto parseerror; - cur++; - se.s_proto=cur; - while (cur<last && isalpha(*cur)) ++cur; - if (cur>=last) return 0; - if (*cur=='\n') { *cur++=0; return &se; } - *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 &se; -parseerror: - while (cur<last && *cur!='\n') cur++; - cur++; - goto again; -error: - if (servicesmap!=(char*)-1) munmap(servicesmap,serviceslen); - if (servicesfd!=-1) close(servicesfd); - servicesmap=(char*)-1; - servicesfd=-1; - errno=ENOMEM; - return 0; -} - -void setservent(int stayopen) { - cur=servicesmap; -} - -struct servent *getservbyname(const char *name, const char *proto) { - struct servent *s; - setservent(0); - for (s=getservent(); s; s=getservent()) { - char **tmp; -#if 0 - write(1,"found ",6); - write(1,s->s_name,strlen(s->s_name)); - write(1,"/",1); - write(1,s->s_proto,strlen(s->s_proto)); - write(1,"\n",1); - if (!strcmp(name,"auth")) { - tmp=s->s_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->s_name) && !strcmp(proto,s->s_proto)) - return s; - tmp=s->s_aliases; - while (*tmp) - if (!strcmp(name,*tmp++)) return s; - } - return 0; -} - -struct servent *getservbyport(int port, const char *proto) { - struct servent *s; - for (s=getservent(); s; s=getservent()) { - if (port==s->s_port && !strcmp(proto,s->s_proto)) - return s; - } - return 0; -} - -void endservent(void) { - if (servicesmap!=(char*)-1) munmap(servicesmap,serviceslen); - if (servicesfd!=-1) close(servicesfd); - servicesmap=(char*)-1; - servicesfd=-1; -} - |