svn commit: r229272 - in head/sys: ddb dev/ata dev/mxge dev/uart
fs/nfs fs/nwfs fs/smbfs gnu/fs/xfs i386/ibcs2 kern libkern
netgraph security/mac_lomac
Ed Schouten
ed at FreeBSD.org
Mon Jan 2 12:12:11 UTC 2012
Author: ed
Date: Mon Jan 2 12:12:10 2012
New Revision: 229272
URL: http://svn.freebsd.org/changeset/base/229272
Log:
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.
Modified:
head/sys/ddb/db_input.c
head/sys/dev/ata/ata-disk.c
head/sys/dev/mxge/if_mxge.c
head/sys/dev/uart/uart_cpu_sparc64.c
head/sys/fs/nfs/nfsport.h
head/sys/fs/nwfs/nwfs_vfsops.c
head/sys/fs/smbfs/smbfs_vfsops.c
head/sys/fs/smbfs/smbfs_vnops.c
head/sys/gnu/fs/xfs/xfs_vfsops.c
head/sys/i386/ibcs2/ibcs2_socksys.c
head/sys/i386/ibcs2/ibcs2_stat.c
head/sys/kern/kern_intr.c
head/sys/kern/kern_ktr.c
head/sys/kern/kern_linker.c
head/sys/kern/subr_hints.c
head/sys/kern/tty_inq.c
head/sys/kern/uipc_mqueue.c
head/sys/libkern/fnmatch.c
head/sys/netgraph/ng_ksocket.c
head/sys/security/mac_lomac/mac_lomac.c
Modified: head/sys/ddb/db_input.c
==============================================================================
--- head/sys/ddb/db_input.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/ddb/db_input.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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;
Modified: head/sys/dev/ata/ata-disk.c
==============================================================================
--- head/sys/dev/ata/ata-disk.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/dev/ata/ata-disk.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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);
Modified: head/sys/dev/mxge/if_mxge.c
==============================================================================
--- head/sys/dev/mxge/if_mxge.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/dev/mxge/if_mxge.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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);
Modified: head/sys/dev/uart/uart_cpu_sparc64.c
==============================================================================
--- head/sys/dev/uart/uart_cpu_sparc64.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/dev/uart/uart_cpu_sparc64.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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'))
Modified: head/sys/fs/nfs/nfsport.h
==============================================================================
--- head/sys/fs/nfs/nfsport.h Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/fs/nfs/nfsport.h Mon Jan 2 12:12:10 2012 (r229272)
@@ -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.
Modified: head/sys/fs/nwfs/nwfs_vfsops.c
==============================================================================
--- head/sys/fs/nwfs/nwfs_vfsops.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/fs/nwfs/nwfs_vfsops.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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);
Modified: head/sys/fs/smbfs/smbfs_vfsops.c
==============================================================================
--- head/sys/fs/smbfs/smbfs_vfsops.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/fs/smbfs/smbfs_vfsops.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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);
Modified: head/sys/fs/smbfs/smbfs_vnops.c
==============================================================================
--- head/sys/fs/smbfs/smbfs_vnops.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/fs/smbfs/smbfs_vnops.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -1039,7 +1039,7 @@ smbfs_pathcheck(struct smbmount *smp, co
* 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, co
*/
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;
}
Modified: head/sys/gnu/fs/xfs/xfs_vfsops.c
==============================================================================
--- head/sys/gnu/fs/xfs/xfs_vfsops.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/gnu/fs/xfs/xfs_vfsops.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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)) {
Modified: head/sys/i386/ibcs2/ibcs2_socksys.c
==============================================================================
--- head/sys/i386/ibcs2/ibcs2_socksys.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/i386/ibcs2/ibcs2_socksys.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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';
Modified: head/sys/i386/ibcs2/ibcs2_stat.c
==============================================================================
--- head/sys/i386/ibcs2/ibcs2_stat.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/i386/ibcs2/ibcs2_stat.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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);
Modified: head/sys/kern/kern_intr.c
==============================================================================
--- head/sys/kern/kern_intr.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/kern_intr.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -693,9 +693,9 @@ intr_event_describe_handler(struct intr_
* 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;
Modified: head/sys/kern/kern_ktr.c
==============================================================================
--- head/sys/kern/kern_ktr.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/kern_ktr.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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)
Modified: head/sys/kern/kern_linker.c
==============================================================================
--- head/sys/kern/kern_linker.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/kern_linker.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -1013,7 +1013,7 @@ kern_kldload(struct thread *td, const ch
* (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])
Modified: head/sys/kern/subr_hints.c
==============================================================================
--- head/sys/kern/subr_hints.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/subr_hints.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -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)
Modified: head/sys/kern/tty_inq.c
==============================================================================
--- head/sys/kern/tty_inq.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/tty_inq.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -355,7 +355,7 @@ ttyinq_findchar(struct ttyinq *ti, const
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);
}
Modified: head/sys/kern/uipc_mqueue.c
==============================================================================
--- head/sys/kern/uipc_mqueue.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/kern/uipc_mqueue.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -1974,7 +1974,7 @@ kern_kmq_open(struct thread *td, const c
* 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
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);
Modified: head/sys/libkern/fnmatch.c
==============================================================================
--- head/sys/libkern/fnmatch.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/libkern/fnmatch.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -89,12 +89,12 @@ fnmatch(const char *pattern, const char
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;
}
Modified: head/sys/netgraph/ng_ksocket.c
==============================================================================
--- head/sys/netgraph/ng_ksocket.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/netgraph/ng_ksocket.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -223,7 +223,7 @@ ng_ksocket_sockaddr_parse(const struct n
/* 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 h
/* 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);
Modified: head/sys/security/mac_lomac/mac_lomac.c
==============================================================================
--- head/sys/security/mac_lomac/mac_lomac.c Mon Jan 2 09:58:39 2012 (r229271)
+++ head/sys/security/mac_lomac/mac_lomac.c Mon Jan 2 12:12:10 2012 (r229272)
@@ -762,10 +762,10 @@ lomac_parse(struct mac_lomac *ml, char *
/* 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 *
*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 *
/* 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')
More information about the svn-src-all
mailing list