summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getprotoname.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2004-10-17 20:24:23 +0000
committermillert <millert@openbsd.org>2004-10-17 20:24:23 +0000
commit71a18e7f07f550b8266ab3b0f1532451d027c9d6 (patch)
treef0f779f79a49f49e8967e822275e3d1f22534cc9 /lib/libc/net/getprotoname.c
parentExpose dl_iterate_phdr. (diff)
downloadwireguard-openbsd-71a18e7f07f550b8266ab3b0f1532451d027c9d6.tar.xz
wireguard-openbsd-71a18e7f07f550b8266ab3b0f1532451d027c9d6.zip
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.c32
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);
+}