diff options
author | millert <> | 2004-10-25 03:09:01 +0000 |
---|---|---|
committer | millert <> | 2004-10-25 03:09:01 +0000 |
commit | 42489d4b990a8793c837811c34a869ec16d055ba (patch) | |
tree | 36483a751887031181b8128f629bde9b388ecac4 /src/lib/libc/net/getservbyport.c | |
parent | eae90a29f226809527585d7ba688d0af8627db58 (diff) | |
download | openbsd-42489d4b990a8793c837811c34a869ec16d055ba.tar.gz openbsd-42489d4b990a8793c837811c34a869ec16d055ba.tar.bz2 openbsd-42489d4b990a8793c837811c34a869ec16d055ba.zip |
Change return value of reentrant getproto* and getserv* to match the
IBM/Digital API.
Diffstat (limited to 'src/lib/libc/net/getservbyport.c')
-rw-r--r-- | src/lib/libc/net/getservbyport.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c index e8b8efc504..5e210b2e8b 100644 --- a/src/lib/libc/net/getservbyport.c +++ b/src/lib/libc/net/getservbyport.c | |||
@@ -28,31 +28,31 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getservbyport.c,v 1.5 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getservbyport.c,v 1.6 2004/10/25 03:09:01 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 <stdio.h> |
36 | #include <string.h> | 36 | #include <string.h> |
37 | 37 | ||
38 | struct servent * | 38 | int |
39 | getservbyport_r(int port, const char *proto, struct servent *se, | 39 | getservbyport_r(int port, const char *proto, struct servent *se, |
40 | struct servent_data *sd) | 40 | struct servent_data *sd) |
41 | { | 41 | { |
42 | struct servent *p; | 42 | int error; |
43 | 43 | ||
44 | setservent_r(sd->stayopen, sd); | 44 | setservent_r(sd->stayopen, sd); |
45 | while ((p = getservent_r(se, sd))) { | 45 | while ((error = getservent_r(se, sd)) == 0) { |
46 | if (p->s_port != port) | 46 | if (se->s_port != port) |
47 | continue; | 47 | continue; |
48 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 48 | if (proto == 0 || strcmp(se->s_proto, proto) == 0) |
49 | break; | 49 | break; |
50 | } | 50 | } |
51 | if (!sd->stayopen && sd->fp != NULL) { | 51 | if (!sd->stayopen && sd->fp != NULL) { |
52 | fclose(sd->fp); | 52 | fclose(sd->fp); |
53 | sd->fp = NULL; | 53 | sd->fp = NULL; |
54 | } | 54 | } |
55 | return (p); | 55 | return (error); |
56 | } | 56 | } |
57 | 57 | ||
58 | struct servent * | 58 | struct servent * |
@@ -61,5 +61,7 @@ getservbyport(int port, const char *proto) | |||
61 | extern struct servent_data _servent_data; | 61 | extern struct servent_data _servent_data; |
62 | static struct servent serv; | 62 | static struct servent serv; |
63 | 63 | ||
64 | return (getservbyport_r(port, proto, &serv, &_servent_data)); | 64 | if (getservbyport_r(port, proto, &serv, &_servent_data) != 0) |
65 | return (NULL); | ||
66 | return (&serv); | ||
65 | } | 67 | } |