diff options
-rw-r--r-- | src/lib/libc/net/getproto.c | 16 | ||||
-rw-r--r-- | src/lib/libc/net/getprotoent.3 | 28 | ||||
-rw-r--r-- | src/lib/libc/net/getprotoent.c | 20 | ||||
-rw-r--r-- | src/lib/libc/net/getprotoname.c | 18 | ||||
-rw-r--r-- | src/lib/libc/net/getservbyname.c | 20 | ||||
-rw-r--r-- | src/lib/libc/net/getservbyport.c | 18 | ||||
-rw-r--r-- | src/lib/libc/net/getservent.3 | 30 | ||||
-rw-r--r-- | src/lib/libc/net/getservent.c | 20 |
8 files changed, 105 insertions, 65 deletions
diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c index 3f05a93cce..16d840394c 100644 --- a/src/lib/libc/net/getproto.c +++ b/src/lib/libc/net/getproto.c | |||
@@ -28,26 +28,26 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getproto.c,v 1.5 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getproto.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 | 36 | ||
37 | struct protoent * | 37 | int |
38 | getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) | 38 | getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) |
39 | { | 39 | { |
40 | struct protoent *p; | 40 | int error; |
41 | 41 | ||
42 | setprotoent_r(pd->stayopen, pd); | 42 | setprotoent_r(pd->stayopen, pd); |
43 | while ((p = getprotoent_r(pe, pd))) | 43 | while ((error = getprotoent_r(pe, pd)) == 0) |
44 | if (p->p_proto == num) | 44 | if (pe->p_proto == num) |
45 | break; | 45 | break; |
46 | if (!pd->stayopen && pd->fp != NULL) { | 46 | if (!pd->stayopen && pd->fp != NULL) { |
47 | (void)fclose(pd->fp); | 47 | (void)fclose(pd->fp); |
48 | pd->fp = NULL; | 48 | pd->fp = NULL; |
49 | } | 49 | } |
50 | return (p); | 50 | return (error); |
51 | } | 51 | } |
52 | 52 | ||
53 | struct protoent * | 53 | struct protoent * |
@@ -56,5 +56,7 @@ getprotobynumber(int num) | |||
56 | extern struct protoent_data _protoent_data; | 56 | extern struct protoent_data _protoent_data; |
57 | static struct protoent proto; | 57 | static struct protoent proto; |
58 | 58 | ||
59 | return getprotobynumber_r(num, &proto, &_protoent_data); | 59 | if (getprotobynumber_r(num, &proto, &_protoent_data) != 0) |
60 | return (NULL); | ||
61 | return (&proto); | ||
60 | } | 62 | } |
diff --git a/src/lib/libc/net/getprotoent.3 b/src/lib/libc/net/getprotoent.3 index 2497f9f7ca..5ebd03cc45 100644 --- a/src/lib/libc/net/getprotoent.3 +++ b/src/lib/libc/net/getprotoent.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getprotoent.3,v 1.11 2004/10/17 20:24:23 millert Exp $ | 1 | .\" $OpenBSD: getprotoent.3,v 1.12 2004/10/25 03:09:01 millert Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -46,15 +46,15 @@ | |||
46 | .Fd #include <netdb.h> | 46 | .Fd #include <netdb.h> |
47 | .Ft struct protoent * | 47 | .Ft struct protoent * |
48 | .Fn getprotoent "void" | 48 | .Fn getprotoent "void" |
49 | .Ft struct protoent * | 49 | .Ft int |
50 | .Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" | 50 | .Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" |
51 | .Ft struct protoent * | 51 | .Ft struct protoent * |
52 | .Fn getprotobyname "const char *name" | 52 | .Fn getprotobyname "const char *name" |
53 | .Ft struct protoent * | 53 | .Ft int |
54 | .Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" | 54 | .Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" |
55 | .Ft struct protoent * | 55 | .Ft struct protoent * |
56 | .Fn getprotobynumber "int proto" | 56 | .Fn getprotobynumber "int proto" |
57 | .Ft struct protoent * | 57 | .Ft int |
58 | .Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" | 58 | .Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" |
59 | .Ft void | 59 | .Ft void |
60 | .Fn setprotoent "int stayopen" | 60 | .Fn setprotoent "int stayopen" |
@@ -144,9 +144,23 @@ also take a pointer to a | |||
144 | .Fa protoent | 144 | .Fa protoent |
145 | structure which is used to store the results of the database lookup. | 145 | structure which is used to store the results of the database lookup. |
146 | .Sh RETURN VALUES | 146 | .Sh RETURN VALUES |
147 | Null pointer (0) returned on | 147 | The |
148 | .Dv EOF | 148 | .Fn getprotoent , |
149 | or error. | 149 | .Fn getprotobyport , |
150 | and | ||
151 | .Fn getprotobyname | ||
152 | functions return a pointer to a | ||
153 | .Fa servent | ||
154 | structure on success or a null pointer if end-of-file | ||
155 | is reached or an error occurs. | ||
156 | .Pp | ||
157 | The | ||
158 | .Fn getprotoent_r , | ||
159 | .Fn getprotobyport_r , | ||
160 | and | ||
161 | .Fn getprotobyname_r | ||
162 | functions return 0 on success or \-1 if end-of-file | ||
163 | is reached or an error occurs. | ||
150 | .Sh FILES | 164 | .Sh FILES |
151 | .Bl -tag -width /etc/protocols -compact | 165 | .Bl -tag -width /etc/protocols -compact |
152 | .It Pa /etc/protocols | 166 | .It Pa /etc/protocols |
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index f3327db9bd..7e93d233ef 100644 --- a/src/lib/libc/net/getprotoent.c +++ b/src/lib/libc/net/getprotoent.c | |||
@@ -28,7 +28,7 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.6 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.7 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 <sys/types.h> | 34 | #include <sys/types.h> |
@@ -65,7 +65,7 @@ endprotoent_r(struct protoent_data *pd) | |||
65 | pd->stayopen = 0; | 65 | pd->stayopen = 0; |
66 | } | 66 | } |
67 | 67 | ||
68 | struct protoent * | 68 | int |
69 | getprotoent_r(struct protoent *pe, struct protoent_data *pd) | 69 | getprotoent_r(struct protoent *pe, struct protoent_data *pd) |
70 | { | 70 | { |
71 | char *p, *cp, **q, *endp; | 71 | char *p, *cp, **q, *endp; |
@@ -74,10 +74,10 @@ getprotoent_r(struct protoent *pe, struct protoent_data *pd) | |||
74 | int serrno; | 74 | int serrno; |
75 | 75 | ||
76 | if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 76 | if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
77 | return (NULL); | 77 | return (-1); |
78 | again: | 78 | again: |
79 | if ((p = fgetln(pd->fp, &len)) == NULL) | 79 | if ((p = fgetln(pd->fp, &len)) == NULL) |
80 | return (NULL); | 80 | return (-1); |
81 | if (len == 0 || *p == '#' || *p == '\n') | 81 | if (len == 0 || *p == '#' || *p == '\n') |
82 | goto again; | 82 | goto again; |
83 | if (p[len-1] == '\n') | 83 | if (p[len-1] == '\n') |
@@ -86,7 +86,7 @@ again: | |||
86 | len = cp - p; | 86 | len = cp - p; |
87 | cp = realloc(pd->line, len + 1); | 87 | cp = realloc(pd->line, len + 1); |
88 | if (cp == NULL) | 88 | if (cp == NULL) |
89 | return (NULL); | 89 | return (-1); |
90 | pd->line = pe->p_name = memcpy(cp, p, len); | 90 | pd->line = pe->p_name = memcpy(cp, p, len); |
91 | cp[len] = '\0'; | 91 | cp[len] = '\0'; |
92 | cp = strpbrk(cp, " \t"); | 92 | cp = strpbrk(cp, " \t"); |
@@ -109,7 +109,7 @@ again: | |||
109 | serrno = errno; | 109 | serrno = errno; |
110 | endprotoent_r(pd); | 110 | endprotoent_r(pd); |
111 | errno = serrno; | 111 | errno = serrno; |
112 | return (NULL); | 112 | return (-1); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | q = pe->p_aliases = pd->aliases; | 115 | q = pe->p_aliases = pd->aliases; |
@@ -127,7 +127,7 @@ again: | |||
127 | serrno = errno; | 127 | serrno = errno; |
128 | endprotoent_r(pd); | 128 | endprotoent_r(pd); |
129 | errno = serrno; | 129 | errno = serrno; |
130 | return (NULL); | 130 | return (-1); |
131 | } | 131 | } |
132 | pd->maxaliases *= 2; | 132 | pd->maxaliases *= 2; |
133 | q = (char **)p + (q - pe->p_aliases); | 133 | q = (char **)p + (q - pe->p_aliases); |
@@ -140,7 +140,7 @@ again: | |||
140 | } | 140 | } |
141 | } | 141 | } |
142 | *q = NULL; | 142 | *q = NULL; |
143 | return (pe); | 143 | return (0); |
144 | } | 144 | } |
145 | 145 | ||
146 | struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ | 146 | struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ |
@@ -162,5 +162,7 @@ getprotoent(void) | |||
162 | { | 162 | { |
163 | static struct protoent proto; | 163 | static struct protoent proto; |
164 | 164 | ||
165 | return getprotoent_r(&proto, &_protoent_data); | 165 | if (getprotoent_r(&proto, &_protoent_data) != 0) |
166 | return (NULL); | ||
167 | return (&proto); | ||
166 | } | 168 | } |
diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c index 429304e7a1..f257bf4a71 100644 --- a/src/lib/libc/net/getprotoname.c +++ b/src/lib/libc/net/getprotoname.c | |||
@@ -28,25 +28,25 @@ | |||
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.5 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getprotoname.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 protoent * | 38 | int |
39 | getprotobyname_r(const char *name, struct protoent *pe, | 39 | getprotobyname_r(const char *name, struct protoent *pe, |
40 | struct protoent_data *pd) | 40 | struct protoent_data *pd) |
41 | { | 41 | { |
42 | struct protoent *p; | ||
43 | char **cp; | 42 | char **cp; |
43 | int error; | ||
44 | 44 | ||
45 | setprotoent_r(pd->stayopen, pd); | 45 | setprotoent_r(pd->stayopen, pd); |
46 | while ((p = getprotoent_r(pe, pd))) { | 46 | while ((error = getprotoent_r(pe, pd)) == 0) { |
47 | if (strcmp(p->p_name, name) == 0) | 47 | if (strcmp(pe->p_name, name) == 0) |
48 | break; | 48 | break; |
49 | for (cp = p->p_aliases; *cp != 0; cp++) | 49 | for (cp = pe->p_aliases; *cp != 0; cp++) |
50 | if (strcmp(*cp, name) == 0) | 50 | if (strcmp(*cp, name) == 0) |
51 | goto found; | 51 | goto found; |
52 | } | 52 | } |
@@ -55,7 +55,7 @@ found: | |||
55 | fclose(pd->fp); | 55 | fclose(pd->fp); |
56 | pd->fp = NULL; | 56 | pd->fp = NULL; |
57 | } | 57 | } |
58 | return (p); | 58 | return (error); |
59 | } | 59 | } |
60 | 60 | ||
61 | struct protoent * | 61 | struct protoent * |
@@ -64,5 +64,7 @@ getprotobyname(const char *name) | |||
64 | extern struct protoent_data _protoent_data; | 64 | extern struct protoent_data _protoent_data; |
65 | static struct protoent proto; | 65 | static struct protoent proto; |
66 | 66 | ||
67 | return getprotobyname_r(name, &proto, &_protoent_data); | 67 | if (getprotobyname_r(name, &proto, &_protoent_data) != 0) |
68 | return (NULL); | ||
69 | return (&proto); | ||
68 | } | 70 | } |
diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c index 597c42497f..062318630f 100644 --- a/src/lib/libc/net/getservbyname.c +++ b/src/lib/libc/net/getservbyname.c | |||
@@ -28,37 +28,37 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.8 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.9 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 | getservbyname_r(const char *name, const char *proto, struct servent *se, | 39 | getservbyname_r(const char *name, const char *proto, struct servent *se, |
40 | struct servent_data *sd) | 40 | struct servent_data *sd) |
41 | { | 41 | { |
42 | struct servent *p; | ||
43 | char **cp; | 42 | char **cp; |
43 | int error; | ||
44 | 44 | ||
45 | setservent_r(sd->stayopen, sd); | 45 | setservent_r(sd->stayopen, sd); |
46 | while ((p = getservent_r(se, sd))) { | 46 | while ((error = getservent_r(se, sd)) == 0) { |
47 | if (strcmp(name, p->s_name) == 0) | 47 | if (strcmp(name, se->s_name) == 0) |
48 | goto gotname; | 48 | goto gotname; |
49 | for (cp = p->s_aliases; *cp; cp++) | 49 | for (cp = se->s_aliases; *cp; cp++) |
50 | if (strcmp(name, *cp) == 0) | 50 | if (strcmp(name, *cp) == 0) |
51 | goto gotname; | 51 | goto gotname; |
52 | continue; | 52 | continue; |
53 | gotname: | 53 | gotname: |
54 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 54 | if (proto == 0 || strcmp(se->s_proto, proto) == 0) |
55 | break; | 55 | break; |
56 | } | 56 | } |
57 | if (!sd->stayopen && sd->fp != NULL) { | 57 | if (!sd->stayopen && sd->fp != NULL) { |
58 | fclose(sd->fp); | 58 | fclose(sd->fp); |
59 | sd->fp = NULL; | 59 | sd->fp = NULL; |
60 | } | 60 | } |
61 | return (p); | 61 | return (error); |
62 | } | 62 | } |
63 | 63 | ||
64 | struct servent * | 64 | struct servent * |
@@ -67,5 +67,7 @@ getservbyname(const char *name, const char *proto) | |||
67 | extern struct servent_data _servent_data; | 67 | extern struct servent_data _servent_data; |
68 | static struct servent serv; | 68 | static struct servent serv; |
69 | 69 | ||
70 | return (getservbyname_r(name, proto, &serv, &_servent_data)); | 70 | if (getservbyname_r(name, proto, &serv, &_servent_data) != 0) |
71 | return (NULL); | ||
72 | return (&serv); | ||
71 | } | 73 | } |
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 | } |
diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3 index f5294b8f70..0e93e195b6 100644 --- a/src/lib/libc/net/getservent.3 +++ b/src/lib/libc/net/getservent.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getservent.3,v 1.14 2004/10/17 20:24:23 millert Exp $ | 1 | .\" $OpenBSD: getservent.3,v 1.15 2004/10/25 03:09:01 millert Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -46,15 +46,15 @@ | |||
46 | .Fd #include <netdb.h> | 46 | .Fd #include <netdb.h> |
47 | .Ft struct servent * | 47 | .Ft struct servent * |
48 | .Fn getservent "void" | 48 | .Fn getservent "void" |
49 | .Ft struct servent * | 49 | .Ft int |
50 | .Fn getservent_r "struct servent *servent" "struct servent_data *servent_data" | 50 | .Fn getservent_r "struct servent *servent" "struct servent_data *servent_data" |
51 | .Ft struct servent * | 51 | .Ft struct servent * |
52 | .Fn getservbyname "const char *name" "const char *proto" | 52 | .Fn getservbyname "const char *name" "const char *proto" |
53 | .Ft struct servent * | 53 | .Ft int |
54 | .Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" | 54 | .Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" |
55 | .Ft struct servent * | 55 | .Ft struct servent * |
56 | .Fn getservbyport "int port" "const char *proto" | 56 | .Fn getservbyport "int port" "const char *proto" |
57 | .Ft struct servent * | 57 | .Ft int |
58 | .Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" | 58 | .Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" |
59 | .Ft void | 59 | .Ft void |
60 | .Fn setservent "int stayopen" | 60 | .Fn setservent "int stayopen" |
@@ -153,10 +153,24 @@ structure which is used to store the results of the database lookup. | |||
153 | .Bl -tag -width /etc/services -compact | 153 | .Bl -tag -width /etc/services -compact |
154 | .It Pa /etc/services | 154 | .It Pa /etc/services |
155 | .El | 155 | .El |
156 | .Sh DIAGNOSTICS | 156 | .Sh RETURN VALUES |
157 | Null pointer (0) returned on | 157 | The |
158 | .Dv EOF | 158 | .Fn getservent , |
159 | or error. | 159 | .Fn getservbyport , |
160 | and | ||
161 | .Fn getservbyname | ||
162 | functions return a pointer to a | ||
163 | .Fa servent | ||
164 | structure on success or a null pointer if end-of-file | ||
165 | is reached or an error occurs. | ||
166 | .Pp | ||
167 | The | ||
168 | .Fn getservent_r , | ||
169 | .Fn getservbyport_r , | ||
170 | and | ||
171 | .Fn getservbyname_r | ||
172 | functions return 0 on success or \-1 if end-of-file | ||
173 | is reached or an error occurs. | ||
160 | .Sh SEE ALSO | 174 | .Sh SEE ALSO |
161 | .Xr getprotoent 3 , | 175 | .Xr getprotoent 3 , |
162 | .Xr services 5 | 176 | .Xr services 5 |
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c index 9cf53774d6..3eaf2a4adc 100644 --- a/src/lib/libc/net/getservent.c +++ b/src/lib/libc/net/getservent.c | |||
@@ -28,7 +28,7 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.8 2004/10/17 20:24:23 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.9 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 <sys/types.h> | 34 | #include <sys/types.h> |
@@ -65,7 +65,7 @@ endservent_r(struct servent_data *sd) | |||
65 | sd->stayopen = 0; | 65 | sd->stayopen = 0; |
66 | } | 66 | } |
67 | 67 | ||
68 | struct servent * | 68 | int |
69 | getservent_r(struct servent *se, struct servent_data *sd) | 69 | getservent_r(struct servent *se, struct servent_data *sd) |
70 | { | 70 | { |
71 | char *p, *cp, **q, *endp; | 71 | char *p, *cp, **q, *endp; |
@@ -74,10 +74,10 @@ getservent_r(struct servent *se, struct servent_data *sd) | |||
74 | int serrno; | 74 | int serrno; |
75 | 75 | ||
76 | if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "r" )) == NULL) | 76 | if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "r" )) == NULL) |
77 | return (NULL); | 77 | return (-1); |
78 | again: | 78 | again: |
79 | if ((p = fgetln(sd->fp, &len)) == NULL) | 79 | if ((p = fgetln(sd->fp, &len)) == NULL) |
80 | return (NULL); | 80 | return (-1); |
81 | if (len == 0 || *p == '#' || *p == '\n') | 81 | if (len == 0 || *p == '#' || *p == '\n') |
82 | goto again; | 82 | goto again; |
83 | if (p[len-1] == '\n') | 83 | if (p[len-1] == '\n') |
@@ -86,7 +86,7 @@ again: | |||
86 | len = cp - p; | 86 | len = cp - p; |
87 | cp = realloc(sd->line, len + 1); | 87 | cp = realloc(sd->line, len + 1); |
88 | if (cp == NULL) | 88 | if (cp == NULL) |
89 | return (NULL); | 89 | return (-1); |
90 | sd->line = se->s_name = memcpy(cp, p, len); | 90 | sd->line = se->s_name = memcpy(cp, p, len); |
91 | cp[len] = '\0'; | 91 | cp[len] = '\0'; |
92 | p = strpbrk(cp, " \t"); | 92 | p = strpbrk(cp, " \t"); |
@@ -111,7 +111,7 @@ again: | |||
111 | serrno = errno; | 111 | serrno = errno; |
112 | endservent_r(sd); | 112 | endservent_r(sd); |
113 | errno = serrno; | 113 | errno = serrno; |
114 | return (NULL); | 114 | return (-1); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | q = se->s_aliases = sd->aliases; | 117 | q = se->s_aliases = sd->aliases; |
@@ -130,7 +130,7 @@ again: | |||
130 | serrno = errno; | 130 | serrno = errno; |
131 | endservent_r(sd); | 131 | endservent_r(sd); |
132 | errno = serrno; | 132 | errno = serrno; |
133 | return (NULL); | 133 | return (-1); |
134 | } | 134 | } |
135 | sd->maxaliases *= 2; | 135 | sd->maxaliases *= 2; |
136 | q = (char **)p + (q - se->s_aliases); | 136 | q = (char **)p + (q - se->s_aliases); |
@@ -142,7 +142,7 @@ again: | |||
142 | *cp++ = '\0'; | 142 | *cp++ = '\0'; |
143 | } | 143 | } |
144 | *q = NULL; | 144 | *q = NULL; |
145 | return (se); | 145 | return (0); |
146 | } | 146 | } |
147 | 147 | ||
148 | struct servent_data _servent_data; /* shared with getservby{name,port}.c */ | 148 | struct servent_data _servent_data; /* shared with getservby{name,port}.c */ |
@@ -164,5 +164,7 @@ getservent(void) | |||
164 | { | 164 | { |
165 | static struct servent serv; | 165 | static struct servent serv; |
166 | 166 | ||
167 | return getservent_r(&serv, &_servent_data); | 167 | if (getservent_r(&serv, &_servent_data) != 0) |
168 | return (NULL); | ||
169 | return (&serv); | ||
168 | } | 170 | } |