summaryrefslogtreecommitdiffstats
path: root/libblkid
diff options
context:
space:
mode:
authorKarel Zak2012-11-30 10:56:54 +0100
committerKarel Zak2012-11-30 10:56:54 +0100
commite0a9b8cf2d7a2f0264332fbc870341103840ed06 (patch)
treef90a7e6230176b90ee4448a994b0c1dd5d489646 /libblkid
parentlibblkid: add function attributes to private API (diff)
downloadkernel-qcow2-util-linux-e0a9b8cf2d7a2f0264332fbc870341103840ed06.tar.gz
kernel-qcow2-util-linux-e0a9b8cf2d7a2f0264332fbc870341103840ed06.tar.xz
kernel-qcow2-util-linux-e0a9b8cf2d7a2f0264332fbc870341103840ed06.zip
libblkid: remove blkid_{strndup,strdup}
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>
Diffstat (limited to 'libblkid')
-rw-r--r--libblkid/src/blkidP.h4
-rw-r--r--libblkid/src/cache.c8
-rw-r--r--libblkid/src/config.c4
-rw-r--r--libblkid/src/devname.c4
-rw-r--r--libblkid/src/devno.c26
-rw-r--r--libblkid/src/evaluate.c2
-rw-r--r--libblkid/src/read.c2
-rw-r--r--libblkid/src/resolve.c12
-rw-r--r--libblkid/src/save.c2
-rw-r--r--libblkid/src/tag.c10
10 files changed, 23 insertions, 51 deletions
diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index 9a15a948d..774193cbc 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -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));
diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c
index a60495aa5..2592d6fe7 100644
--- a/libblkid/src/cache.c
+++ b/libblkid/src/cache.c
@@ -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);
diff --git a/libblkid/src/config.c b/libblkid/src/config.c
index 110251a92..edad6cd7c 100644
--- a/libblkid/src/config.c
+++ b/libblkid/src/config.c
@@ -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)
diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c
index 17a9e5070..95f1d7ec9 100644
--- a/libblkid/src/devname.c
+++ b/libblkid/src/devname.c
@@ -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;
}
}
diff --git a/libblkid/src/devno.c b/libblkid/src/devno.c
index 3024beefa..08ec7afd6 100644
--- a/libblkid/src/devno.c
+++ b/libblkid/src/devno.c
@@ -37,29 +37,6 @@
#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;
diff --git a/libblkid/src/evaluate.c b/libblkid/src/evaluate.c
index 52abfae54..2e1ca574d 100644
--- a/libblkid/src/evaluate.c
+++ b/libblkid/src/evaluate.c
@@ -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);
diff --git a/libblkid/src/read.c b/libblkid/src/read.c
index d31d024bc..8914cad69 100644
--- a/libblkid/src/read.c
+++ b/libblkid/src/read.c
@@ -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;
diff --git a/libblkid/src/resolve.c b/libblkid/src/resolve.c
index bf5041df5..e5c4b5876 100644
--- a/libblkid/src/resolve.c
+++ b/libblkid/src/resolve.c
@@ -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
diff --git a/libblkid/src/save.c b/libblkid/src/save.c
index 7ce6fa498..46925ab2a 100644
--- a/libblkid/src/save.c
+++ b/libblkid/src/save.c
@@ -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);
diff --git a/libblkid/src/tag.c b/libblkid/src/tag.c
index efe67cb29..8fe333634 100644
--- a/libblkid/src/tag.c
+++ b/libblkid/src/tag.c
@@ -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;