From 59889a1524d53b0efa5deebd003a0c6b5118b513 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 29 Aug 2000 21:04:07 +0000 Subject: strtok() -> strsep() (no strtok() in libraries allowed) small cleanup in nearby area: pointer 0 -> NULL, according to manpages hardcoded constant -> sizeof(buf) --- lib/libc/rpc/netnamer.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'lib/libc/rpc/netnamer.c') diff --git a/lib/libc/rpc/netnamer.c b/lib/libc/rpc/netnamer.c index 26e58b0..2fa0a3c 100644 --- a/lib/libc/rpc/netnamer.c +++ b/lib/libc/rpc/netnamer.c @@ -26,6 +26,8 @@ * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 + * + * $FreeBSD$ */ #if !defined(lint) && defined(SCCSIDS) static char sccsid[] = "@(#)netnamer.c 1.13 91/03/11 Copyr 1986 Sun Micro"; @@ -85,18 +87,20 @@ netname2user(netname, uidp, gidp, gidlenp, gidlist) int err; if (getnetid(netname, val)) { - p = strtok(val, ":"); + char *res = val; + + p = strsep(&res, ":"); if (p == NULL) return (0); - *uidp = (uid_t) atol(val); - p = strtok(NULL, "\n,"); - *gidp = (gid_t) atol(p); + *uidp = (uid_t) atol(p); + p = strsep(&res, "\n,"); if (p == NULL) { return (0); } + *gidp = (gid_t) atol(p); gidlen = 0; for (gidlen = 0; gidlen < NGROUPS; gidlen++) { - p = strtok(NULL, "\n,"); + p = strsep(&res, "\n,"); if (p == NULL) break; gidlist[gidlen] = (gid_t) atol(p); @@ -252,7 +256,7 @@ getnetid(key, ret) #endif fd = fopen(NETIDFILE, "r"); - if (fd == (FILE *) 0) { + if (fd == NULL) { #ifdef YP res = "+"; goto getnetidyp; @@ -261,10 +265,10 @@ getnetid(key, ret) #endif } for (;;) { - if (fd == (FILE *) 0) + if (fd == NULL) return (0); /* getnetidyp brings us here */ - res = fgets(buf, 1024, fd); - if (res == 0) { + res = fgets(buf, sizeof(buf), fd); + if (res == NULL) { fclose(fd); return (0); } @@ -301,13 +305,15 @@ getnetid(key, ret) continue; #endif /* YP */ } else { - mkey = strtok(buf, "\t "); + mkey = strsep(&res, "\t "); if (mkey == NULL) { fprintf(stderr, "Bad record in %s -- %s", NETIDFILE, buf); continue; } - mval = strtok(NULL, " \t#\n"); + do { + mval = strsep(&res, " \t#\n"); + } while (mval != NULL && !*mval); if (mval == NULL) { fprintf(stderr, "Bad record in %s val problem - %s", NETIDFILE, buf); -- cgit v1.1