sys-utils: make use xalloc wrappers

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This commit is contained in:
Davidlohr Bueso 2010-10-27 06:14:46 -03:00 committed by Karel Zak
parent 01802c2e6d
commit 2ab428f6a8
4 changed files with 21 additions and 52 deletions

View file

@ -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)) {

View file

@ -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));

View file

@ -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);

View file

@ -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