summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getprotoname.c
diff options
context:
space:
mode:
authormillert <>2004-10-17 20:24:23 +0000
committermillert <>2004-10-17 20:24:23 +0000
commiteae90a29f226809527585d7ba688d0af8627db58 (patch)
treebeb43deef803247f4e915dfbd6ef663407e7dd2b /src/lib/libc/net/getprotoname.c
parent91294475ad30114d23728b4a7599c81a0e1a99a3 (diff)
downloadopenbsd-eae90a29f226809527585d7ba688d0af8627db58.tar.gz
openbsd-eae90a29f226809527585d7ba688d0af8627db58.tar.bz2
openbsd-eae90a29f226809527585d7ba688d0af8627db58.zip
Reentrant versions of getprotoent(3) and getservent(3). Adapted from
changes in NetBSD by Christos. OK otto@
Diffstat (limited to 'src/lib/libc/net/getprotoname.c')
-rw-r--r--src/lib/libc/net/getprotoname.c32
1 files changed, 21 insertions, 11 deletions
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 @@
28 */ 28 */
29 29
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; 31static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.5 2004/10/17 20:24:23 millert Exp $";
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <netdb.h> 34#include <netdb.h>
35#include <stdio.h>
35#include <string.h> 36#include <string.h>
36 37
37extern int _proto_stayopen;
38
39struct protoent * 38struct protoent *
40getprotobyname(name) 39getprotobyname_r(const char *name, struct protoent *pe,
41 register const char *name; 40 struct protoent_data *pd)
42{ 41{
43 register struct protoent *p; 42 struct protoent *p;
44 register char **cp; 43 char **cp;
45 44
46 setprotoent(_proto_stayopen); 45 setprotoent_r(pd->stayopen, pd);
47 while ((p = getprotoent())) { 46 while ((p = getprotoent_r(pe, pd))) {
48 if (strcmp(p->p_name, name) == 0) 47 if (strcmp(p->p_name, name) == 0)
49 break; 48 break;
50 for (cp = p->p_aliases; *cp != 0; cp++) 49 for (cp = p->p_aliases; *cp != 0; cp++)
@@ -52,7 +51,18 @@ getprotobyname(name)
52 goto found; 51 goto found;
53 } 52 }
54found: 53found:
55 if (!_proto_stayopen) 54 if (!pd->stayopen && pd->fp != NULL) {
56 endprotoent(); 55 fclose(pd->fp);
56 pd->fp = NULL;
57 }
57 return (p); 58 return (p);
58} 59}
60
61struct protoent *
62getprotobyname(const char *name)
63{
64 extern struct protoent_data _protoent_data;
65 static struct protoent proto;
66
67 return getprotobyname_r(name, &proto, &_protoent_data);
68}