]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
replace deprecated `index` with `strchr`
authorPatrick O'Leary <patrick.oleary@gmail.com>
Wed, 17 Dec 2014 01:47:21 +0000 (19:47 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Sun, 25 Jan 2015 04:43:29 +0000 (23:43 -0500)
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 <patrick.oleary@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/bdev.c
src/lxc/cgfs.c
src/lxc/conf.c
src/lxc/confile.c
src/lxc/lsm/apparmor.c
src/lxc/lxc_usernsexec.c
src/lxc/lxccontainer.c
src/tests/attach.c

index 6cfba3a8738e6a93be40e067688721daedf29ed0..ac387b11ec44e5e0ddadb8d3eba6af3dd664268a 100644 (file)
@@ -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;
index 8ff3fb3f5d35f26d58516277789888f37ccd6399..20325fa3c669a335f44d4e37963977aee2869c23 100644 (file)
@@ -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);
index 4acc3540002fe055f225a4ecde585f442b12c4c6..c7db06f6a56c1651d4ea8240f24541cbd8b48ffd 100644 (file)
@@ -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;
 
index 2bc8f5f13dad29f8d1306e0e45e2e0008d6a6096..a2e964bf6d00e9efc597420562f923a8debcc622 100644 (file)
@@ -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++;
 
index d8122045dde68f7f2f8abd7dcfa5d92eac37c517..88ea5a3153fa2fef55643f583ad7e6c74f1806cc 100644 (file)
@@ -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;
index fbaa083d1a586ccb5583b5f084a5359c21af194c..19049ffccccdfcf8aac0743afd00f6b3de2d6ace 100644 (file)
@@ -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));
index c7c4cf8a26cbe0a7e31df537ec4aa27f5e8577b9..2b3e28c13c1dabdf744d92ab6e6b3048e183ba36 100644 (file)
@@ -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';
index 5c1ba8e51bf39e47f4a0519e6f65e6130c7ec59c..ee827c1ba3828640f93c1344efb63f0766479594 100644 (file)
@@ -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';