From: Patrick O'Leary Date: Wed, 17 Dec 2014 01:47:21 +0000 (-0600) Subject: replace deprecated `index` with `strchr` X-Git-Tag: lxc-1.1.0.rc2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46cd28455f8eedabcccf8fc1955b7199a7467807;p=thirdparty%2Flxc.git 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: Patrick O'Leary Acked-by: Stéphane Graber --- diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index 6cfba3a87..ac387b11e 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -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; diff --git a/src/lxc/cgfs.c b/src/lxc/cgfs.c index 8ff3fb3f5..20325fa3c 100644 --- a/src/lxc/cgfs.c +++ b/src/lxc/cgfs.c @@ -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); diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 4acc35400..c7db06f6a 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 2bc8f5f13..a2e964bf6 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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++; diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index d8122045d..88ea5a315 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -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; diff --git a/src/lxc/lxc_usernsexec.c b/src/lxc/lxc_usernsexec.c index fbaa083d1..19049ffcc 100644 --- a/src/lxc/lxc_usernsexec.c +++ b/src/lxc/lxc_usernsexec.c @@ -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)); diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index c7c4cf8a2..2b3e28c13 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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'; diff --git a/src/tests/attach.c b/src/tests/attach.c index 5c1ba8e51..ee827c1ba 100644 --- a/src/tests/attach.c +++ b/src/tests/attach.c @@ -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';