From eae90a29f226809527585d7ba688d0af8627db58 Mon Sep 17 00:00:00 2001 From: millert <> Date: Sun, 17 Oct 2004 20:24:23 +0000 Subject: Reentrant versions of getprotoent(3) and getservent(3). Adapted from changes in NetBSD by Christos. OK otto@ --- src/lib/libc/net/getprotoname.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/lib/libc/net/getprotoname.c') diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c index 4742a60a04..429304e7a1 100644 --- a/src/lib/libc/net/getprotoname.c +++ b/src/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 +#include #include -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); +} -- cgit v1.2.3-55-g6feb