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) ...@@ -330,17 +330,17 @@ static int detect_fs(struct bdev *bdev, char *type, int len)
if (!f) if (!f)
exit(1); exit(1);
while (getline(&line, &linelen, f) != -1) { while (getline(&line, &linelen, f) != -1) {
sp1 = index(line, ' '); sp1 = strchr(line, ' ');
if (!sp1) if (!sp1)
exit(1); exit(1);
*sp1 = '\0'; *sp1 = '\0';
if (strcmp(line, l)) if (strcmp(line, l))
continue; continue;
sp2 = index(sp1+1, ' '); sp2 = strchr(sp1+1, ' ');
if (!sp2) if (!sp2)
exit(1); exit(1);
*sp2 = '\0'; *sp2 = '\0';
sp3 = index(sp2+1, ' '); sp3 = strchr(sp2+1, ' ');
if (!sp3) if (!sp3)
exit(1); exit(1);
*sp3 = '\0'; *sp3 = '\0';
...@@ -603,7 +603,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname, ...@@ -603,7 +603,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
if (zfs_list_entry(opath, output, MAXPATHLEN)) { if (zfs_list_entry(opath, output, MAXPATHLEN)) {
// zfsroot is output up to ' ' // zfsroot is output up to ' '
if ((p = index(output, ' ')) == NULL) if ((p = strchr(output, ' ')) == NULL)
return -1; return -1;
*p = '\0'; *p = '\0';
if ((p = strrchr(output, '/')) == NULL) if ((p = strrchr(output, '/')) == NULL)
...@@ -723,7 +723,7 @@ static int zfs_destroy(struct bdev *orig) ...@@ -723,7 +723,7 @@ static int zfs_destroy(struct bdev *orig)
} }
// zfs mount is output up to ' ' // zfs mount is output up to ' '
if ((p = index(output, ' ')) == NULL) if ((p = strchr(output, ' ')) == NULL)
return -1; return -1;
*p = '\0'; *p = '\0';
...@@ -2160,9 +2160,9 @@ static int overlayfs_mount(struct bdev *bdev) ...@@ -2160,9 +2160,9 @@ static int overlayfs_mount(struct bdev *bdev)
// mount -t overlayfs -oupperdir=${upper},lowerdir=${lower} lower dest // mount -t overlayfs -oupperdir=${upper},lowerdir=${lower} lower dest
dup = alloca(strlen(bdev->src)+1); dup = alloca(strlen(bdev->src)+1);
strcpy(dup, bdev->src); strcpy(dup, bdev->src);
if (!(lower = index(dup, ':'))) if (!(lower = strchr(dup, ':')))
return -22; return -22;
if (!(upper = index(++lower, ':'))) if (!(upper = strchr(++lower, ':')))
return -22; return -22;
*upper = '\0'; *upper = '\0';
upper++; upper++;
...@@ -2360,8 +2360,8 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char ...@@ -2360,8 +2360,8 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
int len, ret, lastslashidx; int len, ret, lastslashidx;
if (!(osrc = strdup(orig->src))) if (!(osrc = strdup(orig->src)))
return -22; return -22;
nsrc = index(osrc, ':') + 1; nsrc = strchr(osrc, ':') + 1;
if (nsrc != osrc + 10 || (odelta = index(nsrc, ':')) == NULL) { if (nsrc != osrc + 10 || (odelta = strchr(nsrc, ':')) == NULL) {
free(osrc); free(osrc);
return -22; return -22;
} }
...@@ -2445,7 +2445,7 @@ static int overlayfs_destroy(struct bdev *orig) ...@@ -2445,7 +2445,7 @@ static int overlayfs_destroy(struct bdev *orig)
if (strncmp(orig->src, "overlayfs:", 10) != 0) if (strncmp(orig->src, "overlayfs:", 10) != 0)
return -22; return -22;
upper = index(orig->src + 10, ':'); upper = strchr(orig->src + 10, ':');
if (!upper) if (!upper)
return -22; return -22;
upper++; upper++;
...@@ -2543,9 +2543,9 @@ static int aufs_mount(struct bdev *bdev) ...@@ -2543,9 +2543,9 @@ static int aufs_mount(struct bdev *bdev)
// mount -t aufs -obr=${upper}=rw:${lower}=ro lower dest // mount -t aufs -obr=${upper}=rw:${lower}=ro lower dest
dup = alloca(strlen(bdev->src)+1); dup = alloca(strlen(bdev->src)+1);
strcpy(dup, bdev->src); strcpy(dup, bdev->src);
if (!(lower = index(dup, ':'))) if (!(lower = strchr(dup, ':')))
return -22; return -22;
if (!(upper = index(++lower, ':'))) if (!(upper = strchr(++lower, ':')))
return -22; return -22;
*upper = '\0'; *upper = '\0';
upper++; upper++;
...@@ -2680,8 +2680,8 @@ static int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldn ...@@ -2680,8 +2680,8 @@ static int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldn
int len, ret; int len, ret;
if (!(osrc = strdup(orig->src))) if (!(osrc = strdup(orig->src)))
return -22; return -22;
nsrc = index(osrc, ':') + 1; nsrc = strchr(osrc, ':') + 1;
if (nsrc != osrc + 5 || (odelta = index(nsrc, ':')) == NULL) { if (nsrc != osrc + 5 || (odelta = strchr(nsrc, ':')) == NULL) {
free(osrc); free(osrc);
return -22; return -22;
} }
...@@ -2727,7 +2727,7 @@ static int aufs_destroy(struct bdev *orig) ...@@ -2727,7 +2727,7 @@ static int aufs_destroy(struct bdev *orig)
if (strncmp(orig->src, "aufs:", 5) != 0) if (strncmp(orig->src, "aufs:", 5) != 0)
return -22; return -22;
upper = index(orig->src + 5, ':'); upper = strchr(orig->src + 5, ':');
if (!upper) if (!upper)
return -22; return -22;
upper++; upper++;
...@@ -3502,7 +3502,7 @@ struct bdev *bdev_create(const char *dest, const char *type, ...@@ -3502,7 +3502,7 @@ struct bdev *bdev_create(const char *dest, const char *type,
} }
// -B lvm,dir // -B lvm,dir
if (index(type, ',') != NULL) { if (strchr(type, ',') != NULL) {
char *dup = alloca(strlen(type)+1), *saveptr = NULL, *token; char *dup = alloca(strlen(type)+1), *saveptr = NULL, *token;
strcpy(dup, type); strcpy(dup, type);
for (token = strtok_r(dup, ",", &saveptr); token; for (token = strtok_r(dup, ",", &saveptr); token;
...@@ -3517,7 +3517,7 @@ struct bdev *bdev_create(const char *dest, const char *type, ...@@ -3517,7 +3517,7 @@ struct bdev *bdev_create(const char *dest, const char *type,
char *overlay_getlower(char *p) char *overlay_getlower(char *p)
{ {
char *p1 = index(p, ':'); char *p1 = strchr(p, ':');
if (p1) if (p1)
*p1 = '\0'; *p1 = '\0';
return p; return p;
......
...@@ -1280,7 +1280,7 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c ...@@ -1280,7 +1280,7 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c
subsystem = alloca(strlen(filename) + 1); subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename); strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL) if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0'; *p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path_data(subsystem, d); 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 ...@@ -1298,7 +1298,7 @@ static int lxc_cgroupfs_set(const char *filename, const char *value, const char
subsystem = alloca(strlen(filename) + 1); subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename); strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL) if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0'; *p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path(subsystem, name, lxcpath); 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 ...@@ -1316,7 +1316,7 @@ static int lxc_cgroupfs_get(const char *filename, char *value, size_t len, const
subsystem = alloca(strlen(filename) + 1); subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename); strcpy(subsystem, filename);
if ((p = index(subsystem, '.')) != NULL) if ((p = strchr(subsystem, '.')) != NULL)
*p = '\0'; *p = '\0';
path = lxc_cgroup_get_hierarchy_abs_path(subsystem, name, lxcpath); 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) ...@@ -3914,7 +3914,7 @@ int lxc_clear_nic(struct lxc_conf *c, const char *key)
struct lxc_list *it; struct lxc_list *it;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
p1 = index(key, '.'); p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0') if (!p1 || *(p1+1) == '\0')
p1 = NULL; p1 = NULL;
......
...@@ -298,7 +298,7 @@ static int config_network_nic(const char *key, const char *value, ...@@ -298,7 +298,7 @@ static int config_network_nic(const char *key, const char *value,
*/ */
if (*(key+12) < '0' || *(key+12) > '9') if (*(key+12) < '0' || *(key+12) > '9')
goto out; goto out;
p = index(key+12, '.'); p = strchr(key+12, '.');
if (!p) if (!p)
goto out; goto out;
strcpy(copy+12, p+1); strcpy(copy+12, p+1);
...@@ -2071,8 +2071,8 @@ static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen, ...@@ -2071,8 +2071,8 @@ static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen,
int i; int i;
/* "lxc.hook.mount" */ /* "lxc.hook.mount" */
subkey = index(key, '.'); subkey = strchr(key, '.');
if (subkey) subkey = index(subkey+1, '.'); if (subkey) subkey = strchr(subkey+1, '.');
if (!subkey) if (!subkey)
return -1; return -1;
subkey++; subkey++;
...@@ -2236,7 +2236,7 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen, ...@@ -2236,7 +2236,7 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
p1 = index(key, '.'); p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0') return -1; if (!p1 || *(p1+1) == '\0') return -1;
p1++; p1++;
......
...@@ -117,10 +117,10 @@ again: ...@@ -117,10 +117,10 @@ again:
} }
if (ret >= sz) if (ret >= sz)
goto again; goto again;
space = index(buf, '\n'); space = strchr(buf, '\n');
if (space) if (space)
*space = '\0'; *space = '\0';
space = index(buf, ' '); space = strchr(buf, ' ');
if (space) if (space)
*space = '\0'; *space = '\0';
return buf; return buf;
......
...@@ -214,10 +214,10 @@ static int read_default_map(char *fnam, int which, char *username) ...@@ -214,10 +214,10 @@ static int read_default_map(char *fnam, int which, char *username)
strncmp(line, username, strlen(username)) != 0 || strncmp(line, username, strlen(username)) != 0 ||
line[strlen(username)] != ':') line[strlen(username)] != ':')
continue; continue;
p1 = index(line, ':'); p1 = strchr(line, ':');
if (!p1) if (!p1)
continue; continue;
p2 = index(p1+1, ':'); p2 = strchr(p1+1, ':');
if (!p2) if (!p2)
continue; continue;
newmap = malloc(sizeof(*newmap)); newmap = malloc(sizeof(*newmap));
......
...@@ -4303,7 +4303,7 @@ int list_active_containers(const char *lxcpath, char ***nret, ...@@ -4303,7 +4303,7 @@ int list_active_containers(const char *lxcpath, char ***nret,
p++; p++;
// Now p is the start of lxc_name // Now p is the start of lxc_name
p2 = index(p, '/'); p2 = strchr(p, '/');
if (!p2 || strncmp(p2, "/command", 8) != 0) if (!p2 || strncmp(p2, "/command", 8) != 0)
continue; continue;
*p2 = '\0'; *p2 = '\0';
......
...@@ -149,10 +149,10 @@ static int test_attach_lsm_cmd(struct lxc_container *ct) ...@@ -149,10 +149,10 @@ static int test_attach_lsm_cmd(struct lxc_container *ct)
goto err2; goto err2;
} }
result[ret] = '\0'; result[ret] = '\0';
space = index(result, '\n'); space = strchr(result, '\n');
if (space) if (space)
*space = '\0'; *space = '\0';
space = index(result, ' '); space = strchr(result, ' ');
if (space) if (space)
*space = '\0'; *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