diff options
author | millert <> | 2004-10-17 20:24:23 +0000 |
---|---|---|
committer | millert <> | 2004-10-17 20:24:23 +0000 |
commit | eae90a29f226809527585d7ba688d0af8627db58 (patch) | |
tree | beb43deef803247f4e915dfbd6ef663407e7dd2b /src/lib/libc/net/getprotoname.c | |
parent | 91294475ad30114d23728b4a7599c81a0e1a99a3 (diff) | |
download | openbsd-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.c | 32 |
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) |
31 | static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; | 31 | static 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 | ||
37 | extern int _proto_stayopen; | ||
38 | |||
39 | struct protoent * | 38 | struct protoent * |
40 | getprotobyname(name) | 39 | getprotobyname_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 | } |
54 | found: | 53 | found: |
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 | |||
61 | struct protoent * | ||
62 | getprotobyname(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 | } | ||