Cleanup usage of err() and warn().

Add error handling for ioctl().

Reviewed by:	-current
Obtained from:	PAO
This commit is contained in:
Jun Kuriyama 1999-02-27 12:08:02 +00:00
parent c54f4a7556
commit 7164b74e64
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=44318
8 changed files with 50 additions and 45 deletions

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: dumpcis.c,v 1.9 1997/11/18 21:08:06 nate Exp $";
"$Id: dumpcis.c,v 1.10 1999/02/05 16:00:15 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -43,7 +43,7 @@ static const char rcsid[] =
int nocards;
void
static void
scan(slot)
int slot;
{
@ -57,7 +57,8 @@ scan(slot)
if (fd < 0)
return;
nocards++;
ioctl(fd, PIOCGSTATE, &st);
if (ioctl(fd, PIOCGSTATE, &st))
err(1, "ioctl (PIOCGSTATE)");
if (st.state == filled) {
cp = readcis(fd);
if (cp) {

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: enabler.c,v 1.10 1997/11/18 21:08:06 nate Exp $";
"$Id: enabler.c,v 1.11 1999/02/05 16:00:15 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -138,7 +138,7 @@ void
usage(msg)
char *msg;
{
warnx("enabler: %s", msg);
fprintf(stderr, "enabler: %s\n", msg);
fprintf(stderr,
"usage: pccardc enabler slot driver [-m addr size] [-a iobase] [-i irq]\n");
fprintf(stderr,

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: pccardmem.c,v 1.9 1997/11/18 21:08:06 nate Exp $";
"$Id: pccardmem.c,v 1.10 1999/02/05 16:00:15 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -64,8 +64,8 @@ pccardmem_main(argc, argv)
errx(1, "arg error");
}
if (ioctl(fd, PIOCRWMEM, &addr))
warn("ioctl");
err(1, "ioctl (PIOCRWMEM)");
else
printf("PCCARD Memory address set to 0x%x\n", addr);
exit(0);
return 0;
}

View file

@ -24,11 +24,13 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <pccard/cardinfo.h>
int
@ -42,36 +44,30 @@ rdattr_main(argc, argv)
int fd;
off_t offs;
if (argc != 4) {
fprintf(stderr, "usage: %s rdattr slot offs length\n", argv[0]);
exit(1);
}
if (argc != 4)
errx(1, "Usage: %s rdattr slot offs length", argv[0]);
sprintf(name, CARD_DEVICE, atoi(argv[1]));
fd = open(name, O_RDONLY);
if (fd < 0) {
perror(name);
exit(1);
}
if (fd < 0)
err(1, "%s", name);
reg = MDF_ATTR;
if (ioctl(fd, PIOCRWFLAG, &reg)) {
perror("ioctl (PIOCRWFLAG)");
exit(1);
}
if (ioctl(fd, PIOCRWFLAG, &reg))
err(1, "ioctl (PIOCRWFLAG)");
if (sscanf(argv[2], "%x", &reg) != 1 ||
sscanf(argv[3], "%x", &length) != 1) {
fprintf(stderr, "arg error\n");
exit(1);
}
sscanf(argv[3], "%x", &length) != 1)
errx(1, "arg error");
offs = reg;
if ((buf = malloc(length)) == 0) {
perror(name);
exit(1);
}
if ((buf = malloc(length)) == 0)
errx(1, "malloc failed");
lseek(fd, offs, SEEK_SET);
if (read(fd, buf, length) != length) {
perror(name);
exit(1);
}
if (read(fd, buf, length) != length)
err(1, "%s", name);
for (i = 0; i < length; i++) {
if (i % 16 == 0) {
printf("%04x: ", (int) offs + i);

View file

@ -26,9 +26,10 @@
#ifndef lint
static const char rcsid[] =
"$Id: rdmap.c,v 1.9 1997/11/18 21:08:07 nate Exp $";
"$Id: rdmap.c,v 1.10 1999/02/05 16:00:16 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@ -39,7 +40,7 @@ static const char rcsid[] =
#include <pccard/cardinfo.h>
#include <pccard/cis.h>
void
static void
dump_io(fd, nio)
int fd, nio;
{
@ -48,13 +49,14 @@ dump_io(fd, nio)
for (i = 0; i < nio; i++) {
io.window = i;
ioctl(fd, PIOCGIO, &io);
if (ioctl(fd, PIOCGIO, &io))
err(1, "ioctl (PIOCGIO)");
printf("I/O %d: flags 0x%03x port 0x%3x size %d bytes\n",
io.window, io.flags, io.start, io.size);
}
}
void
static void
dump_mem(fd, nmem)
int fd, nmem;
{
@ -63,7 +65,8 @@ dump_mem(fd, nmem)
for (i = 0; i < nmem; i++) {
mem.window = i;
ioctl(fd, PIOCGMEM, &mem);
if (ioctl(fd, PIOCGMEM, &mem))
err(1, "ioctl (PIOCGMEM)");
printf("Mem %d: flags 0x%03x host %p card %04lx size %d bytes\n",
mem.window, mem.flags, mem.start, mem.card, mem.size);
}
@ -81,7 +84,8 @@ scan(slot)
fd = open(name, O_RDONLY);
if (fd < 0)
return;
ioctl(fd, PIOCGSTATE, &st);
if (ioctl(fd, PIOCGSTATE, &st))
err(1, "ioctl (PIOCGSTATE)");
/*
if (st.state == filled)
*/

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: rdreg.c,v 1.9 1997/11/18 21:08:07 nate Exp $";
"$Id: rdreg.c,v 1.10 1999/02/05 16:00:16 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -38,6 +38,7 @@ static const char rcsid[] =
#include <sys/ioctl.h>
#include <pccard/cardinfo.h>
void
dumpslot(sl)
int sl;
@ -47,7 +48,7 @@ dumpslot(sl)
struct pcic_reg r;
sprintf(name, CARD_DEVICE, sl);
fd = open(name, O_RDWR);
fd = open(name, O_RDONLY);
if (fd < 0) {
warn("%s", name);
return;
@ -55,7 +56,7 @@ dumpslot(sl)
printf("Registers for slot %d\n", sl);
for (r.reg = 0; r.reg < 0x40; r.reg++) {
if (ioctl(fd, PIOCGREG, &r)) {
warn("ioctl");
err(1, "ioctl (PIOCGREG)");
break;
}
if ((r.reg % 16) == 0)

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: wrattr.c,v 1.10 1997/11/18 21:08:08 nate Exp $";
"$Id: wrattr.c,v 1.11 1999/02/05 16:00:16 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -62,16 +62,19 @@ wrattr_main(argc, argv)
fd = open(name, O_RDWR);
if (fd < 0)
err(1, "%s", name);
reg = MDF_ATTR;
if (ioctl(fd, PIOCRWFLAG, &reg))
err(1, "ioctl (PIOCRWFLAG)");
if (sscanf(argv[2], "%x", &reg) != 1 ||
sscanf(argv[3], "%x", &value) != 1)
errx(1, "arg error");
offs = reg;
c = value;
lseek(fd, offs, SEEK_SET);
if (write(fd, &c, 1) != 1)
warn("%s", name);
err(1, "%s", name);
return 0;
}

View file

@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: wrreg.c,v 1.9 1997/11/18 21:08:08 nate Exp $";
"$Id: wrreg.c,v 1.10 1999/02/05 16:00:16 kuriyama Exp $";
#endif /* not lint */
#include <err.h>
@ -68,6 +68,6 @@ wrreg_main(argc, argv)
r.reg = reg;
r.value = value;
if (ioctl(fd, PIOCSREG, &r))
warn("ioctl");
err(1, "ioctl (PIOCSREG)");
return 0;
}