From 2ab428f6a8966d90ac97ce0ce0c7d73b82fade8f Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Wed, 27 Oct 2010 06:14:46 -0300 Subject: [PATCH] sys-utils: make use xalloc wrappers Signed-off-by: Davidlohr Bueso --- sys-utils/cytune.c | 9 +++------ sys-utils/readprofile.c | 23 +++-------------------- sys-utils/rtcwake.c | 7 ++----- sys-utils/tunelp.c | 34 +++++++++++++--------------------- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/sys-utils/cytune.c b/sys-utils/cytune.c index 10a874d4..47b37290 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 52f5d8c9..91ff3295 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -49,6 +49,8 @@ #include #include #include + +#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 26511306..f7ecb162 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -36,6 +36,7 @@ #include #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 00ad5b76..0f22fd8c 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -60,7 +60,9 @@ #include #include #include + #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 -- 2.39.5