diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-10-17 20:24:24 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-10-17 20:24:24 +0000 |
commit | 6119135c871cdb14d2c537be99ec398e13edf027 (patch) | |
tree | 0dd5c7c99caa44c2ea5e7debe0d7beb2abf79729 /lib/libc/net/getprotoname.c | |
parent | ee9ebb877e4b54f13e03b0aea8679e04c928043f (diff) |
Reentrant versions of getprotoent(3) and getservent(3). Adapted from
changes in NetBSD by Christos. OK otto@
Diffstat (limited to 'lib/libc/net/getprotoname.c')
-rw-r--r-- | lib/libc/net/getprotoname.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/libc/net/getprotoname.c b/lib/libc/net/getprotoname.c index 4742a60a04b..429304e7a1c 100644 --- a/lib/libc/net/getprotoname.c +++ b/lib/libc/net/getprotoname.c @@ -28,23 +28,22 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; +static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.5 2004/10/17 20:24:23 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <netdb.h> +#include <stdio.h> #include <string.h> -extern int _proto_stayopen; - struct protoent * -getprotobyname(name) - register const char *name; +getprotobyname_r(const char *name, struct protoent *pe, + struct protoent_data *pd) { - register struct protoent *p; - register char **cp; + struct protoent *p; + char **cp; - setprotoent(_proto_stayopen); - while ((p = getprotoent())) { + setprotoent_r(pd->stayopen, pd); + while ((p = getprotoent_r(pe, pd))) { if (strcmp(p->p_name, name) == 0) break; for (cp = p->p_aliases; *cp != 0; cp++) @@ -52,7 +51,18 @@ getprotobyname(name) goto found; } found: - if (!_proto_stayopen) - endprotoent(); + if (!pd->stayopen && pd->fp != NULL) { + fclose(pd->fp); + pd->fp = NULL; + } return (p); } + +struct protoent * +getprotobyname(const char *name) +{ + extern struct protoent_data _protoent_data; + static struct protoent proto; + + return getprotobyname_r(name, &proto, &_protoent_data); +} |