diff options
Diffstat (limited to 'src/lib/libc/net/getprotoname.c')
-rw-r--r-- | src/lib/libc/net/getprotoname.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c index 4f8cf21c3f..749b6b3f13 100644 --- a/src/lib/libc/net/getprotoname.c +++ b/src/lib/libc/net/getprotoname.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* $NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */ | 1 | /* $OpenBSD: getprotoname.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ |
2 | |||
3 | /* | 2 | /* |
4 | * Copyright (c) 1983, 1993 | 3 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -12,11 +11,7 @@ | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by the University of | ||
18 | * California, Berkeley and its contributors. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | 15 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 16 | * without specific prior written permission. |
22 | * | 17 | * |
@@ -33,36 +28,40 @@ | |||
33 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
34 | */ | 29 | */ |
35 | 30 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
37 | #if 0 | ||
38 | static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | ||
43 | |||
44 | #include <netdb.h> | 31 | #include <netdb.h> |
32 | #include <stdio.h> | ||
45 | #include <string.h> | 33 | #include <string.h> |
46 | 34 | ||
47 | extern int _proto_stayopen; | 35 | int |
48 | 36 | getprotobyname_r(const char *name, struct protoent *pe, | |
49 | struct protoent * | 37 | struct protoent_data *pd) |
50 | getprotobyname(name) | ||
51 | register const char *name; | ||
52 | { | 38 | { |
53 | register struct protoent *p; | 39 | char **cp; |
54 | register char **cp; | 40 | int error; |
55 | 41 | ||
56 | setprotoent(_proto_stayopen); | 42 | setprotoent_r(pd->stayopen, pd); |
57 | while (p = getprotoent()) { | 43 | while ((error = getprotoent_r(pe, pd)) == 0) { |
58 | if (strcmp(p->p_name, name) == 0) | 44 | if (strcmp(pe->p_name, name) == 0) |
59 | break; | 45 | break; |
60 | for (cp = p->p_aliases; *cp != 0; cp++) | 46 | for (cp = pe->p_aliases; *cp != 0; cp++) |
61 | if (strcmp(*cp, name) == 0) | 47 | if (strcmp(*cp, name) == 0) |
62 | goto found; | 48 | goto found; |
63 | } | 49 | } |
64 | found: | 50 | found: |
65 | if (!_proto_stayopen) | 51 | if (!pd->stayopen && pd->fp != NULL) { |
66 | endprotoent(); | 52 | fclose(pd->fp); |
67 | return (p); | 53 | pd->fp = NULL; |
54 | } | ||
55 | return (error); | ||
56 | } | ||
57 | |||
58 | struct protoent * | ||
59 | getprotobyname(const char *name) | ||
60 | { | ||
61 | extern struct protoent_data _protoent_data; | ||
62 | static struct protoent proto; | ||
63 | |||
64 | if (getprotobyname_r(name, &proto, &_protoent_data) != 0) | ||
65 | return (NULL); | ||
66 | return (&proto); | ||
68 | } | 67 | } |