summaryrefslogtreecommitdiff
path: root/lib/libc/net/getproto.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-10-17 20:24:24 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-10-17 20:24:24 +0000
commit6119135c871cdb14d2c537be99ec398e13edf027 (patch)
tree0dd5c7c99caa44c2ea5e7debe0d7beb2abf79729 /lib/libc/net/getproto.c
parentee9ebb877e4b54f13e03b0aea8679e04c928043f (diff)
Reentrant versions of getprotoent(3) and getservent(3). Adapted from
changes in NetBSD by Christos. OK otto@
Diffstat (limited to 'lib/libc/net/getproto.c')
-rw-r--r--lib/libc/net/getproto.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/libc/net/getproto.c b/lib/libc/net/getproto.c
index dee089d5c2c..3f05a93cce6 100644
--- a/lib/libc/net/getproto.c
+++ b/lib/libc/net/getproto.c
@@ -28,24 +28,33 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getproto.c,v 1.4 2003/06/02 20:18:35 millert Exp $";
+static char rcsid[] = "$OpenBSD: getproto.c,v 1.5 2004/10/17 20:24:23 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <netdb.h>
-
-extern int _proto_stayopen;
+#include <stdio.h>
struct protoent *
-getprotobynumber(proto)
- register int proto;
+getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd)
{
- register struct protoent *p;
+ struct protoent *p;
- setprotoent(_proto_stayopen);
- while ((p = getprotoent()))
- if (p->p_proto == proto)
+ setprotoent_r(pd->stayopen, pd);
+ while ((p = getprotoent_r(pe, pd)))
+ if (p->p_proto == num)
break;
- if (!_proto_stayopen)
- endprotoent();
+ if (!pd->stayopen && pd->fp != NULL) {
+ (void)fclose(pd->fp);
+ pd->fp = NULL;
+ }
return (p);
}
+
+struct protoent *
+getprotobynumber(int num)
+{
+ extern struct protoent_data _protoent_data;
+ static struct protoent proto;
+
+ return getprotobynumber_r(num, &proto, &_protoent_data);
+}