misc-utils: use new xmalloc() wrapper

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This commit is contained in:
Davidlohr Bueso 2010-10-15 11:59:18 -03:00 committed by Karel Zak
parent d7df7ba264
commit 87f3feac71
4 changed files with 8 additions and 17 deletions

View File

@ -19,6 +19,7 @@
* Arkadiusz Mikiewicz (1999-02-22)
* Li Zefan (2007-09-10).
*/
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
@ -34,6 +35,7 @@
#include <grp.h>
#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 */

View File

@ -17,7 +17,9 @@ for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#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;

View File

@ -117,6 +117,7 @@
#endif
#include "c.h"
#include "xalloc.h"
#include "nls.h"
#if __GNU_LIBRARY__ < 5

View File

@ -34,6 +34,7 @@
#include <blkid.h>
#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)
{