Commit 46cd2845 by Patrick O'Leary Committed by Stéphane Graber

replace deprecated `index` with `strchr`

The `index` libc function was removed in POSIX 2008, and `strchr` is a direct replacement. The bionic (Android) libc has removed `index` when you are compiling for a 64-bit architecture, such as AArch64. Signed-off-by: 's avatarPatrick O'Leary <patrick.oleary@gmail.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 411c4974
......@@ -330,17 +330,17 @@ static int detect_fs(struct bdev *bdev, char *type, int len)
if (!f)
exit(1);
while (getline(&line, &linelen, f) != -1) {
sp1 = index(line, ' ');
sp1 = strchr(line, ' ');
if (!sp1)
exit(1);
*sp1 = '\0';
if (strcmp(line, l))
continue;
sp2 = index(sp1+1, ' ');
sp2 = strchr(sp1+1, ' ');
if (!sp2)
exit(1);
*sp2 = '\0';
sp3 = index(sp2+1, ' ');
sp3 = strchr(sp2+1, ' ');
if (!sp3)
exit(1);
*sp3 = '\0';
......@@ -603,7 +603,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
if (zfs_list_entry(opath, output, MAXPATHLEN)) {
// zfsroot is output up to ' '
if ((p = index(output, ' ')) == NULL)
if ((p = strchr(output, ' ')) == NULL)
return -1;
*p = '\0';
if ((p = strrchr(output, '/')) == NULL)
......@@ -723,7 +723,7 @@ static int zfs_destroy(struct bdev *orig)
}
// zfs mount is output up to ' '
if ((p = index(output, ' ')) == NULL)
if ((p = strchr(output, ' ')) == NULL)
return -1;
*p = '\0';
......@@ -2160,9 +2160,9 @@ static int overlayfs_mount(struct bdev *bdev)
// mount -t overlayfs -oupperdir=${upper},lowerdir=${lower} lower dest
dup = alloca(strlen(bdev->src)+1);
strcpy(dup, bdev->src);
if (!(lower = index(dup, ':')))
if (!(lower = strchr(dup, ':')))
return -22;
if (!(upper = index(++lower, ':')))
if (!(upper = strchr(++lower, ':')))
return -22;
*upper = '\0';
upper++;
......@@ -2360,8 +2360,8 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
int len, ret, lastslashidx;
if (!(osrc = strdup(orig->src)))
return -22;
nsrc = index(osrc, ':') + 1;
if (nsrc != osrc + 10 || (odelta = index(nsrc, ':')) == NULL) {
nsrc = strchr(osrc, ':') + 1;
if (nsrc != osrc + 10 || (odelta = strchr(nsrc, ':')) == NULL) {
free(osrc);
return -22;
}
......@@ -2445,7 +2445,7 @@ static int overlayfs_destroy(struct bdev *orig)
if (strncmp(orig->src, "overlayfs:", 10) != 0)
return -22;
upper = index(orig->src + 10, ':');
upper = strchr(orig->src + 10, ':');
if (!upper)
return -22;
upper++;
......@@ -2543,9 +2543,9 @@ static int aufs_mount(struct bdev *bdev)
// mount -t aufs -obr=${upper}=rw:${lower}=ro lower dest
dup = alloca(strlen(bdev->src)+1);
strcpy(dup, bdev->src);
if (!(lower = index(dup, ':')))
if (!(lower = strchr(dup, ':')))
return -22;
if (!(upper = index(++lower, ':')))
if (!(upper = strchr(++lower, ':')))
return -22;
*upper = '\0';
upper++;
......@@ -2680,8 +2680,8 @@ static int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldn
int len, ret;
if (!(osrc = strdup(orig->src)))
return -22;
nsrc = index(osrc, ':') + 1;
if (nsrc != osrc + 5 || (odelta = index(nsrc, ':')) == NULL) {
nsrc = strchr(osrc, ':') + 1;
if (nsrc != osrc + 5 || (odelta = strchr(nsrc, ':')) == NULL) {
free(osrc);
return -22;
}
......@@ -2727,7 +2727,7 @@ static int aufs_destroy(struct bdev *orig)
if (strncmp(orig->src, "aufs:", 5) != 0)
return -22;
upper = index(orig->src + 5, ':');
upper = strchr(orig->src + 5, ':');
if (!upper)
return -22;
upper++;
......@@ -3502,7 +3502,7 @@ struct bdev *bdev_create(const char *dest, const char *type,
}
// -B lvm,dir
if (index(type, ',') != NULL) {
if (strchr(type, ',') != NULL) {
char *dup = alloca(strlen(type)+1), *saveptr = NULL, *token;
strcpy(dup, type);
for (token = strtok_r(dup, ",", &saveptr); token;
......@@ -3517,7 +3517,7 @@ struct bdev *bdev_create(const char *dest, const char *type,
char *overlay_getlower(char *p)
{
char *p1 = index(p, ':');
char *p1 = strchr(p, ':');
if (p1)
*p1 = '\0';
return p;
......
......@@ -1280,7 +1280,7 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c
subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL)
if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path_data(subsystem, d);
......@@ -1298,7 +1298,7 @@ static int lxc_cgroupfs_set(const char *filename, const char *value, const char
subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL)
if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path(subsystem, name, lxcpath);
......@@ -1316,7 +1316,7 @@ static int lxc_cgroupfs_get(const char *filename, char *value, size_t len, const
subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL)
if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path(subsystem, name, lxcpath);
......
......@@ -3914,7 +3914,7 @@ int lxc_clear_nic(struct lxc_conf *c, const char *key)
struct lxc_list *it;
struct lxc_netdev *netdev;
p1 = index(key, '.');
p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0')
p1 = NULL;
......
......@@ -298,7 +298,7 @@ static int config_network_nic(const char *key, const char *value,
*/
if (*(key+12) < '0' || *(key+12) > '9')
goto out;
p = index(key+12, '.');
p = strchr(key+12, '.');
if (!p)
goto out;
strcpy(copy+12, p+1);
......@@ -2071,8 +2071,8 @@ static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen,
int i;
/* "lxc.hook.mount" */
subkey = index(key, '.');
if (subkey) subkey = index(subkey+1, '.');
subkey = strchr(key, '.');
if (subkey) subkey = strchr(subkey+1, '.');
if (!subkey)
return -1;
subkey++;
......@@ -2236,7 +2236,7 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
else
memset(retv, 0, inlen);
p1 = index(key, '.');
p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0') return -1;
p1++;
......
......@@ -117,10 +117,10 @@ again:
}
if (ret >= sz)
goto again;
space = index(buf, '\n');
space = strchr(buf, '\n');
if (space)
*space = '\0';
space = index(buf, ' ');
space = strchr(buf, ' ');
if (space)
*space = '\0';
return buf;
......
......@@ -214,10 +214,10 @@ static int read_default_map(char *fnam, int which, char *username)
strncmp(line, username, strlen(username)) != 0 ||
line[strlen(username)] != ':')
continue;
p1 = index(line, ':');
p1 = strchr(line, ':');
if (!p1)
continue;
p2 = index(p1+1, ':');
p2 = strchr(p1+1, ':');
if (!p2)
continue;
newmap = malloc(sizeof(*newmap));
......
......@@ -4303,7 +4303,7 @@ int list_active_containers(const char *lxcpath, char ***nret,
p++;
// Now p is the start of lxc_name
p2 = index(p, '/');
p2 = strchr(p, '/');
if (!p2 || strncmp(p2, "/command", 8) != 0)
continue;
*p2 = '\0';
......
......@@ -149,10 +149,10 @@ static int test_attach_lsm_cmd(struct lxc_container *ct)
goto err2;
}
result[ret] = '\0';
space = index(result, '\n');
space = strchr(result, '\n');
if (space)
*space = '\0';
space = index(result, ' ');
space = strchr(result, ' ');
if (space)
*space = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment