Use strchr() and strrchr().

It seems strchr() and strrchr() are used more often than index() and
rindex(). Therefore, simply migrate all kernel code to use it.

For the XFS code, remove an empty line to make the code identical to
the code in the Linux kernel.
This commit is contained in:
Ed Schouten 2012-01-02 12:12:10 +00:00
parent 762ad1d614
commit dc15eac046
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=229272
20 changed files with 47 additions and 49 deletions

View File

@ -253,7 +253,7 @@ db_inputchar(c)
db_putnchars(BACKUP, db_lc - db_lbuf_start);
db_putnchars(BLANK, db_le - db_lbuf_start);
db_putnchars(BACKUP, db_le - db_lbuf_start);
db_le = index(db_lbuf_start, '\0');
db_le = strchr(db_lbuf_start, '\0');
if (db_le[-1] == '\r' || db_le[-1] == '\n')
*--db_le = '\0';
db_lc = db_le;

View File

@ -532,8 +532,8 @@ ad_describe(device_t dev)
u_int8_t *marker, vendor[64], product[64];
/* try to separate the ATA model string into vendor and model parts */
if ((marker = index(atadev->param.model, ' ')) ||
(marker = index(atadev->param.model, '-'))) {
if ((marker = strchr(atadev->param.model, ' ')) ||
(marker = strchr(atadev->param.model, '-'))) {
int len = (marker - atadev->param.model);
strncpy(vendor, atadev->param.model, len);

View File

@ -2827,7 +2827,7 @@ mxge_media_init(mxge_softc_t *sc)
}
for (i = 0; i < 3; i++, ptr++) {
ptr = index(ptr, '-');
ptr = strchr(ptr, '-');
if (ptr == NULL) {
device_printf(sc->dev,
"only %d dashes in PC?!?\n", i);

View File

@ -71,7 +71,7 @@ uart_cpu_channel(char *dev)
if ((aliases = OF_finddevice("/aliases")) != -1)
(void)OF_getprop(aliases, dev, alias, sizeof(alias));
len = strlen(alias);
if ((p = rindex(alias, ':')) == NULL)
if ((p = strrchr(alias, ':')) == NULL)
return (0);
p++;
if (p - alias == len - 1 && (*p == 'a' || *p == 'b'))

View File

@ -712,7 +712,7 @@ MALLOC_DECLARE(M_NEWNFSDROLLBACK);
/*
* Set this macro to index() or strchr(), whichever is supported.
*/
#define STRCHR(s, c) index((s), (c))
#define STRCHR(s, c) strchr((s), (c))
/*
* Set the n_time in the client write rpc, as required.

View File

@ -206,10 +206,10 @@ static int nwfs_mount(struct mount *mp)
pe = pc+sizeof(mp->mnt_stat.f_mntfromname);
bzero(pc, MNAMELEN);
*(pc++) = '/';
pc = index(strncpy(pc, conn->li.server, pe-pc-2),0);
pc = strchr(strncpy(pc, conn->li.server, pe - pc - 2), 0);
if (pc < pe-1) {
*(pc++) = ':';
pc=index(strncpy(pc, conn->li.user, pe-pc-2),0);
pc = strchr(strncpy(pc, conn->li.user, pe - pc - 2), 0);
if (pc < pe-1) {
*(pc++) = '/';
strncpy(pc, nmp->m.mounted_vol, pe-pc-2);

View File

@ -234,10 +234,10 @@ smbfs_mount(struct mount *mp)
bzero(pc, MNAMELEN);
*pc++ = '/';
*pc++ = '/';
pc=index(strncpy(pc, vcp->vc_username, pe - pc - 2), 0);
pc = strchr(strncpy(pc, vcp->vc_username, pe - pc - 2), 0);
if (pc < pe-1) {
*(pc++) = '@';
pc = index(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0);
pc = strchr(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0);
if (pc < pe - 1) {
*(pc++) = '/';
strncpy(pc, ssp->ss_name, pe - pc - 2);

View File

@ -1039,7 +1039,7 @@ smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
* Backslash characters, being a path delimiter, are prohibited
* within a path component even for LOOKUP operations.
*/
if (index(name, '\\') != NULL)
if (strchr(name, '\\') != NULL)
return ENOENT;
if (nameiop == LOOKUP)
@ -1051,20 +1051,20 @@ smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
*/
if (nmlen > 12)
return ENAMETOOLONG;
cp = index(name, '.');
cp = strchr(name, '.');
if (cp == NULL)
return error;
if (cp == name || (cp - name) > 8)
return error;
cp = index(cp + 1, '.');
cp = strchr(cp + 1, '.');
if (cp != NULL)
return error;
for (cp = name, i = 0; i < nmlen; i++, cp++)
if (index(badchars83, *cp) != NULL)
if (strchr(badchars83, *cp) != NULL)
return error;
}
for (cp = name, i = 0; i < nmlen; i++, cp++)
if (index(badchars, *cp) != NULL)
if (strchr(badchars, *cp) != NULL)
return error;
return 0;
}

View File

@ -1743,8 +1743,7 @@ xfs_parseargs(
while ((this_char = strsep(&options, ",")) != NULL) {
if (!*this_char)
continue;
if ((value = index(this_char, '=')) != NULL)
if ((value = strchr(this_char, '=')) != NULL)
*value++ = 0;
if (!strcmp(this_char, MNTOPT_LOGBUFS)) {

View File

@ -152,7 +152,7 @@ ibcs2_getipdomainname(td, uap)
/* Get the domain name. */
getcredhostname(td->td_ucred, hname, sizeof(hname));
dptr = index(hname, '.');
dptr = strchr(hname, '.');
if ( dptr )
dptr++;
else
@ -182,7 +182,7 @@ ibcs2_setipdomainname(td, uap)
return EINVAL;
/* Get the host's unqualified name (strip off the domain) */
ptr = index(hname, '.');
ptr = strchr(hname, '.');
if ( ptr != NULL ) {
ptr++;
*ptr = '\0';

View File

@ -212,7 +212,7 @@ ibcs2_utssys(td, uap)
IBCS2_UNAME_VERSION, sizeof(sut.version) - 1);
getcredhostname(td->td_ucred, machine_name,
sizeof(machine_name) - 1);
p = index(machine_name, '.');
p = strchr(machine_name, '.');
if ( p )
*p = '\0';
strncpy(sut.nodename, machine_name, sizeof(sut.nodename) - 1);

View File

@ -693,9 +693,9 @@ intr_event_describe_handler(struct intr_event *ie, void *cookie,
* description at that point. If one is not found, find the
* end of the name to use as the insertion point.
*/
start = index(ih->ih_name, ':');
start = strchr(ih->ih_name, ':');
if (start == NULL)
start = index(ih->ih_name, 0);
start = strchr(ih->ih_name, 0);
/*
* See if there is enough remaining room in the string for the
@ -1832,8 +1832,8 @@ DB_SHOW_COMMAND(intr, db_show_intr)
struct intr_event *ie;
int all, verbose;
verbose = index(modif, 'v') != NULL;
all = index(modif, 'a') != NULL;
verbose = strchr(modif, 'v') != NULL;
all = strchr(modif, 'a') != NULL;
TAILQ_FOREACH(ie, &event_list, ie_list) {
if (!all && TAILQ_EMPTY(&ie->ie_handlers))
continue;

View File

@ -341,9 +341,9 @@ DB_SHOW_COMMAND(ktr, db_ktr_all)
tstate.cur = (ktr_idx - 1) & (KTR_ENTRIES - 1);
tstate.first = -1;
db_ktr_verbose = 0;
db_ktr_verbose |= (index(modif, 'v') != NULL) ? 2 : 0;
db_ktr_verbose |= (index(modif, 'V') != NULL) ? 1 : 0; /* just timestap please */
if (index(modif, 'a') != NULL) {
db_ktr_verbose |= (strchr(modif, 'v') != NULL) ? 2 : 0;
db_ktr_verbose |= (strchr(modif, 'V') != NULL) ? 1 : 0; /* just timestap please */
if (strchr(modif, 'a') != NULL) {
db_disable_pager();
while (cncheckc() != -1)
if (db_mach_vtrace() == 0)

View File

@ -1013,7 +1013,7 @@ kern_kldload(struct thread *td, const char *file, int *fileid)
* (kldname.ko, or kldname.ver.ko) treat it as an interface
* name.
*/
if (index(file, '/') || index(file, '.')) {
if (strchr(file, '/') || strchr(file, '.')) {
kldname = file;
modname = NULL;
} else {
@ -1906,7 +1906,7 @@ linker_search_kld(const char *name)
int len;
/* qualified at all? */
if (index(name, '/'))
if (strchr(name, '/'))
return (linker_strdup(name));
/* traverse the linker path */
@ -1927,7 +1927,7 @@ linker_basename(const char *path)
{
const char *filename;
filename = rindex(path, '/');
filename = strrchr(path, '/');
if (filename == NULL)
return path;
if (filename[1])

View File

@ -133,8 +133,7 @@ res_find(int *line, int *startln,
r_name, &r_unit, r_resname, r_value);
if (hit && n != 4) {
printf("CONFIG: invalid hint '%s'\n", cp);
/* XXX: abuse bogus index() declaration */
p = index(cp, 'h');
p = strchr(cp, 'h');
*p = 'H';
hit = 0;
}
@ -172,18 +171,18 @@ res_find(int *line, int *startln,
s = cp;
/* This is a bit of a hack, but at least is reentrant */
/* Note that it returns some !unterminated! strings. */
s = index(s, '.') + 1; /* start of device */
s = strchr(s, '.') + 1; /* start of device */
if (ret_name)
*ret_name = s;
s = index(s, '.') + 1; /* start of unit */
s = strchr(s, '.') + 1; /* start of unit */
if (ret_namelen && ret_name)
*ret_namelen = s - *ret_name - 1; /* device length */
if (ret_unit)
*ret_unit = r_unit;
s = index(s, '.') + 1; /* start of resname */
s = strchr(s, '.') + 1; /* start of resname */
if (ret_resname)
*ret_resname = s;
s = index(s, '=') + 1; /* start of value */
s = strchr(s, '=') + 1; /* start of value */
if (ret_resnamelen && ret_resname)
*ret_resnamelen = s - *ret_resname - 1; /* value len */
if (ret_value)

View File

@ -355,7 +355,7 @@ ttyinq_findchar(struct ttyinq *ti, const char *breakc, size_t maxlen,
return (0);
while (boff < bend) {
if (index(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
if (strchr(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
*lastc = tib->tib_data[boff];
return (boff - ti->ti_begin + 1);
}

View File

@ -1974,7 +1974,7 @@ kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode,
* characters.
*/
len = strlen(path);
if (len < 2 || path[0] != '/' || index(path + 1, '/') != NULL)
if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
return (EINVAL);
error = falloc(td, &fp, &fd, 0);
@ -2077,7 +2077,7 @@ sys_kmq_unlink(struct thread *td, struct kmq_unlink_args *uap)
return (error);
len = strlen(path);
if (len < 2 || path[0] != '/' || index(path + 1, '/') != NULL)
if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
return (EINVAL);
sx_xlock(&mqfs_data.mi_lock);

View File

@ -89,12 +89,12 @@ fnmatch(const char *pattern, const char *string, int flags)
if (c == EOS)
if (flags & FNM_PATHNAME)
return ((flags & FNM_LEADING_DIR) ||
index(string, '/') == NULL ?
strchr(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = index(string, '/')) == NULL)
if ((string = strchr(string, '/')) == NULL)
return (FNM_NOMATCH);
break;
}

View File

@ -223,7 +223,7 @@ ng_ksocket_sockaddr_parse(const struct ng_parse_type *type,
/* Get socket address family followed by a slash */
while (isspace(s[*off]))
(*off)++;
if ((t = index(s + *off, '/')) == NULL)
if ((t = strchr(s + *off, '/')) == NULL)
return (EINVAL);
if ((len = t - (s + *off)) > sizeof(fambuf) - 1)
return (EINVAL);
@ -565,14 +565,14 @@ ng_ksocket_newhook(node_p node, hook_p hook, const char *name0)
/* Extract family, type, and protocol from hook name */
snprintf(name, sizeof(name), "%s", name0);
s1 = name;
if ((s2 = index(s1, '/')) == NULL)
if ((s2 = strchr(s1, '/')) == NULL)
return (EINVAL);
*s2++ = '\0';
family = ng_ksocket_parse(ng_ksocket_families, s1, 0);
if (family == -1)
return (EINVAL);
s1 = s2;
if ((s2 = index(s1, '/')) == NULL)
if ((s2 = strchr(s1, '/')) == NULL)
return (EINVAL);
*s2++ = '\0';
type = ng_ksocket_parse(ng_ksocket_types, s1, 0);

View File

@ -762,10 +762,10 @@ lomac_parse(struct mac_lomac *ml, char *string)
/* Do we have a range? */
single = string;
range = index(string, '(');
range = strchr(string, '(');
if (range == single)
single = NULL;
auxsingle = index(string, '[');
auxsingle = strchr(string, '[');
if (auxsingle == single)
single = NULL;
if (range != NULL && auxsingle != NULL)
@ -776,13 +776,13 @@ lomac_parse(struct mac_lomac *ml, char *string)
*range = '\0';
range++;
rangelow = range;
rangehigh = index(rangelow, '-');
rangehigh = strchr(rangelow, '-');
if (rangehigh == NULL)
return (EINVAL);
rangehigh++;
if (*rangelow == '\0' || *rangehigh == '\0')
return (EINVAL);
rangeend = index(rangehigh, ')');
rangeend = strchr(rangehigh, ')');
if (rangeend == NULL)
return (EINVAL);
if (*(rangeend + 1) != '\0')
@ -798,7 +798,7 @@ lomac_parse(struct mac_lomac *ml, char *string)
/* Nul terminate the end of the single string. */
*auxsingle = '\0';
auxsingle++;
auxsingleend = index(auxsingle, ']');
auxsingleend = strchr(auxsingle, ']');
if (auxsingleend == NULL)
return (EINVAL);
if (*(auxsingleend + 1) != '\0')