summaryrefslogtreecommitdiffstats
path: root/misc-utils/namei.c
diff options
context:
space:
mode:
authorSami Kerola2011-06-11 15:20:56 +0200
committerSami Kerola2011-06-25 12:37:37 +0200
commitb977951749fcd30a11c5bff608ee5a18e41c65ee (patch)
tree1847e09390a6d194e84345a9b692e99363ae86b4 /misc-utils/namei.c
parentnamei: add --version option (diff)
downloadkernel-qcow2-util-linux-b977951749fcd30a11c5bff608ee5a18e41c65ee.tar.gz
kernel-qcow2-util-linux-b977951749fcd30a11c5bff608ee5a18e41c65ee.tar.xz
kernel-qcow2-util-linux-b977951749fcd30a11c5bff608ee5a18e41c65ee.zip
namei: use xalloc.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/namei.c')
-rw-r--r--misc-utils/namei.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/misc-utils/namei.c b/misc-utils/namei.c
index f133e40fa..0db4c4295 100644
--- a/misc-utils/namei.c
+++ b/misc-utils/namei.c
@@ -105,9 +105,7 @@ add_id(struct idcache **ic, char *name, unsigned long int id, int *width)
struct idcache *nc, *x;
int w = 0;
- nc = calloc(1, sizeof(*nc));
- if (!nc)
- goto alloc_err;
+ nc = xcalloc(1, sizeof(*nc));
nc->id = id;
if (name) {
@@ -124,11 +122,9 @@ add_id(struct idcache **ic, char *name, unsigned long int id, int *width)
}
/* note, we ignore names with non-printable widechars */
if (w > 0)
- nc->name = strdup(name);
+ nc->name = xstrdup(name);
else if (asprintf(&nc->name, "%lu", id) == -1)
nc->name = NULL;
- if (!nc->name)
- goto alloc_err;
for (x = *ic; x && x->next; x = x->next);
@@ -142,8 +138,6 @@ add_id(struct idcache **ic, char *name, unsigned long int id, int *width)
*width = *width < w ? w : *width;
return;
-alloc_err:
- err(EXIT_FAILURE, _("out of memory?"));
}
static void
@@ -221,9 +215,7 @@ dotdot_stat(const char *dirname, struct stat *st)
return NULL;
len = strlen(dirname);
- path = malloc(len + sizeof(DOTDOTDIR));
- if (!path)
- err(EXIT_FAILURE, _("out of memory?"));
+ path = xmalloc(len + sizeof(DOTDOTDIR));
memcpy(path, dirname, len);
memcpy(path + len, DOTDOTDIR, sizeof(DOTDOTDIR));
@@ -241,16 +233,12 @@ new_namei(struct namei *parent, const char *path, const char *fname, int lev)
if (!fname)
return NULL;
- nm = calloc(1, sizeof(*nm));
- if (!nm)
- err(EXIT_FAILURE, _("out of memory?"));
+ nm = xcalloc(1, sizeof(*nm));
if (parent)
parent->next = nm;
nm->level = lev;
- nm->name = strdup(fname);
- if (!nm->name)
- err(EXIT_FAILURE, _("out of memory?"));
+ nm->name = xstrdup(fname);
nm->noent = (lstat(path, &nm->st) == -1);
if (nm->noent)
@@ -292,9 +280,7 @@ add_namei(struct namei *parent, const char *orgpath, int start, struct namei **l
nm = parent;
level = parent->level + 1;
}
- path = strdup(orgpath);
- if (!path)
- err(EXIT_FAILURE, _("out of memory?"));
+ path = xstrdup(orgpath);
fname = path + start;
/* root directory */