From 42489d4b990a8793c837811c34a869ec16d055ba Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 25 Oct 2004 03:09:01 +0000 Subject: Change return value of reentrant getproto* and getserv* to match the IBM/Digital API. --- src/lib/libc/net/getprotoent.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/lib/libc/net/getprotoent.c') 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 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.6 2004/10/17 20:24:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.7 2004/10/25 03:09:01 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -65,7 +65,7 @@ endprotoent_r(struct protoent_data *pd) pd->stayopen = 0; } -struct protoent * +int getprotoent_r(struct protoent *pe, struct protoent_data *pd) { char *p, *cp, **q, *endp; @@ -74,10 +74,10 @@ getprotoent_r(struct protoent *pe, struct protoent_data *pd) int serrno; if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r" )) == NULL) - return (NULL); + return (-1); again: if ((p = fgetln(pd->fp, &len)) == NULL) - return (NULL); + return (-1); if (len == 0 || *p == '#' || *p == '\n') goto again; if (p[len-1] == '\n') @@ -86,7 +86,7 @@ again: len = cp - p; cp = realloc(pd->line, len + 1); if (cp == NULL) - return (NULL); + return (-1); pd->line = pe->p_name = memcpy(cp, p, len); cp[len] = '\0'; cp = strpbrk(cp, " \t"); @@ -109,7 +109,7 @@ again: serrno = errno; endprotoent_r(pd); errno = serrno; - return (NULL); + return (-1); } } q = pe->p_aliases = pd->aliases; @@ -127,7 +127,7 @@ again: serrno = errno; endprotoent_r(pd); errno = serrno; - return (NULL); + return (-1); } pd->maxaliases *= 2; q = (char **)p + (q - pe->p_aliases); @@ -140,7 +140,7 @@ again: } } *q = NULL; - return (pe); + return (0); } struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ @@ -162,5 +162,7 @@ getprotoent(void) { static struct protoent proto; - return getprotoent_r(&proto, &_protoent_data); + if (getprotoent_r(&proto, &_protoent_data) != 0) + return (NULL); + return (&proto); } -- cgit v1.2.3-55-g6feb