diff options
Diffstat (limited to 'src/lib/libc/net/getservbyname.c')
-rw-r--r-- | src/lib/libc/net/getservbyname.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c index b4a6311966..beb8943af6 100644 --- a/src/lib/libc/net/getservbyname.c +++ b/src/lib/libc/net/getservbyname.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* $NetBSD: getservbyname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */ | 1 | /* $OpenBSD: getservbyname.c,v 1.10 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,39 +28,43 @@ | |||
33 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
34 | */ | 29 | */ |
35 | 30 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
37 | #if 0 | ||
38 | static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getservbyname.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 _serv_stayopen; | 35 | int |
48 | 36 | getservbyname_r(const char *name, const char *proto, struct servent *se, | |
49 | struct servent * | 37 | struct servent_data *sd) |
50 | getservbyname(name, proto) | ||
51 | const char *name, *proto; | ||
52 | { | 38 | { |
53 | register struct servent *p; | 39 | char **cp; |
54 | register char **cp; | 40 | int error; |
55 | 41 | ||
56 | setservent(_serv_stayopen); | 42 | setservent_r(sd->stayopen, sd); |
57 | while (p = getservent()) { | 43 | while ((error = getservent_r(se, sd)) == 0) { |
58 | if (strcmp(name, p->s_name) == 0) | 44 | if (strcmp(name, se->s_name) == 0) |
59 | goto gotname; | 45 | goto gotname; |
60 | for (cp = p->s_aliases; *cp; cp++) | 46 | for (cp = se->s_aliases; *cp; cp++) |
61 | if (strcmp(name, *cp) == 0) | 47 | if (strcmp(name, *cp) == 0) |
62 | goto gotname; | 48 | goto gotname; |
63 | continue; | 49 | continue; |
64 | gotname: | 50 | gotname: |
65 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 51 | if (proto == 0 || strcmp(se->s_proto, proto) == 0) |
66 | break; | 52 | break; |
67 | } | 53 | } |
68 | if (!_serv_stayopen) | 54 | if (!sd->stayopen && sd->fp != NULL) { |
69 | endservent(); | 55 | fclose(sd->fp); |
70 | return (p); | 56 | sd->fp = NULL; |
57 | } | ||
58 | return (error); | ||
59 | } | ||
60 | |||
61 | struct servent * | ||
62 | getservbyname(const char *name, const char *proto) | ||
63 | { | ||
64 | extern struct servent_data _servent_data; | ||
65 | static struct servent serv; | ||
66 | |||
67 | if (getservbyname_r(name, proto, &serv, &_servent_data) != 0) | ||
68 | return (NULL); | ||
69 | return (&serv); | ||
71 | } | 70 | } |