diff options
Diffstat (limited to 'lib/libc/net/getservent.c')
-rw-r--r-- | lib/libc/net/getservent.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c index feb97aa129a..7d8cb6d8cad 100644 --- a/lib/libc/net/getservent.c +++ b/lib/libc/net/getservent.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getservent.c,v 1.3 1997/04/05 21:13:09 millert Exp $"; +static char rcsid[] = "$OpenBSD: getservent.c,v 1.4 1998/03/16 05:07:00 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -74,20 +74,24 @@ endservent() struct servent * getservent() { - char *p; - register char *cp, **q; + char *p, *cp, **q; + size_t len; if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) return (NULL); again: - if ((p = fgets(line, BUFSIZ, servf)) == NULL) + if ((p = fgetln(servf, &len)) == NULL) return (NULL); - if (*p == '#') + if (p[len-1] == '\n') + len--; + if (len >= sizeof(line) || len == 0) goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) + p = memcpy(line, p, len); + line[len] = '\0'; + if (*p == '#') goto again; - *cp = '\0'; + if ((cp = strchr(p, '#')) != NULL) + *cp = '\0'; serv.s_name = p; p = strpbrk(p, " \t"); if (p == NULL) |