summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-10-27 11:14:46 +0200
committerKarel Zak2010-11-01 16:43:23 +0100
commit2ab428f6a8966d90ac97ce0ce0c7d73b82fade8f (patch)
tree81da9f5e03454912f8904d189c1ae4662a8d882c /sys-utils
parentlibblkid: add signature to FAT32 fsinfo block (diff)
downloadkernel-qcow2-util-linux-2ab428f6a8966d90ac97ce0ce0c7d73b82fade8f.tar.gz
kernel-qcow2-util-linux-2ab428f6a8966d90ac97ce0ce0c7d73b82fade8f.tar.xz
kernel-qcow2-util-linux-2ab428f6a8966d90ac97ce0ce0c7d73b82fade8f.zip
sys-utils: make use xalloc wrappers
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/cytune.c9
-rw-r--r--sys-utils/readprofile.c23
-rw-r--r--sys-utils/rtcwake.c7
-rw-r--r--sys-utils/tunelp.c34
4 files changed, 21 insertions, 52 deletions
diff --git a/sys-utils/cytune.c b/sys-utils/cytune.c
index 10a874d44..47b372907 100644
--- a/sys-utils/cytune.c
+++ b/sys-utils/cytune.c
@@ -63,6 +63,7 @@
#endif
#endif
+#include "xalloc.h"
#include "nls.h"
/* Until it gets put in the kernel,
toggle by hand. */
@@ -315,12 +316,8 @@ int main(int argc, char *argv[]) {
/* query stuff after this line */
- cmon = (struct cyclades_control *) malloc(sizeof (struct cyclades_control)
- * numfiles);
- if(!cmon) {
- perror(_("malloc failed"));
- exit(1);
- }
+ cmon = xmalloc(sizeof(struct cyclades_control) * numfiles);
+
if(signal(SIGINT, summary)||
signal(SIGQUIT, summary)||
signal(SIGTERM, summary)) {
diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c
index 52f5d8c94..91ff32951 100644
--- a/sys-utils/readprofile.c
+++ b/sys-utils/readprofile.c
@@ -49,6 +49,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
+
+#include "xalloc.h"
#include "nls.h"
#define S_LEN 128
@@ -60,22 +62,6 @@ static char defaultmap[]="/boot/System.map";
static char defaultpro[]="/proc/profile";
static char optstring[]="M:m:np:itvarVbs";
-static void *
-xmalloc (size_t size) {
- void *t;
-
- if (size == 0)
- return NULL;
-
- t = malloc (size);
- if (t == NULL) {
- fprintf(stderr, _("out of memory"));
- exit(1);
- }
-
- return t;
-}
-
static FILE *
myopen(char *name, char *mode, int *flag) {
int len = strlen(name);
@@ -242,10 +228,7 @@ main(int argc, char **argv) {
exit(1);
}
- if (!(buf=malloc(len))) {
- fprintf(stderr,"%s: malloc(): %s\n", prgname, strerror(errno));
- exit(1);
- }
+ buf = xmalloc(len);
if (read(proFd,buf,len) != len) {
fprintf(stderr,"%s: %s: %s\n",prgname,proFile,strerror(errno));
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index 265113069..f7ecb1624 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -36,6 +36,7 @@
#include <linux/rtc.h>
#include "nls.h"
+#include "xalloc.h"
#include "pathnames.h"
#include "usleep.h"
@@ -423,11 +424,7 @@ int main(int argc, char **argv)
if (strncmp(devname, "/dev/", strlen("/dev/")) != 0) {
char *new_devname;
- new_devname = malloc(strlen(devname) + strlen("/dev/") + 1);
- if (!new_devname) {
- perror(_("malloc() failed"));
- exit(EXIT_FAILURE);
- }
+ new_devname = xmalloc(strlen(devname) + strlen("/dev/") + 1);
strcpy(new_devname, "/dev/");
strcat(new_devname, devname);
diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c
index 00ad5b765..0f22fd8c6 100644
--- a/sys-utils/tunelp.c
+++ b/sys-utils/tunelp.c
@@ -60,7 +60,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+
#include "lp.h"
+#include "xalloc.h"
#include "nls.h"
struct command {
@@ -84,16 +86,6 @@ print_version(char *progname) {
printf(_("%s (%s)\n"), progname, PACKAGE_STRING);
}
-static void *
-mylloc(long size) {
- void *ptr;
- if(!(ptr = (void*)malloc(size))) {
- perror(_("malloc error"));
- exit(2);
- }
- return ptr;
-}
-
static char *progname;
static long
@@ -131,7 +123,7 @@ main (int argc, char ** argv) {
if (argc < 2) print_usage(progname);
- cmdst = cmds = mylloc(sizeof(struct command));
+ cmdst = cmds = xmalloc(sizeof(struct command));
cmds->next = 0;
show_irq = 1;
@@ -143,31 +135,31 @@ main (int argc, char ** argv) {
case 'i':
cmds->op = LPSETIRQ;
cmds->val = get_val(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 't':
cmds->op = LPTIME;
cmds->val = get_val(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 'c':
cmds->op = LPCHAR;
cmds->val = get_val(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 'w':
cmds->op = LPWAIT;
cmds->val = get_val(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 'a':
cmds->op = LPABORT;
cmds->val = get_onoff(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 'q':
@@ -180,20 +172,20 @@ main (int argc, char ** argv) {
case 'o':
cmds->op = LPABORTOPEN;
cmds->val = get_onoff(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 'C':
cmds->op = LPCAREFUL;
cmds->val = get_onoff(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
case 's':
show_irq = 0;
cmds->op = LPGETSTATUS;
cmds->val = 0;
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
#endif
@@ -201,7 +193,7 @@ main (int argc, char ** argv) {
case 'r':
cmds->op = LPRESET;
cmds->val = 0;
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
#endif
@@ -210,7 +202,7 @@ main (int argc, char ** argv) {
/* Note: this will do the wrong thing on 2.0.36 when compiled under 2.2.x */
cmds->op = LPTRUSTIRQ;
cmds->val = get_onoff(optarg);
- cmds->next = mylloc(sizeof(struct command));
+ cmds->next = xmalloc(sizeof(struct command));
cmds = cmds->next; cmds->next = 0;
break;
#endif