Replace all calls to rindex by strrchr

The two functions are identical but strrchr also works on Bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2013-08-16 11:53:11 +02:00
parent 4ba0d9af63
commit c32981c3fb
3 changed files with 11 additions and 11 deletions

View File

@ -540,7 +540,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
if ((p = index(output, ' ')) == NULL) if ((p = index(output, ' ')) == NULL)
return -1; return -1;
*p = '\0'; *p = '\0';
if ((p = rindex(output, '/')) == NULL) if ((p = strrchr(output, '/')) == NULL)
return -1; return -1;
*p = '\0'; *p = '\0';
} else } else
@ -796,14 +796,14 @@ static int do_lvm_create(const char *path, unsigned long size)
pathdup = strdup(path); pathdup = strdup(path);
if (!pathdup) if (!pathdup)
exit(1); exit(1);
lv = rindex(pathdup, '/'); lv = strrchr(pathdup, '/');
if (!lv) { if (!lv) {
free(pathdup); free(pathdup);
exit(1); exit(1);
} }
*lv = '\0'; *lv = '\0';
lv++; lv++;
vg = rindex(pathdup, '/'); vg = strrchr(pathdup, '/');
if (!vg) if (!vg)
exit(1); exit(1);
vg++; vg++;
@ -831,7 +831,7 @@ static int lvm_snapshot(const char *orig, const char *path, unsigned long size)
pathdup = strdup(path); pathdup = strdup(path);
if (!pathdup) if (!pathdup)
exit(1); exit(1);
lv = rindex(pathdup, '/'); lv = strrchr(pathdup, '/');
if (!lv) { if (!lv) {
free(pathdup); free(pathdup);
exit(1); exit(1);
@ -1139,7 +1139,7 @@ static int btrfs_subvolume_create(const char *path)
return -1; return -1;
} }
p = rindex(newfull, '/'); p = strrchr(newfull, '/');
if (!p) { if (!p) {
ERROR("bad path: %s", path); ERROR("bad path: %s", path);
return -1; return -1;
@ -1266,7 +1266,7 @@ static int btrfs_destroy(struct bdev *orig)
return -1; return -1;
} }
p = rindex(newfull, '/'); p = strrchr(newfull, '/');
if (!p) { if (!p) {
ERROR("bad path: %s", path); ERROR("bad path: %s", path);
return -1; return -1;

View File

@ -246,7 +246,7 @@ char *lxc_cgroup_path_get(const char *subsystem, const char *name,
return strdup("/"); return strdup("/");
} }
// path still has 'tasks' on the end, drop it // path still has 'tasks' on the end, drop it
if ((p = rindex(path, '/')) != NULL) if ((p = strrchr(path, '/')) != NULL)
*p = '\0'; *p = '\0';
return strdup(path); return strdup(path);
} }
@ -841,7 +841,7 @@ static char *find_free_cgroup(struct cgroup_desc *d, const char *lxc_name)
} }
// found it // found it
// path has '/tasks' at end, drop that // path has '/tasks' at end, drop that
if (!(cgp = rindex(path, '/'))) { if (!(cgp = strrchr(path, '/'))) {
ERROR("Got nonsensical path name %s\n", path); ERROR("Got nonsensical path name %s\n", path);
return NULL; return NULL;
} }

View File

@ -1645,7 +1645,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
for (i=0; i<NUM_LXC_HOOKS; i++) { for (i=0; i<NUM_LXC_HOOKS; i++) {
lxc_list_for_each(it, &c->lxc_conf->hooks[i]) { lxc_list_for_each(it, &c->lxc_conf->hooks[i]) {
char *hookname = it->elem; char *hookname = it->elem;
char *fname = rindex(hookname, '/'); char *fname = strrchr(hookname, '/');
char tmppath[MAXPATHLEN]; char tmppath[MAXPATHLEN];
if (!fname) // relative path - we don't support, but maybe we should if (!fname) // relative path - we don't support, but maybe we should
return 0; return 0;
@ -1706,7 +1706,7 @@ static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
if (!oldpath) if (!oldpath)
return 0; return 0;
char *p = rindex(oldpath, '/'); char *p = strrchr(oldpath, '/');
if (!p) if (!p)
return -1; return -1;
ret = snprintf(newpath, MAXPATHLEN, "%s/%s%s", ret = snprintf(newpath, MAXPATHLEN, "%s/%s%s",
@ -1845,7 +1845,7 @@ only rootfs gets converted (copied/snapshotted) on clone.
static int create_file_dirname(char *path) static int create_file_dirname(char *path)
{ {
char *p = rindex(path, '/'); char *p = strrchr(path, '/');
int ret; int ret;
if (!p) if (!p)