Skip to content

Commit b3608ae

Browse files
Ed SchoutenEd Schouten
authored andcommitted
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.
1 parent 69ee3e2 commit b3608ae

File tree

51 files changed

+103
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+103
-106
lines changed

games/fortune/fortune/fortune.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ all_forts(FILEDESC *fp, char *offensive)
683683
obscene->fd = fd;
684684
obscene->inf = NULL;
685685
obscene->path = offensive;
686-
if ((sp = rindex(offensive, '/')) == NULL)
686+
if ((sp = strrchr(offensive, '/')) == NULL)
687687
obscene->name = offensive;
688688
else
689689
obscene->name = ++sp;
@@ -785,7 +785,7 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
785785
}
786786
}
787787

788-
if ((sp = rindex(file, '/')) == NULL)
788+
if ((sp = strrchr(file, '/')) == NULL)
789789
sp = file;
790790
else
791791
sp++;
@@ -797,7 +797,7 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
797797
DPRINTF(2, (stderr, "FALSE (check fortunes only)\n"));
798798
return (FALSE);
799799
}
800-
if ((sp = rindex(sp, '.')) != NULL) {
800+
if ((sp = strrchr(sp, '.')) != NULL) {
801801
sp++;
802802
for (i = 0; suflist[i] != NULL; i++)
803803
if (strcmp(sp, suflist[i]) == 0) {

lib/libc/gen/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ execvPe(const char *name, const char *path, char * const *argv,
159159
eacces = 0;
160160

161161
/* If it's an absolute or relative path name, it's easy. */
162-
if (index(name, '/')) {
162+
if (strchr(name, '/')) {
163163
bp = name;
164164
cur = NULL;
165165
goto retry;

lib/libc/gen/getttyent.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ getttyent(void)
7878
if (!fgets(p = line, lbsize, tf))
7979
return (NULL);
8080
/* extend buffer if line was too big, and retry */
81-
while (!index(p, '\n') && !feof(tf)) {
81+
while (!strchr(p, '\n') && !feof(tf)) {
8282
i = strlen(p);
8383
lbsize += MALLOCCHUNK;
8484
if ((p = realloc(line, lbsize)) == NULL) {
@@ -148,7 +148,7 @@ getttyent(void)
148148
tty.ty_comment = p;
149149
if (*p == 0)
150150
tty.ty_comment = 0;
151-
if ( (p = index(p, '\n')) )
151+
if ((p = strchr(p, '\n')))
152152
*p = '\0';
153153
return (&tty);
154154
}
@@ -196,7 +196,7 @@ static char *
196196
value(char *p)
197197
{
198198

199-
return ((p = index(p, '=')) ? ++p : NULL);
199+
return ((p = strchr(p, '=')) ? ++p : NULL);
200200
}
201201

202202
int

lib/libc/gen/timezone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ timezone(int zone, int dst)
5959
*end;
6060

6161
if ( (beg = getenv("TZNAME")) ) { /* set in environment */
62-
if ( (end = index(beg, ',')) ) {/* "PST,PDT" */
62+
if ((end = strchr(beg, ','))) { /* "PST,PDT" */
6363
if (dst)
6464
return(++end);
6565
*end = '\0';

lib/libc/net/gethostbynis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he,
9191
free(result);
9292
result = (char *)&ypbuf;
9393

94-
if ((cp = index(result, '\n')))
94+
if ((cp = strchr(result, '\n')))
9595
*cp = '\0';
9696

9797
cp = strpbrk(result, " \t");

lib/libc/net/getnetbynis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _getnetbynis(const char *name, char *map, int af, struct netent *ne,
8080
free(result);
8181
result = (char *)&ypbuf;
8282

83-
if ((cp = index(result, '\n')))
83+
if ((cp = strchr(result, '\n')))
8484
*cp = '\0';
8585

8686
cp = strpbrk(result, " \t");

lib/libcam/camlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
137137
*/
138138
if (*tmpstr == '/') {
139139
tmpstr2 = tmpstr;
140-
tmpstr = (char *)rindex(tmpstr2, '/');
140+
tmpstr = strrchr(tmpstr2, '/');
141141
if ((tmpstr != NULL) && (*tmpstr != '\0'))
142142
tmpstr++;
143143
}

lib/libstand/bootp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,13 @@ setenv_(u_char *cp, u_char *ep, struct dhcp_opt *opts)
703703
u_char *s = NULL; /* semicolon ? */
704704

705705
/* skip leading whitespace */
706-
while (*endv && index(" \t\n\r", *endv))
706+
while (*endv && strchr(" \t\n\r", *endv))
707707
endv++;
708-
vp = index(endv, '='); /* find name=value separator */
708+
vp = strchr(endv, '='); /* find name=value separator */
709709
if (!vp)
710710
break;
711711
*vp++ = 0;
712-
if (op->fmt == __ILIST && (s = index(vp, ';')))
712+
if (op->fmt == __ILIST && (s = strchr(vp, ';')))
713713
*s++ = '\0';
714714
setenv(endv, vp, 1);
715715
vp = s; /* prepare for next round */

lib/libutil/quotafile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize)
8484
}
8585
strcpy(buf, fs->fs_mntops);
8686
for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
87-
if ((cp = index(opt, '=')))
87+
if ((cp = strchr(opt, '=')))
8888
*cp++ = '\0';
8989
if (type == USRQUOTA && strcmp(opt, usrname) == 0)
9090
break;

libexec/mknetid/parse_group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ grscan(int search, int gid)
114114
return(0);
115115
bp = line;
116116
/* skip lines that are too big */
117-
if (!index(line, '\n')) {
117+
if (!strchr(line, '\n')) {
118118
int ch;
119119

120120
while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)

0 commit comments

Comments
 (0)