diff options
author | ache <ache@FreeBSD.org> | 2000-08-29 21:04:07 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2000-08-29 21:04:07 +0000 |
commit | 59889a1524d53b0efa5deebd003a0c6b5118b513 (patch) | |
tree | 5e6b6c3eb13edc4dd1394a4c346416f346da6cc5 /lib/libc/rpc | |
parent | 5c34b0eac75aa6d5a8bb94e8054260564cd1f3d4 (diff) | |
download | FreeBSD-src-59889a1524d53b0efa5deebd003a0c6b5118b513.zip FreeBSD-src-59889a1524d53b0efa5deebd003a0c6b5118b513.tar.gz |
strtok() -> strsep() (no strtok() in libraries allowed)
small cleanup in nearby area:
pointer 0 -> NULL, according to manpages
hardcoded constant -> sizeof(buf)
Diffstat (limited to 'lib/libc/rpc')
-rw-r--r-- | lib/libc/rpc/getpublickey.c | 14 | ||||
-rw-r--r-- | lib/libc/rpc/netnamer.c | 28 |
2 files changed, 26 insertions, 16 deletions
diff --git a/lib/libc/rpc/getpublickey.c b/lib/libc/rpc/getpublickey.c index e1c34d9..49227b4 100644 --- a/lib/libc/rpc/getpublickey.c +++ b/lib/libc/rpc/getpublickey.c @@ -26,6 +26,8 @@ * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 + * + * $FreeBSD$ */ #if !defined(lint) && defined(SCCSIDS) static char sccsid[] = "@(#)publickey.c 1.10 91/03/11 Copyr 1986 Sun Micro"; @@ -97,11 +99,11 @@ getpublicandprivatekey(key, ret) char *mval; fd = fopen(PKFILE, "r"); - if (fd == (FILE *) 0) + if (fd == NULL) return (0); for (;;) { - res = fgets(buf, 1024, fd); - if (res == 0) { + res = fgets(buf, sizeof(buf), fd); + if (res == NULL) { fclose(fd); return (0); } @@ -140,13 +142,15 @@ getpublicandprivatekey(key, ret) continue; #endif /* YP */ } else { - mkey = strtok(buf, "\t "); + mkey = strsep(&res, "\t "); if (mkey == NULL) { fprintf(stderr, "Bad record in %s -- %s", PKFILE, buf); continue; } - mval = strtok((char *)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", PKFILE, buf); 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); |