summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getprotoent.c
diff options
context:
space:
mode:
authormillert <>2004-10-25 03:09:01 +0000
committermillert <>2004-10-25 03:09:01 +0000
commit42489d4b990a8793c837811c34a869ec16d055ba (patch)
tree36483a751887031181b8128f629bde9b388ecac4 /src/lib/libc/net/getprotoent.c
parenteae90a29f226809527585d7ba688d0af8627db58 (diff)
downloadopenbsd-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/getprotoent.c')
-rw-r--r--src/lib/libc/net/getprotoent.c20
1 files changed, 11 insertions, 9 deletions
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)
31static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.6 2004/10/17 20:24:23 millert Exp $"; 31static 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
68struct protoent * 68int
69getprotoent_r(struct protoent *pe, struct protoent_data *pd) 69getprotoent_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);
78again: 78again:
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
146struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ 146struct 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}