From 87f3feac713c7aa652bb1d7e4e231ed06a960f4c Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Fri, 15 Oct 2010 11:59:18 -0300 Subject: [PATCH] misc-utils: use new xmalloc() wrapper Signed-off-by: Davidlohr Bueso --- misc-utils/namei.c | 6 +++--- misc-utils/rename.c | 8 +++----- misc-utils/setterm.c | 1 + misc-utils/wipefs.c | 10 +--------- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 9873cda9..0342a08c 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -19,6 +19,7 @@ * Arkadiusz Mikiewicz (1999-02-22) * Li Zefan (2007-09-10). */ + #include #include #include @@ -34,6 +35,7 @@ #include #include "c.h" +#include "xalloc.h" #include "nls.h" #include "widechar.h" @@ -194,9 +196,7 @@ readlink_to_namei(struct namei *nm, const char *path) if (nm->relstart) sz += nm->relstart + 1; } - nm->abslink = malloc(sz + 1); - if (!nm->abslink) - err(EXIT_FAILURE, _("out of memory?")); + nm->abslink = xmalloc(sz + 1); if (*sym != '/' && nm->relstart) { /* create the absolute path from the relative symlink */ diff --git a/misc-utils/rename.c b/misc-utils/rename.c index 87262b80..495e511c 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -17,7 +17,9 @@ for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done #include #include #include + #include "nls.h" +#include "xalloc.h" static char *progname; @@ -33,11 +35,7 @@ do_rename(char *from, char *to, char *s) { flen = strlen(from); tlen = strlen(to); slen = strlen(s); - newname = malloc(tlen+slen+1); - if (newname == NULL) { - fprintf(stderr, _("%s: out of memory\n"), progname); - exit(1); - } + newname = xmalloc(tlen+slen+1); p = s; q = newname; diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index 2601ffc6..14b2c3df 100644 --- a/misc-utils/setterm.c +++ b/misc-utils/setterm.c @@ -117,6 +117,7 @@ #endif #include "c.h" +#include "xalloc.h" #include "nls.h" #if __GNU_LIBRARY__ < 5 diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index c0b29f0e..dbfabc4a 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -34,6 +34,7 @@ #include #include "nls.h" +#include "xalloc.h" #include "strtosize.h" struct wipe_desc { @@ -135,15 +136,6 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap) return wp; } -static inline void * -xmalloc(size_t sz) -{ - void *x = malloc(sz); - if (!x) - err(EXIT_FAILURE, _("malloc failed")); - return x; -} - static inline char * xstrdup(const char *s) { -- 2.39.5