diff options
author | kris <kris@FreeBSD.org> | 2001-01-28 09:20:47 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2001-01-28 09:20:47 +0000 |
commit | 72eee5791327b4dcbfa3abdf32d7ef50392318fe (patch) | |
tree | 842f0a4320ea841993a99005bca19fd6856956e7 | |
parent | f8be4d8cb4a410f6081a42abe7bea6071e48053e (diff) | |
download | FreeBSD-src-72eee5791327b4dcbfa3abdf32d7ef50392318fe.zip FreeBSD-src-72eee5791327b4dcbfa3abdf32d7ef50392318fe.tar.gz |
Finish cleaning up the error reporting (standardize on err*()/warn*())
and fix some overflows.
Submitted by: Mike Heffner <mheffner@vt.edu>
-rw-r--r-- | usr.sbin/pcvt/ispcvt/ispcvt.c | 21 | ||||
-rw-r--r-- | usr.sbin/pcvt/loadfont/loadfont.c | 57 | ||||
-rw-r--r-- | usr.sbin/pcvt/scon/scon.c | 89 | ||||
-rw-r--r-- | usr.sbin/pcvt/userkeys/vt220keys.c | 17 |
4 files changed, 44 insertions, 140 deletions
diff --git a/usr.sbin/pcvt/ispcvt/ispcvt.c b/usr.sbin/pcvt/ispcvt/ispcvt.c index a3181a8..d760337 100644 --- a/usr.sbin/pcvt/ispcvt/ispcvt.c +++ b/usr.sbin/pcvt/ispcvt/ispcvt.c @@ -37,6 +37,7 @@ *---------------------------------------------------------------------------*/ #include <stdio.h> +#include <err.h> #include <fcntl.h> #include <machine/pcvt_ioctl.h> @@ -94,12 +95,7 @@ char *argv[]; if((fd = open(device, O_RDWR)) == -1) { if(verbose) - { - char buffer[80]; - strcpy(buffer,"ERROR opening "); - strcat(buffer,device); - perror(buffer); - } + warn("ERROR opening %s", device); exit(1); } } @@ -111,7 +107,7 @@ char *argv[]; if(ioctl(fd, VGAPCVTID, &pcvtid) == -1) { if(verbose) - perror("ispcvt - ioctl VGAPCVTID failed, error"); + warn("ioctl VGAPCVTID failed, error"); exit(1); } @@ -122,27 +118,28 @@ char *argv[]; if(pcvtid.rminor != PCVTIDMINOR) { if(verbose) - fprintf(stderr,"ispcvt - minor revision: expected %d, got %d\n", PCVTIDMINOR, pcvtid.rminor); + warnx("minor revision: expected %d, got %d", PCVTIDMINOR, pcvtid.rminor); exit(4); /* minor revision mismatch */ } } else { if(verbose) - fprintf(stderr,"ispcvt - major revision: expected %d, got %d\n", PCVTIDMAJOR, pcvtid.rmajor); + warnx("major revision: expected %d, got %d", PCVTIDMAJOR, pcvtid.rmajor); exit(3); /* major revision mismatch */ } } else { if(verbose) - fprintf(stderr,"ispcvt - name check: expected %s, got %s\n", PCVTIDNAME, pcvtid.name); + warnx("name check: expected %s, got %s", PCVTIDNAME, pcvtid.name); exit(2); /* name mismatch */ } if(verbose) { - fprintf(stderr,"\nispcvt: kernel and utils match, driver name [%s], release [%1.1d.%02.2d]\n\n",pcvtid.name,pcvtid.rmajor,pcvtid.rminor); + warnx("\nkernel and utils match, driver name [%s], release [%1.1d.%02.2d]\n", + pcvtid.name, pcvtid.rmajor, pcvtid.rminor); } if(config == 0 && n_screens == 0) @@ -151,7 +148,7 @@ char *argv[]; if(ioctl(fd, VGAPCVTINFO, &pcvtinfo) == -1) { if(verbose) - perror("ispcvt - ioctl VGAPCVTINFO failed, error"); + warn("ioctl VGAPCVTINFO failed, error"); exit(1); } diff --git a/usr.sbin/pcvt/loadfont/loadfont.c b/usr.sbin/pcvt/loadfont/loadfont.c index a9a5bc5..c1df6e8 100644 --- a/usr.sbin/pcvt/loadfont/loadfont.c +++ b/usr.sbin/pcvt/loadfont/loadfont.c @@ -44,6 +44,7 @@ *---------------------------------------------------------------------------*/ #include <stdio.h> +#include <err.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> @@ -129,13 +130,7 @@ char *argv[]; if(dflag) { if((fd = open(device, O_RDWR)) == -1) - { - char buffer[80]; - strcpy(buffer,"ERROR opening "); - strcat(buffer,device); - perror(buffer); - exit(1); - } + err(1, "ERROR opening %s", device); } else { @@ -147,10 +142,7 @@ char *argv[]; int i; if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGAGETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGAGETSCREEN failed"); switch(screeninfo.adaptor_type) { @@ -183,20 +175,10 @@ char *argv[]; sbp = &sbuf; if((in = fopen(filename, "r")) == NULL) - { - char buffer[80]; - sprintf(buffer, "cannot open file %s for reading", filename); - perror(buffer); - exit(1); - } + err(1, "cannot open file %s for reading", filename); if((fstat(fileno(in), sbp)) != 0) - { - char buffer[80]; - sprintf(buffer, "cannot fstat file %s", filename); - perror(buffer); - exit(1); - } + err(1, "cannot fstat file %s", filename); switch(sbp->st_size) { @@ -225,21 +207,15 @@ char *argv[]; break; default: - fprintf(stderr,"error, file %s is no valid font file, size=%d\n",argv[1],sbp->st_size); - exit(1); + errx(1, "error, file %s is no valid font file, size=%d", argv[1], sbp->st_size); } if((fonttab = (unsigned char *)malloc((size_t)sbp->st_size)) == NULL) - { - fprintf(stderr,"error, malloc failed\n"); - exit(1); - } + errx(1, "error, malloc failed"); if((ret = fread(fonttab, sizeof(*fonttab), sbp->st_size, in)) != sbp->st_size) - { - fprintf(stderr,"error reading file %s, size = %d, read = is no valid font file, size=%d\n",argv[1],sbp->st_size, ret); - exit(1); - } + errx(1, "error reading file %s, size = %d, read = is no valid font file, size=%d", + argv[1], sbp->st_size, ret); loadfont(chr_set, chr_height, fonttab); setfont(chr_set, 1, chr_height - 1, scr_scan, scr_rows); @@ -259,10 +235,7 @@ int charset, fontloaded, charscan, scrscan, scrrow; vfattr.screen_size = scrrow; if(ioctl(fd, VGASETFONTATTR, &vfattr) == -1) - { - perror("loadfont - ioctl VGASETFONTATTR failed, error"); - exit(1); - } + err(1, "ioctl VGASETFONTATTR failed, error"); } loadfont(fontset,charscanlines,font_table) @@ -285,10 +258,7 @@ unsigned char *font_table; } font_table += charscanlines; if(ioctl(fd, VGALOADCHAR, &vlc) == -1) - { - perror("loadfont - ioctl VGALOADCHAR failed, error"); - exit(1); - } + err(1, "ioctl VGALOADCHAR failed, error"); } } @@ -301,10 +271,7 @@ int charset; vfattr.character_set = charset; if(ioctl(fd, VGAGETFONTATTR, &vfattr) == -1) - { - perror("loadfont - ioctl VGAGETFONTATTR failed, error"); - exit(1); - } + err(1, "ioctl VGAGETFONTATTR failed, error"); printf(" %d ",charset); if(vfattr.font_loaded) { diff --git a/usr.sbin/pcvt/scon/scon.c b/usr.sbin/pcvt/scon/scon.c index c5acbd9..7671292 100644 --- a/usr.sbin/pcvt/scon/scon.c +++ b/usr.sbin/pcvt/scon/scon.c @@ -38,6 +38,7 @@ *---------------------------------------------------------------------------*/ #include <stdio.h> +#include <err.h> #include <fcntl.h> #include <machine/pcvt_ioctl.h> @@ -239,43 +240,23 @@ char *argv[]; if(!strcmp(optarg, "list")) { if(Pflag) - { - fprintf(stderr, - "-p list is mutual exclusive " - "with other -p options\n"); - return 2; - } + errx(2, "-p list is mutual exclusive with other -p options"); Pflag = 3; } else if(!strcmp(optarg, "default")) { if(Pflag) - { - fprintf(stderr, - "multiple -p default not " - "allowed\n"); - return 2; - } + errx(2, "multiple -p default not allowed"); Pflag = 2; } else { unsigned idx, r, g, b; if(Pflag > 1) - { - fprintf(stderr, - "-p default and -p i,r,g,b " - "ambiguous\n"); - return 2; - } + errx(2, "-p default and -p i,r,g,b ambiguous"); Pflag = 1; parsepopt(optarg, &idx, &r, &g, &b); if(idx >= NVGAPEL) - { - fprintf(stderr, - "index %u in -p option " - "out of range\n", idx); - return 2; - } + errx(2, "index %u in -p option out of range", idx); palette[idx].r = r; palette[idx].g = g; palette[idx].b = b; @@ -322,13 +303,7 @@ char *argv[]; else { if((fd = open(device, O_RDWR)) == -1) - { - char buffer[80]; - strcpy(buffer,"ERROR opening "); - strcat(buffer,device); - perror(buffer); - exit(1); - } + err(1, "ERROR opening %s", device); if(vflag) printf("using device %s\n",device); } @@ -368,7 +343,7 @@ char *argv[]; if(ioctl(fd, VGASCREENSAVER, &timeout) < 0) { - perror("ioctl(VGASCREENSAVER)"); + warn("ioctl(VGASCREENSAVER)"); fprintf(stderr, "Check the driver, the screensaver is probably not compiled in!\n"); exit(2); } @@ -380,10 +355,7 @@ char *argv[]; if(vflag) printf("Setting number of columns to %d\n", colms); if(ioctl(fd, VGASETCOLMS, &colms) < 0) - { - perror("ioctl(VGASETCOLMS)"); - exit(2); - } + err(2, "ioctl(VGASETCOLMS)"); goto success; } @@ -416,10 +388,7 @@ char *argv[]; p.g = palette[idx].g; p.b = palette[idx].b; if(ioctl(fd, VGAWRITEPEL, (caddr_t)&p) < 0) - { - perror("ioctl(fd, VGAWRITEPEL)"); - return 2; - } + err(2, "ioctl(fd, VGAWRITEPEL)"); } goto success; } @@ -436,10 +405,7 @@ char *argv[]; printf("processing option -c, setting current screen to %d\n",current); if(ioctl(1, VGASETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGASETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGASETSCREEN failed"); exit(0); } @@ -498,10 +464,7 @@ char *argv[]; screeninfo.force_24lines = fflag; if(ioctl(fd, VGASETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGASETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGASETSCREEN failed"); success: if(vflag) printf("successful execution of ioctl VGASETSCREEN!\n"); @@ -538,10 +501,7 @@ printadaptor(fd) int fd; { if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGAGETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGAGETSCREEN failed"); switch(screeninfo.adaptor_type) { default: @@ -571,10 +531,7 @@ printmonitor(fd) int fd; { if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGAGETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGAGETSCREEN failed"); switch(screeninfo.monitor_type) { default: @@ -651,10 +608,7 @@ printinfo(fd) int fd; { if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1) - { - perror("ioctl VGAGETSCREEN failed"); - exit(1); - } + err(1, "ioctl VGAGETSCREEN failed"); printf( "\nVideo Adaptor Type = "); @@ -776,10 +730,7 @@ static void printpalette(int fd) struct vgapel p; p.idx = idx; if(ioctl(fd, VGAREADPEL, &p) < 0) - { - perror("ioctl(VGAREADPEL)"); - exit(2); - } + err(2, "ioctl(VGAREADPEL)"); palette[idx].r = p.r; palette[idx].g = p.g; palette[idx].b = p.b; @@ -817,10 +768,8 @@ static void parsepopt(char *arg, unsigned *idx, register unsigned i; if(sscanf(arg, "%20[a-zA-Z0-9]%*[,:]%u,%u,%u", firstarg, r, g, b) < 4 - || strlen(firstarg) == 0) { - fprintf(stderr, "too few args in -p i,r,g,b\n"); - exit(2); - } + || strlen(firstarg) == 0) + errx(2, "too few args in -p i,r,g,b"); if(firstarg[0] >= '0' && firstarg[0] <= '9') { *idx = strtoul(firstarg, NULL, 10); @@ -832,7 +781,5 @@ static void parsepopt(char *arg, unsigned *idx, *idx = colnames[i].idx; return; } - fprintf(stderr, "arg ``%s'' in -p option not recognized\n", - firstarg); - exit(2); + errx(2, "arg ``%s'' in -p option not recognized", firstarg); } diff --git a/usr.sbin/pcvt/userkeys/vt220keys.c b/usr.sbin/pcvt/userkeys/vt220keys.c index 55664c5..ac9c3fc 100644 --- a/usr.sbin/pcvt/userkeys/vt220keys.c +++ b/usr.sbin/pcvt/userkeys/vt220keys.c @@ -24,9 +24,12 @@ -hm minor modifications for pcvt 2.0 release +$FreeBSD$ */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <ctype.h> /* @@ -81,9 +84,8 @@ main(argc,argv) int initf = 0; /* read initialization file */ int lockf = 0; /* lock keys after loading strings */ int clearf = 0; /* clear all keys before loading strings */ - char *strcpy(); - (void) strcpy(prog, *argv); /* store program name */ + strlcpy(prog, *argv, sizeof(prog)); /* store program name */ if(argc == 1) usage(); /* program requires options */ @@ -232,18 +234,9 @@ getinit() struct stat statbuf; /* stat of the init file */ FILE *fp; /* file pointer to init file */ - /* system calls and subroutines */ - FILE *fopen(); - char *strcpy(); - char *strcat(); - char *fgets(); - char *getenv(); - /* construct full path name for init file */ home = getenv("HOME"); - (void) strcpy(path, home); - (void) strcat(path,"/"); - (void) strcat(path,INITFILE); + snprintf(path, sizeof(path), "%s/%s", home, INITFILE); /* check status if init file */ if (stat(path, &statbuf) != -1) |