#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));
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;
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);
} 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)
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)
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;
(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;
}
}
#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;
if (!dp)
return;
dp->name = subdir ? blkid_strconcat(dir, "/", subdir) :
- blkid_strdup(dir);
+ dir ? strdup(dir) : NULL;
+
if (!dp->name) {
free(dp);
return;
if (!value) {
if (!strchr(token, '=')) {
- ret = blkid_strdup(token);
+ ret = strdup(token);
goto out;
}
blkid_parse_tag_string(token, &t, &v);
return -BLKID_ERR_CACHE;
}
- name = blkid_strndup(start, end-start);
+ name = strndup(start, end - start);
if (name == NULL)
return -BLKID_ERR_MEM;
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);
if (!value) {
if (!strchr(token, '=')) {
- ret = blkid_strdup(token);
+ ret = strdup(token);
goto out;
}
blkid_parse_tag_string(token, &t, &v);
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
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);
if (!dev || !name)
return -BLKID_ERR_PARAM;
- if (value && !(val = blkid_strndup(value, vlength)))
+ if (value && !(val = strndup(value, vlength)))
return -BLKID_ERR_MEM;
/*
/* 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;
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,
if (!token || !(cp = strchr(token, '=')))
return -1;
- name = blkid_strdup(token);
+ name = strdup(token);
if (!name)
return -1;
value = name + (cp - token);
goto errout; /* missing closing quote */
*cp = '\0';
}
- value = blkid_strdup(value);
+ value = strdup(value);
if (!value)
goto errout;