namei: use xalloc.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
64718fe7d9
commit
b977951749
|
@ -105,9 +105,7 @@ add_id(struct idcache **ic, char *name, unsigned long int id, int *width)
|
||||||
struct idcache *nc, *x;
|
struct idcache *nc, *x;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
|
||||||
nc = calloc(1, sizeof(*nc));
|
nc = xcalloc(1, sizeof(*nc));
|
||||||
if (!nc)
|
|
||||||
goto alloc_err;
|
|
||||||
nc->id = id;
|
nc->id = id;
|
||||||
|
|
||||||
if (name) {
|
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 */
|
/* note, we ignore names with non-printable widechars */
|
||||||
if (w > 0)
|
if (w > 0)
|
||||||
nc->name = strdup(name);
|
nc->name = xstrdup(name);
|
||||||
else if (asprintf(&nc->name, "%lu", id) == -1)
|
else if (asprintf(&nc->name, "%lu", id) == -1)
|
||||||
nc->name = NULL;
|
nc->name = NULL;
|
||||||
if (!nc->name)
|
|
||||||
goto alloc_err;
|
|
||||||
|
|
||||||
for (x = *ic; x && x->next; x = x->next);
|
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;
|
*width = *width < w ? w : *width;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
alloc_err:
|
|
||||||
err(EXIT_FAILURE, _("out of memory?"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -221,9 +215,7 @@ dotdot_stat(const char *dirname, struct stat *st)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
len = strlen(dirname);
|
len = strlen(dirname);
|
||||||
path = malloc(len + sizeof(DOTDOTDIR));
|
path = xmalloc(len + sizeof(DOTDOTDIR));
|
||||||
if (!path)
|
|
||||||
err(EXIT_FAILURE, _("out of memory?"));
|
|
||||||
|
|
||||||
memcpy(path, dirname, len);
|
memcpy(path, dirname, len);
|
||||||
memcpy(path + len, DOTDOTDIR, sizeof(DOTDOTDIR));
|
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)
|
if (!fname)
|
||||||
return NULL;
|
return NULL;
|
||||||
nm = calloc(1, sizeof(*nm));
|
nm = xcalloc(1, sizeof(*nm));
|
||||||
if (!nm)
|
|
||||||
err(EXIT_FAILURE, _("out of memory?"));
|
|
||||||
if (parent)
|
if (parent)
|
||||||
parent->next = nm;
|
parent->next = nm;
|
||||||
|
|
||||||
nm->level = lev;
|
nm->level = lev;
|
||||||
nm->name = strdup(fname);
|
nm->name = xstrdup(fname);
|
||||||
if (!nm->name)
|
|
||||||
err(EXIT_FAILURE, _("out of memory?"));
|
|
||||||
|
|
||||||
nm->noent = (lstat(path, &nm->st) == -1);
|
nm->noent = (lstat(path, &nm->st) == -1);
|
||||||
if (nm->noent)
|
if (nm->noent)
|
||||||
|
@ -292,9 +280,7 @@ add_namei(struct namei *parent, const char *orgpath, int start, struct namei **l
|
||||||
nm = parent;
|
nm = parent;
|
||||||
level = parent->level + 1;
|
level = parent->level + 1;
|
||||||
}
|
}
|
||||||
path = strdup(orgpath);
|
path = xstrdup(orgpath);
|
||||||
if (!path)
|
|
||||||
err(EXIT_FAILURE, _("out of memory?"));
|
|
||||||
fname = path + start;
|
fname = path + start;
|
||||||
|
|
||||||
/* root directory */
|
/* root directory */
|
||||||
|
|
Loading…
Reference in New Issue