[PATCH 2/2] misc-utils: integrate xalloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This would be the first commands to use the xalloc.h functions. Note that look(1) needs to be treated a bit differently because of err() conflicts.

misc-utils: use new xmalloc() wrapper

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 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 9873cda..0342a08 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 <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 */
diff --git a/misc-utils/rename.c b/misc-utils/rename.c
index 87262b8..495e511 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 <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;
diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c
index 2601ffc..14b2c3d 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 c0b29f0..dbfabc4 100644
--- a/misc-utils/wipefs.c
+++ b/misc-utils/wipefs.c
@@ -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)
 {
-- 
1.7.0.4




--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux