summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-01-03 18:51:58 +0000
committered <ed@FreeBSD.org>2012-01-03 18:51:58 +0000
commite7e5b53bf16ab3b35646f0580b36fa7d7afa9678 (patch)
treeb751618c7a82d9c00cab91ea9f611585dbf14d84
parentd106f2fd7cf6be7617b1756d893b5b6fba5310f4 (diff)
downloadFreeBSD-src-e7e5b53bf16ab3b35646f0580b36fa7d7afa9678.zip
FreeBSD-src-e7e5b53bf16ab3b35646f0580b36fa7d7afa9678.tar.gz
Replace index() and rindex() calls with strchr() and strrchr().
The index() and rindex() functions were marked LEGACY in the 2001 revision of POSIX and were subsequently removed from the 2008 revision. The strchr() and strrchr() functions are part of the C standard. This makes the source code a lot more consistent, as most of these C files also call into other str*() routines. In fact, about a dozen already perform strchr() calls.
-rw-r--r--games/fortune/fortune/fortune.c6
-rw-r--r--lib/libc/gen/exec.c2
-rw-r--r--lib/libc/gen/getttyent.c6
-rw-r--r--lib/libc/gen/timezone.c2
-rw-r--r--lib/libc/net/gethostbynis.c2
-rw-r--r--lib/libc/net/getnetbynis.c2
-rw-r--r--lib/libcam/camlib.c2
-rw-r--r--lib/libstand/bootp.c6
-rw-r--r--lib/libutil/quotafile.c2
-rw-r--r--libexec/mknetid/parse_group.c2
-rw-r--r--libexec/rlogind/rlogind.c7
-rw-r--r--sbin/bsdlabel/bsdlabel.c4
-rw-r--r--sbin/dump/main.c2
-rw-r--r--sbin/fsck_ffs/pass2.c2
-rw-r--r--sbin/ipfw/main.c10
-rw-r--r--sbin/shutdown/shutdown.c2
-rw-r--r--sys/boot/common/interp_parse.c2
-rw-r--r--sys/boot/ofw/common/main.c2
-rw-r--r--sys/boot/ofw/libofw/ofw_net.c2
-rw-r--r--usr.bin/cksum/cksum.c2
-rw-r--r--usr.bin/compress/compress.c6
-rw-r--r--usr.bin/finger/finger.c2
-rw-r--r--usr.bin/hexdump/display.c2
-rw-r--r--usr.bin/hexdump/hexdump.c2
-rw-r--r--usr.bin/hexdump/hexsyntax.c2
-rw-r--r--usr.bin/hexdump/parse.c8
-rw-r--r--usr.bin/locate/locate/fastfind.c2
-rw-r--r--usr.bin/locate/locate/util.c8
-rw-r--r--usr.bin/netstat/if.c2
-rw-r--r--usr.bin/netstat/inet.c2
-rw-r--r--usr.bin/netstat/inet6.c6
-rw-r--r--usr.bin/netstat/sctp.c6
-rw-r--r--usr.bin/rlogin/rlogin.c2
-rw-r--r--usr.bin/rpcgen/rpc_main.c8
-rw-r--r--usr.bin/systat/devs.c2
-rw-r--r--usr.bin/systat/netcmds.c2
-rw-r--r--usr.bin/systat/netstat.c4
-rw-r--r--usr.bin/tftp/main.c14
-rw-r--r--usr.bin/tr/str.c2
-rw-r--r--usr.bin/tset/map.c2
-rw-r--r--usr.bin/tset/term.c4
-rw-r--r--usr.bin/tset/wrterm.c2
-rw-r--r--usr.sbin/bootparamd/bootparamd/bootparamd.c4
-rw-r--r--usr.sbin/config/main.c2
-rw-r--r--usr.sbin/config/mkmakefile.c14
-rw-r--r--usr.sbin/inetd/inetd.c4
-rw-r--r--usr.sbin/ipfwpcap/ipfwpcap.c2
-rw-r--r--usr.sbin/mtree/spec.c4
-rw-r--r--usr.sbin/newsyslog/newsyslog.c8
-rw-r--r--usr.sbin/rwhod/rwhod.c2
-rw-r--r--usr.sbin/sade/variable.c12
51 files changed, 103 insertions, 106 deletions
diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c
index e93b0e7..de85d09 100644
--- a/games/fortune/fortune/fortune.c
+++ b/games/fortune/fortune/fortune.c
@@ -683,7 +683,7 @@ all_forts(FILEDESC *fp, char *offensive)
obscene->fd = fd;
obscene->inf = NULL;
obscene->path = offensive;
- if ((sp = rindex(offensive, '/')) == NULL)
+ if ((sp = strrchr(offensive, '/')) == NULL)
obscene->name = offensive;
else
obscene->name = ++sp;
@@ -785,7 +785,7 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
}
}
- if ((sp = rindex(file, '/')) == NULL)
+ if ((sp = strrchr(file, '/')) == NULL)
sp = file;
else
sp++;
@@ -797,7 +797,7 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
DPRINTF(2, (stderr, "FALSE (check fortunes only)\n"));
return (FALSE);
}
- if ((sp = rindex(sp, '.')) != NULL) {
+ if ((sp = strrchr(sp, '.')) != NULL) {
sp++;
for (i = 0; suflist[i] != NULL; i++)
if (strcmp(sp, suflist[i]) == 0) {
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index b83136e..4998ee8 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -159,7 +159,7 @@ execvPe(const char *name, const char *path, char * const *argv,
eacces = 0;
/* If it's an absolute or relative path name, it's easy. */
- if (index(name, '/')) {
+ if (strchr(name, '/')) {
bp = name;
cur = NULL;
goto retry;
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index 9b9e3ea..f2fc298 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -78,7 +78,7 @@ getttyent(void)
if (!fgets(p = line, lbsize, tf))
return (NULL);
/* extend buffer if line was too big, and retry */
- while (!index(p, '\n') && !feof(tf)) {
+ while (!strchr(p, '\n') && !feof(tf)) {
i = strlen(p);
lbsize += MALLOCCHUNK;
if ((p = realloc(line, lbsize)) == NULL) {
@@ -148,7 +148,7 @@ getttyent(void)
tty.ty_comment = p;
if (*p == 0)
tty.ty_comment = 0;
- if ( (p = index(p, '\n')) )
+ if ((p = strchr(p, '\n')))
*p = '\0';
return (&tty);
}
@@ -196,7 +196,7 @@ static char *
value(char *p)
{
- return ((p = index(p, '=')) ? ++p : NULL);
+ return ((p = strchr(p, '=')) ? ++p : NULL);
}
int
diff --git a/lib/libc/gen/timezone.c b/lib/libc/gen/timezone.c
index 5f0fa66..9b50e79 100644
--- a/lib/libc/gen/timezone.c
+++ b/lib/libc/gen/timezone.c
@@ -59,7 +59,7 @@ timezone(int zone, int dst)
*end;
if ( (beg = getenv("TZNAME")) ) { /* set in environment */
- if ( (end = index(beg, ',')) ) {/* "PST,PDT" */
+ if ((end = strchr(beg, ','))) { /* "PST,PDT" */
if (dst)
return(++end);
*end = '\0';
diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c
index 11de8ae..c0d5177 100644
--- a/lib/libc/net/gethostbynis.c
+++ b/lib/libc/net/gethostbynis.c
@@ -91,7 +91,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he,
free(result);
result = (char *)&ypbuf;
- if ((cp = index(result, '\n')))
+ if ((cp = strchr(result, '\n')))
*cp = '\0';
cp = strpbrk(result, " \t");
diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c
index 811e431..1dbed83 100644
--- a/lib/libc/net/getnetbynis.c
+++ b/lib/libc/net/getnetbynis.c
@@ -80,7 +80,7 @@ _getnetbynis(const char *name, char *map, int af, struct netent *ne,
free(result);
result = (char *)&ypbuf;
- if ((cp = index(result, '\n')))
+ if ((cp = strchr(result, '\n')))
*cp = '\0';
cp = strpbrk(result, " \t");
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c
index 47ca384..525ad2f 100644
--- a/lib/libcam/camlib.c
+++ b/lib/libcam/camlib.c
@@ -137,7 +137,7 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
*/
if (*tmpstr == '/') {
tmpstr2 = tmpstr;
- tmpstr = (char *)rindex(tmpstr2, '/');
+ tmpstr = strrchr(tmpstr2, '/');
if ((tmpstr != NULL) && (*tmpstr != '\0'))
tmpstr++;
}
diff --git a/lib/libstand/bootp.c b/lib/libstand/bootp.c
index eb4a8ba..904b3ba 100644
--- a/lib/libstand/bootp.c
+++ b/lib/libstand/bootp.c
@@ -703,13 +703,13 @@ setenv_(u_char *cp, u_char *ep, struct dhcp_opt *opts)
u_char *s = NULL; /* semicolon ? */
/* skip leading whitespace */
- while (*endv && index(" \t\n\r", *endv))
+ while (*endv && strchr(" \t\n\r", *endv))
endv++;
- vp = index(endv, '='); /* find name=value separator */
+ vp = strchr(endv, '='); /* find name=value separator */
if (!vp)
break;
*vp++ = 0;
- if (op->fmt == __ILIST && (s = index(vp, ';')))
+ if (op->fmt == __ILIST && (s = strchr(vp, ';')))
*s++ = '\0';
setenv(endv, vp, 1);
vp = s; /* prepare for next round */
diff --git a/lib/libutil/quotafile.c b/lib/libutil/quotafile.c
index 0fda5f6..03e3de4 100644
--- a/lib/libutil/quotafile.c
+++ b/lib/libutil/quotafile.c
@@ -84,7 +84,7 @@ hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize)
}
strcpy(buf, fs->fs_mntops);
for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
- if ((cp = index(opt, '=')))
+ if ((cp = strchr(opt, '=')))
*cp++ = '\0';
if (type == USRQUOTA && strcmp(opt, usrname) == 0)
break;
diff --git a/libexec/mknetid/parse_group.c b/libexec/mknetid/parse_group.c
index 84cb991..75665dc 100644
--- a/libexec/mknetid/parse_group.c
+++ b/libexec/mknetid/parse_group.c
@@ -114,7 +114,7 @@ grscan(int search, int gid)
return(0);
bp = line;
/* skip lines that are too big */
- if (!index(line, '\n')) {
+ if (!strchr(line, '\n')) {
int ch;
while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
diff --git a/libexec/rlogind/rlogind.c b/libexec/rlogind/rlogind.c
index 2c2c9ef..be92f0f 100644
--- a/libexec/rlogind/rlogind.c
+++ b/libexec/rlogind/rlogind.c
@@ -543,16 +543,17 @@ extern char **environ;
void
setup_term(int fd)
{
- char *cp = index(term+ENVSIZE, '/');
+ char *cp;
char *speed;
struct termios tt, def;
+ cp = strchr(term + ENVSIZE, '/');
#ifndef notyet
tcgetattr(fd, &tt);
if (cp) {
*cp++ = '\0';
speed = cp;
- cp = index(speed, '/');
+ cp = strchr(speed, '/');
if (cp)
*cp++ = '\0';
cfsetspeed(&tt, atoi(speed));
@@ -567,7 +568,7 @@ setup_term(int fd)
if (cp) {
*cp++ = '\0';
speed = cp;
- cp = index(speed, '/');
+ cp = strchr(speed, '/');
if (cp)
*cp++ = '\0';
tcgetattr(fd, &tt);
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index 2dcffd0..a7cc2a2 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -782,12 +782,12 @@ getasciilabel(FILE *f, struct disklabel *lp)
lp->d_sbsize = 0; /* XXX */
while (fgets(line, sizeof(line) - 1, f)) {
lineno++;
- if ((cp = index(line,'\n')) != 0)
+ if ((cp = strchr(line,'\n')) != 0)
*cp = '\0';
cp = skip(line);
if (cp == NULL)
continue;
- tp = index(cp, ':');
+ tp = strchr(cp, ':');
if (tp == NULL) {
fprintf(stderr, "line %d: syntax error\n", lineno);
errors++;
diff --git a/sbin/dump/main.c b/sbin/dump/main.c
index 3e6ed1f..3ec78fd1 100644
--- a/sbin/dump/main.c
+++ b/sbin/dump/main.c
@@ -290,7 +290,7 @@ main(int argc, char *argv[])
tape = strchr(host, ':');
*tape++ = '\0';
#ifdef RDUMP
- if (index(tape, '\n')) {
+ if (strchr(tape, '\n')) {
(void)fprintf(stderr, "invalid characters in tape\n");
exit(X_STARTUP);
}
diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c
index 5959778..bd9bf97 100644
--- a/sbin/fsck_ffs/pass2.c
+++ b/sbin/fsck_ffs/pass2.c
@@ -613,7 +613,7 @@ fix_extraneous(struct inoinfo *inp, struct inodesc *idesc)
printf(" (IGNORED)\n");
return (0);
}
- if ((cp = rindex(oldname, '/')) == NULL) {
+ if ((cp = strchr(oldname, '/')) == NULL) {
printf(" (IGNORED)\n");
return (0);
}
diff --git a/sbin/ipfw/main.c b/sbin/ipfw/main.c
index 337d545..debed4e 100644
--- a/sbin/ipfw/main.c
+++ b/sbin/ipfw/main.c
@@ -122,9 +122,9 @@ ipfw_main(int oldac, char **oldav)
break;
if (copy) {
arg[j++] = arg[i];
- copy = !index("," WHITESP, arg[i]);
+ copy = !strchr("," WHITESP, arg[i]);
} else {
- copy = !index(WHITESP, arg[i]);
+ copy = !strchr(WHITESP, arg[i]);
if (copy)
arg[j++] = arg[i];
}
@@ -141,7 +141,7 @@ ipfw_main(int oldac, char **oldav)
* processing, this is just the number of blanks plus 1.
*/
for (i = 0, ac = 1; i < l; i++)
- if (index(WHITESP, arg[i]) != NULL)
+ if (strchr(WHITESP, arg[i]) != NULL)
ac++;
/*
@@ -162,7 +162,7 @@ ipfw_main(int oldac, char **oldav)
*/
av_p = (char *)&av[ac+1];
for (ac = 1, i = j = 0; i < l; i++) {
- if (index(WHITESP, arg[i]) != NULL || i == l-1) {
+ if (strchr(WHITESP, arg[i]) != NULL || i == l-1) {
if (i == l-1)
i++;
bcopy(arg+j, av_p, i-j);
@@ -240,7 +240,7 @@ ipfw_main(int oldac, char **oldav)
" ipfw sysctl -a\n");
return 0;
}
- s = index(av[2], '=');
+ s = strchr(av[2], '=');
if (s == NULL) {
s = !strcmp(av[2], "-a") ? NULL : av[2];
sysctlbyname(s, NULL, NULL, NULL, 0);
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index 7bd93a0..6e662a8 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -123,7 +123,7 @@ main(int argc, char **argv)
* Test for the special case where the utility is called as
* "poweroff", for which it runs 'shutdown -p now'.
*/
- if ((p = rindex(argv[0], '/')) == NULL)
+ if ((p = strrchr(argv[0], '/')) == NULL)
p = argv[0];
else
++p;
diff --git a/sys/boot/common/interp_parse.c b/sys/boot/common/interp_parse.c
index 32b01c8..32d4f48 100644
--- a/sys/boot/common/interp_parse.c
+++ b/sys/boot/common/interp_parse.c
@@ -137,7 +137,7 @@ parse(int *argc, char ***argv, char *str)
case VAR:
if (token) {
- PARSE_FAIL((q = index(p, token)) == NULL);
+ PARSE_FAIL((q = strchr(p, token)) == NULL);
} else {
q = p;
while (*q && !isspace(*q))
diff --git a/sys/boot/ofw/common/main.c b/sys/boot/ofw/common/main.c
index 52e69199..940ca63 100644
--- a/sys/boot/ofw/common/main.c
+++ b/sys/boot/ofw/common/main.c
@@ -133,7 +133,7 @@ main(int (*openfirm)(void *))
printf("Memory: %lldKB\n", memsize() / 1024);
OF_getprop(chosen, "bootpath", bootpath, 64);
- ch = index(bootpath, ':');
+ ch = strchr(bootpath, ':');
*ch = '\0';
printf("Booted from: %s\n", bootpath);
diff --git a/sys/boot/ofw/libofw/ofw_net.c b/sys/boot/ofw/libofw/ofw_net.c
index 36600ef..691deda 100644
--- a/sys/boot/ofw/libofw/ofw_net.c
+++ b/sys/boot/ofw/libofw/ofw_net.c
@@ -185,7 +185,7 @@ ofwn_init(struct iodesc *desc, void *machdep_hint)
int pathlen;
pathlen = OF_getprop(chosen, "bootpath", path, 64);
- if ((ch = index(path, ':')) != NULL)
+ if ((ch = strchr(path, ':')) != NULL)
*ch = '\0';
netdev = OF_finddevice(path);
#ifdef __sparc64__
diff --git a/usr.bin/cksum/cksum.c b/usr.bin/cksum/cksum.c
index dacf572..05dc8bb 100644
--- a/usr.bin/cksum/cksum.c
+++ b/usr.bin/cksum/cksum.c
@@ -68,7 +68,7 @@ main(int argc, char **argv)
int (*cfncn)(int, uint32_t *, off_t *);
void (*pfncn)(char *, uint32_t, off_t);
- if ((p = rindex(argv[0], '/')) == NULL)
+ if ((p = strrchr(argv[0], '/')) == NULL)
p = argv[0];
else
++p;
diff --git a/usr.bin/compress/compress.c b/usr.bin/compress/compress.c
index f73419d..1f458e5 100644
--- a/usr.bin/compress/compress.c
+++ b/usr.bin/compress/compress.c
@@ -75,7 +75,7 @@ main(int argc, char *argv[])
char *p, newname[MAXPATHLEN];
cat = 0;
- if ((p = rindex(argv[0], '/')) == NULL)
+ if ((p = strrchr(argv[0], '/')) == NULL)
p = argv[0];
else
++p;
@@ -141,7 +141,7 @@ main(int argc, char *argv[])
compress(*argv, "/dev/stdout", bits);
break;
}
- if ((p = rindex(*argv, '.')) != NULL &&
+ if ((p = strrchr(*argv, '.')) != NULL &&
!strcmp(p, ".Z")) {
cwarnx("%s: name already has trailing .Z",
*argv);
@@ -164,7 +164,7 @@ main(int argc, char *argv[])
break;
}
len = strlen(*argv);
- if ((p = rindex(*argv, '.')) == NULL ||
+ if ((p = strrchr(*argv, '.')) == NULL ||
strcmp(p, ".Z")) {
if (len > sizeof(newname) - 3) {
cwarnx("%s: name too long", *argv);
diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c
index 2704a96..7519f15 100644
--- a/usr.bin/finger/finger.c
+++ b/usr.bin/finger/finger.c
@@ -287,7 +287,7 @@ userlist(int argc, char **argv)
/* Pull out all network requests. */
for (ap = p = argv, np = nargv; *p; ++p)
- if (index(*p, '@'))
+ if (strchr(*p, '@'))
*np++ = *p;
else
*ap++ = *p;
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c
index 991509d..a5f2a47 100644
--- a/usr.bin/hexdump/display.c
+++ b/usr.bin/hexdump/display.c
@@ -220,7 +220,7 @@ bpad(PR *pr)
pr->cchar[0] = 's';
pr->cchar[1] = '\0';
for (p1 = pr->fmt; *p1 != '%'; ++p1);
- for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
+ for (p2 = ++p1; *p1 && strchr(spec, *p1); ++p1);
while ((*p2++ = *p1++));
}
diff --git a/usr.bin/hexdump/hexdump.c b/usr.bin/hexdump/hexdump.c
index c3aaab5..d3c4bb5 100644
--- a/usr.bin/hexdump/hexdump.c
+++ b/usr.bin/hexdump/hexdump.c
@@ -61,7 +61,7 @@ main(int argc, char *argv[])
(void)setlocale(LC_ALL, "");
- if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
+ if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od"))
newsyntax(argc, &argv);
else
oldsyntax(argc, &argv);
diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c
index a1b2099..ac1971a 100644
--- a/usr.bin/hexdump/hexsyntax.c
+++ b/usr.bin/hexdump/hexsyntax.c
@@ -54,7 +54,7 @@ newsyntax(int argc, char ***argvp)
char *p, **argv;
argv = *argvp;
- if ((p = rindex(argv[0], 'h')) != NULL &&
+ if ((p = strrchr(argv[0], 'h')) != NULL &&
strcmp(p, "hd") == 0) {
/* "Canonical" format, implies -C. */
add("\"%08.8_Ax\n\"");
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index b550bd6..0fa24f5 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -58,7 +58,7 @@ addfile(char *name)
if ((fp = fopen(name, "r")) == NULL)
err(1, "%s", name);
while (fgets(buf, sizeof(buf), fp)) {
- if (!(p = index(buf, '\n'))) {
+ if (!(p = strchr(buf, '\n'))) {
warnx("line too long");
while ((ch = getchar()) != '\n' && ch != EOF);
continue;
@@ -167,7 +167,7 @@ size(FS *fs)
* skip any special chars -- save precision in
* case it's a %s format.
*/
- while (index(spec + 1, *++fmt));
+ while (strchr(spec + 1, *++fmt));
if (*fmt == '.' && isdigit(*++fmt)) {
prec = atoi(fmt);
while (isdigit(*++fmt));
@@ -243,10 +243,10 @@ rewrite(FS *fs)
if (fu->bcnt) {
sokay = USEBCNT;
/* Skip to conversion character. */
- for (++p1; index(spec, *p1); ++p1);
+ for (++p1; strchr(spec, *p1); ++p1);
} else {
/* Skip any special chars, field width. */
- while (index(spec + 1, *++p1));
+ while (strchr(spec + 1, *++p1));
if (*p1 == '.' && isdigit(*++p1)) {
sokay = USEPREC;
prec = atoi(p1);
diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c
index 21148bc..c15730b 100644
--- a/usr.bin/locate/locate/fastfind.c
+++ b/usr.bin/locate/locate/fastfind.c
@@ -167,7 +167,7 @@ fastfind
/* find optimal (last) char for searching */
for (p = pathpart; *p != '\0'; p++)
- if (index(LOCATE_REG, *p) != NULL)
+ if (strchr(LOCATE_REG, *p) != NULL)
break;
if (*p == '\0')
diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c
index 7b9fe49..d00a9a3 100644
--- a/usr.bin/locate/locate/util.c
+++ b/usr.bin/locate/locate/util.c
@@ -162,7 +162,7 @@ patprep(name)
/* skip trailing metacharacters */
for (; p >= name; p--)
- if (index(LOCATE_REG, *p) == NULL)
+ if (strchr(LOCATE_REG, *p) == NULL)
break;
/*
@@ -172,7 +172,7 @@ patprep(name)
* |----< p
*/
if (p >= name &&
- (index(p, '[') != NULL || index(p, ']') != NULL)) {
+ (strchr(p, '[') != NULL || strchr(p, ']') != NULL)) {
for (p = name; *p != '\0'; p++)
if (*p == ']' || *p == '[')
break;
@@ -183,7 +183,7 @@ patprep(name)
* '*\*[a-z]'
* |-------< p
*/
- if (p >= name && index(LOCATE_REG, *p) != NULL)
+ if (p >= name && strchr(LOCATE_REG, *p) != NULL)
p = name - 1;
}
@@ -193,7 +193,7 @@ patprep(name)
else {
for (endmark = p; p >= name; p--)
- if (index(LOCATE_REG, *p) != NULL)
+ if (strchr(LOCATE_REG, *p) != NULL)
break;
for (++p;
(p <= endmark) && subp < (globfree + sizeof(globfree));)
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 8a11270..a985791 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -256,7 +256,7 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
if (interface != 0 && strcmp(name, interface) != 0)
continue;
- cp = index(name, '\0');
+ cp = strchr(name, '\0');
if (pfunc) {
(*pfunc)(name);
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 1653018..7309951 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -1247,7 +1247,7 @@ inetprint(struct in_addr *in, int port, const char *proto, int num_port)
sprintf(line, "%s.", inetname(in));
else
sprintf(line, "%.*s.", (Aflag && !num_port) ? 12 : 16, inetname(in));
- cp = index(line, '\0');
+ cp = strchr(line, '\0');
if (!num_port && port)
sp = getservbyport((int)port, proto);
if (sp || port == 0)
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index 03fef6e..1a19fa5 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -1100,7 +1100,7 @@ inet6print(struct in6_addr *in6, int port, const char *proto, int numeric)
sprintf(line, "%.*s.", Wflag ? 39 :
(Aflag && !numeric) ? 12 : 16, inet6name(in6));
- cp = index(line, '\0');
+ cp = strchr(line, '\0');
if (!numeric && port)
GETSERVBYPORT6(port, proto, sp);
if (sp || port == 0)
@@ -1129,7 +1129,7 @@ inet6name(struct in6_addr *in6p)
if (first && !numeric_addr) {
first = 0;
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
- (cp = index(domain, '.')))
+ (cp = strchr(domain, '.')))
(void) strcpy(domain, cp + 1);
else
domain[0] = 0;
@@ -1138,7 +1138,7 @@ inet6name(struct in6_addr *in6p)
if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
if (hp) {
- if ((cp = index(hp->h_name, '.')) &&
+ if ((cp = strchr(hp->h_name, '.')) &&
!strcmp(cp + 1, domain))
*cp = 0;
cp = hp->h_name;
diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c
index d5ad70e..fb94d44 100644
--- a/usr.bin/netstat/sctp.c
+++ b/usr.bin/netstat/sctp.c
@@ -162,7 +162,7 @@ inet6name(struct in6_addr *in6p)
if (first && !numeric_addr) {
first = 0;
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
- (cp = index(domain, '.')))
+ (cp = strchr(domain, '.')))
(void) strcpy(domain, cp + 1);
else
domain[0] = 0;
@@ -171,7 +171,7 @@ inet6name(struct in6_addr *in6p)
if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
if (hp) {
- if ((cp = index(hp->h_name, '.')) &&
+ if ((cp = strchr(hp->h_name, '.')) &&
!strcmp(cp + 1, domain))
*cp = 0;
cp = hp->h_name;
@@ -209,7 +209,7 @@ sctp_print_address(union sctp_sockstore *address, int port, int num_port)
sprintf(line, "%.*s.", Wflag ? 39 : 16, "");
break;
}
- cp = index(line, '\0');
+ cp = strchr(line, '\0');
if (!num_port && port)
sp = getservbyport((int)port, "sctp");
if (sp || port == 0)
diff --git a/usr.bin/rlogin/rlogin.c b/usr.bin/rlogin/rlogin.c
index 4d1f7b0..b134679 100644
--- a/usr.bin/rlogin/rlogin.c
+++ b/usr.bin/rlogin/rlogin.c
@@ -142,7 +142,7 @@ main(int argc, char *argv[])
one = 1;
host = localname = user = NULL;
- if ((p = rindex(argv[0], '/')))
+ if ((p = strrchr(argv[0], '/')))
++p;
else
p = argv[0];
diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c
index 00d85b8..c9b2e7a 100644
--- a/usr.bin/rpcgen/rpc_main.c
+++ b/usr.bin/rpcgen/rpc_main.c
@@ -64,10 +64,6 @@ static void clnt_output(const char *, const char *, int, const char * );
static char *generate_guard(const char *);
static void c_initialize(void);
-#if !defined(__FreeBSD__) && !defined(__NetBSD__)
-char * rindex();
-#endif
-
static void usage(void);
static void options_usage(void);
static int do_registers(int, const char **);
@@ -233,7 +229,7 @@ extendfile(const char *path, const char *ext)
const char *p;
const char *file;
- if ((file = rindex(path, '/')) == NULL)
+ if ((file = strrchr(path, '/')) == NULL)
file = path;
else
file++;
@@ -821,7 +817,7 @@ static void mkfile_output(struct commandline *cmd)
if (allfiles){
mkftemp = xmalloc(strlen("makefile.") +
strlen(cmd->infile) + 1);
- temp = (char *)rindex(cmd->infile, '.');
+ temp = strrchr(cmd->infile, '.');
strcpy(mkftemp, "makefile.");
(void) strncat(mkftemp, cmd->infile,
(temp - cmd->infile));
diff --git a/usr.bin/systat/devs.c b/usr.bin/systat/devs.c
index 09a1838..3c74fb7 100644
--- a/usr.bin/systat/devs.c
+++ b/usr.bin/systat/devs.c
@@ -265,7 +265,7 @@ dsselect(const char *args, devstat_select_mode select_mode, int maxshowdevs,
specified_devices = (char **)malloc(sizeof(char *));
tmpstr = tmpstr1 = strdup(args);
- cp = index(tmpstr1, '\n');
+ cp = strchr(tmpstr1, '\n');
if (cp)
*cp = '\0';
for (;;) {
diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c
index c7f1178..e627329 100644
--- a/usr.bin/systat/netcmds.c
+++ b/usr.bin/systat/netcmds.c
@@ -131,7 +131,7 @@ changeitems(const char *args, int onoff)
struct in_addr in;
tmpstr = tmpstr1 = strdup(args);
- cp = index(tmpstr1, '\n');
+ cp = strchr(tmpstr1, '\n');
if (cp)
*cp = '\0';
for (;;tmpstr1 = cp) {
diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c
index d96fb16..a5e0608 100644
--- a/usr.bin/systat/netstat.c
+++ b/usr.bin/systat/netstat.c
@@ -554,7 +554,7 @@ inetprint(struct sockaddr *sa, const char *proto)
break;
}
snprintf(line, sizeof(line), "%.*s.", 16, inetname(sa));
- cp = index(line, '\0');
+ cp = strchr(line, '\0');
if (!nflag && port)
sp = getservbyport(port, proto);
if (sp || port == 0)
@@ -564,7 +564,7 @@ inetprint(struct sockaddr *sa, const char *proto)
snprintf(cp, sizeof(line) - (cp - line), "%d",
ntohs((u_short)port));
/* pad to full column to clear any garbage */
- cp = index(line, '\0');
+ cp = strchr(line, '\0');
while (cp - line < 22)
*cp++ = ' ';
line[22] = '\0';
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
index 2b0172e..0092827 100644
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -437,16 +437,16 @@ put(int argc, char *argv[])
return;
}
targ = argv[argc - 1];
- if (rindex(argv[argc - 1], ':')) {
+ if (strrchr(argv[argc - 1], ':')) {
char *lcp;
for (n = 1; n < argc - 1; n++)
- if (index(argv[n], ':')) {
+ if (strchr(argv[n], ':')) {
putusage(argv[0]);
return;
}
lcp = argv[argc - 1];
- targ = rindex(lcp, ':');
+ targ = strrchr(lcp, ':');
*targ++ = 0;
if (lcp[0] == '[' && lcp[strlen(lcp) - 1] == ']') {
lcp[strlen(lcp) - 1] = '\0';
@@ -477,7 +477,7 @@ put(int argc, char *argv[])
}
/* this assumes the target is a directory */
/* on a remote unix system. hmmmm. */
- cp = index(targ, '\0');
+ cp = strchr(targ, '\0');
*cp++ = '/';
for (n = 1; n < argc - 1; n++) {
strcpy(cp, tail(argv[n]));
@@ -532,7 +532,7 @@ get(int argc, char *argv[])
}
if (!connected) {
for (n = 1; n < argc ; n++)
- if (rindex(argv[n], ':') == 0) {
+ if (strrchr(argv[n], ':') == 0) {
printf("No remote host specified and "
"no host given for file '%s'\n", argv[n]);
getusage(argv[0]);
@@ -540,7 +540,7 @@ get(int argc, char *argv[])
}
}
for (n = 1; n < argc ; n++) {
- src = rindex(argv[n], ':');
+ src = strrchr(argv[n], ':');
if (src == NULL)
src = argv[n];
else {
@@ -681,7 +681,7 @@ tail(char *filename)
char *s;
while (*filename) {
- s = rindex(filename, '/');
+ s = strrchr(filename, '/');
if (s == NULL)
break;
if (s[1])
diff --git a/usr.bin/tr/str.c b/usr.bin/tr/str.c
index abfd0d6..333ca5c 100644
--- a/usr.bin/tr/str.c
+++ b/usr.bin/tr/str.c
@@ -161,7 +161,7 @@ bracket(STR *s)
repeat:
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
return (0);
- if (p[0] != '*' || index(p, ']') == NULL)
+ if (p[0] != '*' || strchr(p, ']') == NULL)
return (0);
s->str += 1;
genseq(s);
diff --git a/usr.bin/tset/map.c b/usr.bin/tset/map.c
index 18ee135..8de594f 100644
--- a/usr.bin/tset/map.c
+++ b/usr.bin/tset/map.c
@@ -132,7 +132,7 @@ next: if (*arg == ':') {
goto badmopt;
++arg;
} else { /* Optional baudrate. */
- arg = index(p = arg, ':');
+ arg = strchr(p = arg, ':');
if (arg == NULL)
goto badmopt;
*arg++ = '\0';
diff --git a/usr.bin/tset/term.c b/usr.bin/tset/term.c
index 7082e5f..544e928 100644
--- a/usr.bin/tset/term.c
+++ b/usr.bin/tset/term.c
@@ -74,7 +74,7 @@ get_termcap_entry(char *userarg, char **tcapbufp)
/* Try ttyname(3); check for dialup or other mapping. */
if ((ttypath = ttyname(STDERR_FILENO))) {
- if ((p = rindex(ttypath, '/')))
+ if ((p = strrchr(ttypath, '/')))
++p;
else
p = ttypath;
@@ -146,7 +146,7 @@ askuser(const char *dflt)
return (dflt);
}
- if ((p = index(answer, '\n')))
+ if ((p = strchr(answer, '\n')))
*p = '\0';
if (answer[0])
return (answer);
diff --git a/usr.bin/tset/wrterm.c b/usr.bin/tset/wrterm.c
index e258e16..77751fa 100644
--- a/usr.bin/tset/wrterm.c
+++ b/usr.bin/tset/wrterm.c
@@ -56,7 +56,7 @@ wrtermcap(char *bp)
char *t, *sep;
/* Find the end of the terminal names. */
- if ((t = index(bp, ':')) == NULL)
+ if ((t = strchr(bp, ':')) == NULL)
errx(1, "termcap names not colon terminated");
*t++ = '\0';
diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c
index 5c1d264..0921305 100644
--- a/usr.sbin/bootparamd/bootparamd/bootparamd.c
+++ b/usr.sbin/bootparamd/bootparamd/bootparamd.c
@@ -114,7 +114,7 @@ bp_getfile_res *
bp_getfile_arg *getfile;
struct svc_req *req;
{
- char *where, *index();
+ char *where;
static bp_getfile_res res;
if (debug)
@@ -133,7 +133,7 @@ struct svc_req *req;
askname[sizeof(askname)-1] = 0;
if (getthefile(askname, getfile->file_id,buffer,sizeof(buffer))) {
- if ( (where = index(buffer,':')) ) {
+ if ( (where = strchr(buffer,':')) ) {
/* buffer is re-written to contain the name of the info of file */
strncpy(hostname, buffer, where - buffer);
hostname[where - buffer] = '\0';
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index ceee035..28d4f8a 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -626,7 +626,7 @@ remember(const char *file)
else
s = ns(file);
- if (index(s, '_') && strncmp(s, "opt_", 4) != 0) {
+ if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
free(s);
return;
}
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 9ae52af..4cbc135 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -206,12 +206,12 @@ makehints(void)
err(1, "%s", hint->hint_name);
while (fgets(line, BUFSIZ, ifp) != 0) {
/* zap trailing CR and/or LF */
- while ((s = rindex(line, '\n')) != NULL)
+ while ((s = strrchr(line, '\n')) != NULL)
*s = '\0';
- while ((s = rindex(line, '\r')) != NULL)
+ while ((s = strrchr(line, '\r')) != NULL)
*s = '\0';
/* remove # comments */
- s = index(line, '#');
+ s = strchr(line, '#');
if (s)
*s = '\0';
/* remove any whitespace and " characters */
@@ -268,12 +268,12 @@ makeenv(void)
if (ifp) {
while (fgets(line, BUFSIZ, ifp) != 0) {
/* zap trailing CR and/or LF */
- while ((s = rindex(line, '\n')) != NULL)
+ while ((s = strrchr(line, '\n')) != NULL)
*s = '\0';
- while ((s = rindex(line, '\r')) != NULL)
+ while ((s = strrchr(line, '\r')) != NULL)
*s = '\0';
/* remove # comments */
- s = index(line, '#');
+ s = strchr(line, '#');
if (s)
*s = '\0';
/* remove any whitespace and " characters */
@@ -689,7 +689,7 @@ tail(char *fn)
{
char *cp;
- cp = rindex(fn, '/');
+ cp = strrchr(fn, '/');
if (cp == 0)
return (fn);
return (cp+1);
diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c
index 0a39fdf..7dc77b3 100644
--- a/usr.sbin/inetd/inetd.c
+++ b/usr.sbin/inetd/inetd.c
@@ -1764,7 +1764,7 @@ more:
sep->se_rpc_lowvers = 0;
memcpy(&sep->se_ctrladdr4, bind_sa4,
sizeof(sep->se_ctrladdr4));
- if ((versp = rindex(sep->se_service, '/'))) {
+ if ((versp = strrchr(sep->se_service, '/'))) {
*versp++ = '\0';
switch (sscanf(versp, "%u-%u",
&sep->se_rpc_lowvers,
@@ -1936,7 +1936,7 @@ more:
} else
sep->se_group = NULL;
sep->se_server = newstr(sskip(&cp));
- if ((sep->se_server_name = rindex(sep->se_server, '/')))
+ if ((sep->se_server_name = strrchr(sep->se_server, '/')))
sep->se_server_name++;
if (strcmp(sep->se_server, "internal") == 0) {
struct biltin *bi;
diff --git a/usr.sbin/ipfwpcap/ipfwpcap.c b/usr.sbin/ipfwpcap/ipfwpcap.c
index c7543ef..d579bd9 100644
--- a/usr.sbin/ipfwpcap/ipfwpcap.c
+++ b/usr.sbin/ipfwpcap/ipfwpcap.c
@@ -87,7 +87,7 @@ okay(int pn)
char *p, numbuf[80];
if (pidfile[0] == '\0') {
- p = rindex(prog, '/');
+ p = strrchr(prog, '/');
p = (p == NULL) ? prog : p + 1;
snprintf(pidfile, sizeof pidfile,
diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c
index c7c6460..417932d 100644
--- a/usr.sbin/mtree/spec.c
+++ b/usr.sbin/mtree/spec.c
@@ -73,7 +73,7 @@ mtree_readspec(FILE *fi)
continue;
/* Find end of line. */
- if ((p = index(buf, '\n')) == NULL)
+ if ((p = strchr(buf, '\n')) == NULL)
errx(1, "line %d too long", lineno);
/* See if next line is continuation line. */
@@ -118,7 +118,7 @@ mtree_readspec(FILE *fi)
continue;
}
- if (index(p, '/'))
+ if (strchr(p, '/'))
errx(1, "line %d: slash character in file name",
lineno);
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 4e3d077..c2fdee2 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1710,7 +1710,7 @@ do_rotate(const struct conf_entry *ent)
} else { /* relative */
/* get directory part of logfile */
strlcpy(dirpart, ent->log, sizeof(dirpart));
- if ((p = rindex(dirpart, '/')) == NULL)
+ if ((p = strrchr(dirpart, '/')) == NULL)
dirpart[0] = '\0';
else
*(p + 1) = '\0';
@@ -1722,7 +1722,7 @@ do_rotate(const struct conf_entry *ent)
createdir(ent, dirpart);
/* get filename part of logfile */
- if ((p = rindex(ent->log, '/')) == NULL)
+ if ((p = strrchr(ent->log, '/')) == NULL)
strlcpy(namepart, ent->log, sizeof(namepart));
else
strlcpy(namepart, p + 1, sizeof(namepart));
@@ -2255,7 +2255,7 @@ age_old_log(char *file)
} else { /* relative */
/* get directory part of logfile */
strlcpy(tmp, file, sizeof(tmp));
- if ((p = rindex(tmp, '/')) == NULL)
+ if ((p = strrchr(tmp, '/')) == NULL)
tmp[0] = '\0';
else
*(p + 1) = '\0';
@@ -2265,7 +2265,7 @@ age_old_log(char *file)
strlcat(tmp, "/", sizeof(tmp));
/* get filename part of logfile */
- if ((p = rindex(file, '/')) == NULL)
+ if ((p = strrchr(file, '/')) == NULL)
strlcat(tmp, file, sizeof(tmp));
else
strlcat(tmp, p + 1, sizeof(tmp));
diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c
index 30cc2cf..16bf948 100644
--- a/usr.sbin/rwhod/rwhod.c
+++ b/usr.sbin/rwhod/rwhod.c
@@ -227,7 +227,7 @@ main(int argc, char *argv[])
syslog(LOG_ERR, "gethostname: %m");
exit(1);
}
- if ((cp = index(myname, '.')) != NULL)
+ if ((cp = strchr(myname, '.')) != NULL)
*cp = '\0';
strncpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname) - 1);
mywd.wd_hostname[sizeof(mywd.wd_hostname) - 1] = '\0';
diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c
index 911eb02..ae3a6e0 100644
--- a/usr.sbin/sade/variable.c
+++ b/usr.sbin/sade/variable.c
@@ -83,7 +83,7 @@ variable_set(char *var, int dirty)
else if (!*var)
msgDebug("Warning: Zero length name & value passed to variable_set()\n");
SAFE_STRCPY(tmp, var);
- if ((cp = index(tmp, '=')) == NULL)
+ if ((cp = strchr(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
make_variable(tmp, string_skipwhite(cp), dirty);
@@ -123,7 +123,7 @@ variable_unset(char *var)
Variable *vp;
char name[512], *cp;
- if ((cp = index(var, '=')) != NULL)
+ if ((cp = strchr(var, '=')) != NULL)
sstrncpy(name, var, cp - var);
else
SAFE_STRCPY(name, var);
@@ -189,14 +189,14 @@ variable_check2(char *data)
if (data == NULL)
return -1;
SAFE_STRCPY(tmp, data);
- if ((cp = index(tmp, '=')) != NULL) {
+ if ((cp = strchr(tmp, '=')) != NULL) {
*(cp++) = '\0';
if (*cp == '"') { /* smash quotes if present */
++cp;
- if ((cp3 = index(cp, '"')) != NULL)
+ if ((cp3 = strchr(cp, '"')) != NULL)
*cp3 = '\0';
}
- else if ((cp3 = index(cp, ',')) != NULL)
+ else if ((cp3 = strchr(cp, ',')) != NULL)
*cp3 = '\0';
cp2 = variable_get(tmp);
if (cp2 != NULL) {
@@ -305,7 +305,7 @@ pvariable_set(char *var)
msgDebug("Warning: Zero length name & value passed to variable_set()\n");
/* Add a trivial namespace to whatever name the caller chooses. */
SAFE_STRCPY(tmp, "SYSINSTALL_PVAR");
- if (index(var, '=') == NULL)
+ if (strchr(var, '=') == NULL)
msgFatal("Invalid variable format: %s", var);
strlcat(tmp, var, 1024);
p = strchr(tmp, '=');
OpenPOWER on IntegriCloud