aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2012-01-03 18:51:58 +0000
committerEd Schouten <ed@FreeBSD.org>2012-01-03 18:51:58 +0000
commitb3608ae18f1e5598bed81d0a10dd585a5080c40d (patch)
treeb751618c7a82d9c00cab91ea9f611585dbf14d84 /usr.sbin
parent69ee3e2f52eb8cba6e103cd1de3f91a7ffe1ddc7 (diff)
downloadsrc-b3608ae18f1e5598bed81d0a10dd585a5080c40d.tar.gz
src-b3608ae18f1e5598bed81d0a10dd585a5080c40d.zip
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.
Notes
Notes: svn path=/head/; revision=229403
Diffstat (limited to 'usr.sbin')
-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
9 files changed, 26 insertions, 26 deletions
diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c
index 5c1d264a1650..09213058bbd4 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 ceee035de7d3..28d4f8abe466 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 9ae52af074dc..4cbc1356f83a 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 0a39fdf7f648..7dc77b355947 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 c7543ef0b8f0..d579bd94ef01 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 c7c6460de214..417932db4310 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 4e3d0773f2b5..c2fdee26ce12 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 30cc2cf439a0..16bf9482c0cc 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 911eb029e1ca..ae3a6e03e073 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, '=');