]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: remove blkid_{strndup,strdup}
authorKarel Zak <kzak@redhat.com>
Fri, 30 Nov 2012 09:56:54 +0000 (10:56 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 30 Nov 2012 09:56:54 +0000 (10:56 +0100)
Don't try to be smart. Let's use standard libc functions. (Note that
we have fallback for strndup() in include/strutils.h)

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/blkidP.h
libblkid/src/cache.c
libblkid/src/config.c
libblkid/src/devname.c
libblkid/src/devno.c
libblkid/src/evaluate.c
libblkid/src/read.c
libblkid/src/resolve.c
libblkid/src/save.c
libblkid/src/tag.c

index 9a15a948db7bfee27d5b1e122fd87773da54ab2b..774193cbc84cd9c037a22271de1e140ecb2da536 100644 (file)
@@ -286,10 +286,6 @@ struct blkid_struct_cache
 #define BLKID_BIC_FL_PROBED    0x0002  /* We probed /proc/partition devices */
 #define BLKID_BIC_FL_CHANGED   0x0004  /* Cache has changed from disk */
 
-extern char *blkid_strdup(const char *s)
-                       __attribute__((warn_unused_result));
-extern char *blkid_strndup(const char *s, const int length)
-                       __attribute__((warn_unused_result));
 extern char *blkid_strconcat(const char *a, const char *b, const char *c)
                        __attribute__((warn_unused_result));
 
index a60495aa50e3053f6147419cdc7f39177261419f..2592d6fe7692be97cb23999da49538a4d1505f2a 100644 (file)
@@ -112,13 +112,13 @@ char *blkid_get_cache_filename(struct blkid_config *conf)
 
        filename = safe_getenv("BLKID_FILE");
        if (filename)
-               filename = blkid_strdup(filename);
+               filename = strdup(filename);
        else if (conf)
-               filename = blkid_strdup(conf->cachefile);
+               filename = conf->cachefile ? strdup(conf->cachefile) : NULL;
        else {
                struct blkid_config *c = blkid_read_config(NULL);
                if (!c)
-                       filename = blkid_strdup(get_default_cache_filename());
+                       filename = strdup(get_default_cache_filename());
                else {
                        filename = c->cachefile;  /* already allocated */
                        c->cachefile = NULL;
@@ -155,7 +155,7 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
        if (filename && !*filename)
                filename = NULL;
        if (filename)
-               cache->bic_filename = blkid_strdup(filename);
+               cache->bic_filename = strdup(filename);
        else
                cache->bic_filename = blkid_get_cache_filename(NULL);
 
index 110251a92f36c5e2fdb71ddb95c607895ca65d52..edad6cd7ccabb62211c55ef4c4acf0db9a3682d4 100644 (file)
@@ -96,7 +96,7 @@ static int parse_next(FILE *fd, struct blkid_config *conf)
        } else if (!strncmp(s, "CACHE_FILE=", 11)) {
                s += 11;
                if (*s)
-                       conf->cachefile = blkid_strdup(s);
+                       conf->cachefile = strdup(s);
        } else if (!strncmp(s, "EVALUATE=", 9)) {
                s += 9;
                if (*s && parse_evaluate(conf, s) == -1)
@@ -148,7 +148,7 @@ dflt:
                conf->nevals = 2;
        }
        if (!conf->cachefile)
-               conf->cachefile = blkid_strdup(BLKID_CACHE_FILE);
+               conf->cachefile = strdup(BLKID_CACHE_FILE);
        if (conf->uevent == -1)
                conf->uevent = TRUE;
        if (f)
index 17a9e507063921d1905bab38aa201711151cc0de..95f1d7ec9b622fb8ff2b064a71bb7364cebf8834 100644 (file)
@@ -73,7 +73,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
                if (!dev)
                        return NULL;
                dev->bid_time = INT_MIN;
-               dev->bid_name = blkid_strdup(devname);
+               dev->bid_name = strdup(devname);
                dev->bid_cache = cache;
                list_add_tail(&dev->bid_devs, &cache->bic_devs);
                cache->bic_flags |= BLKID_BIC_FL_CHANGED;
@@ -208,7 +208,7 @@ static void probe_one(blkid_cache cache, const char *ptname,
                    (S_ISBLK(st.st_mode) ||
                     (S_ISCHR(st.st_mode) && !strncmp(ptname, "ubi", 3))) &&
                    st.st_rdev == devno) {
-                       devname = blkid_strdup(device);
+                       devname = strdup(device);
                        goto get_dev;
                }
        }
index 3024beefa77bce8685b08ab7d03591927d4e5dda..08ec7afd6b66394f969d47b767390ff0e86fefb2 100644 (file)
 #include "at.h"
 #include "sysfs.h"
 
-char *blkid_strndup(const char *s, int length)
-{
-       char *ret;
-
-       if (!s)
-               return NULL;
-
-       if (!length)
-               length = strlen(s);
-
-       ret = malloc(length + 1);
-       if (ret) {
-               strncpy(ret, s, length);
-               ret[length] = '\0';
-       }
-       return ret;
-}
-
-char *blkid_strdup(const char *s)
-{
-       return blkid_strndup(s, 0);
-}
-
 char *blkid_strconcat(const char *a, const char *b, const char *c)
 {
        char *res, *p;
@@ -103,7 +80,8 @@ static void add_to_dirlist(const char *dir, const char *subdir,
        if (!dp)
                return;
        dp->name = subdir ? blkid_strconcat(dir, "/", subdir) :
-                           blkid_strdup(dir);
+                  dir ? strdup(dir) : NULL;
+
        if (!dp->name) {
                free(dp);
                return;
index 52abfae54fc0ec5e3f1592359ae16ce70729f5a6..2e1ca574daa42851e6db461a3d230dcd57d76b1d 100644 (file)
@@ -240,7 +240,7 @@ char *blkid_evaluate_tag(const char *token, const char *value, blkid_cache *cach
 
        if (!value) {
                if (!strchr(token, '=')) {
-                       ret = blkid_strdup(token);
+                       ret = strdup(token);
                        goto out;
                }
                blkid_parse_tag_string(token, &t, &v);
index d31d024bc5c02fd8103138e5b9ba7c22f850ba4c..8914cad695fd8c87eec29bc1b305a8bbab556b8d 100644 (file)
@@ -221,7 +221,7 @@ static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
                return -BLKID_ERR_CACHE;
        }
 
-       name = blkid_strndup(start, end-start);
+       name = strndup(start, end - start);
        if (name == NULL)
                return -BLKID_ERR_MEM;
 
index bf5041df52275025c901588dbff5aa7d673bda28..e5c4b5876fdeb99305ae5293bb5d5efa8f40411d 100644 (file)
@@ -44,7 +44,7 @@ char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
 
        if ((dev = blkid_get_dev(c, devname, BLKID_DEV_NORMAL)) &&
            (found = blkid_find_tag_dev(dev, tagname)))
-               ret = blkid_strdup(found->bit_val);
+               ret = found->bit_val ? strdup(found->bit_val) : NULL;
 
        if (!cache)
                blkid_put_cache(c);
@@ -80,7 +80,7 @@ char *blkid_get_devname(blkid_cache cache, const char *token,
 
        if (!value) {
                if (!strchr(token, '=')) {
-                       ret = blkid_strdup(token);
+                       ret = strdup(token);
                        goto out;
                }
                blkid_parse_tag_string(token, &t, &v);
@@ -94,15 +94,13 @@ char *blkid_get_devname(blkid_cache cache, const char *token,
        if (!dev)
                goto out;
 
-       ret = blkid_strdup(blkid_dev_devname(dev));
-
+       ret = dev->bid_name ? strdup(dev->bid_name) : NULL;
 out:
        free(t);
        free(v);
-       if (!cache) {
+       if (!cache)
                blkid_put_cache(c);
-       }
-       return (ret);
+       return ret;
 }
 
 #ifdef TEST_PROGRAM
index 7ce6fa498e33f863db7f65b3ef625b713ff6ce34..46925ab2a6af78bebc9a8ceeee60f82664639146 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
                fprintf(stderr, "error (%d) probing devices\n", ret);
                exit(1);
        }
-       cache->bic_filename = blkid_strdup(argv[1]);
+       cache->bic_filename = strdup(argv[1]);
 
        if ((ret = blkid_flush_cache(cache)) < 0) {
                fprintf(stderr, "error (%d) saving cache\n", ret);
index efe67cb29034b059b0bcc80af1440d6b3c3be415..8fe3336342021ba8262613c355cc6ba8c0620334 100644 (file)
@@ -136,7 +136,7 @@ int blkid_set_tag(blkid_dev dev, const char *name,
        if (!dev || !name)
                return -BLKID_ERR_PARAM;
 
-       if (value && !(val = blkid_strndup(value, vlength)))
+       if (value && !(val = strndup(value, vlength)))
                return -BLKID_ERR_MEM;
 
        /*
@@ -167,7 +167,7 @@ int blkid_set_tag(blkid_dev dev, const char *name,
                /* Existing tag not present, add to device */
                if (!(t = blkid_new_tag()))
                        goto errout;
-               t->bit_name = blkid_strdup(name);
+               t->bit_name = name ? strdup(name) : NULL;
                t->bit_val = val;
                t->bit_dev = dev;
 
@@ -183,7 +183,7 @@ int blkid_set_tag(blkid_dev dev, const char *name,
 
                                DBG(DEBUG_TAG,
                                    printf("    creating new cache tag head %s\n", name));
-                               head->bit_name = blkid_strdup(name);
+                               head->bit_name = name ? strdup(name) : NULL;
                                if (!head->bit_name)
                                        goto errout;
                                list_add_tail(&head->bit_tags,
@@ -231,7 +231,7 @@ int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val)
        if (!token || !(cp = strchr(token, '=')))
                return -1;
 
-       name = blkid_strdup(token);
+       name = strdup(token);
        if (!name)
                return -1;
        value = name + (cp - token);
@@ -242,7 +242,7 @@ int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val)
                        goto errout; /* missing closing quote */
                *cp = '\0';
        }
-       value = blkid_strdup(value);
+       value = strdup(value);
        if (!value)
                goto errout;