=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/midicat/midicat.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- src/usr.bin/midicat/midicat.c 2022/12/02 22:29:59 1.6 +++ src/usr.bin/midicat/midicat.c 2022/12/02 22:36:34 1.7 @@ -1,4 +1,4 @@ -/* $OpenBSD: midicat.c,v 1.6 2022/12/02 22:29:59 cheloha Exp $ */ +/* $OpenBSD: midicat.c,v 1.7 2022/12/02 22:36:34 cheloha Exp $ */ /* * Copyright (c) 2015 Alexandre Ratchov * @@ -49,10 +49,8 @@ port0 = optarg; else if (port1 == NULL) port1 = optarg; - else { - fputs("too many -q options\n", stderr); - return 1; - } + else + errx(1, "too many -q options"); break; case 'i': ifile = optarg; @@ -71,16 +69,12 @@ usage(); /* we don't support more than one data flow */ - if (ifile != NULL && ofile != NULL) { - fputs("-i and -o are exclusive\n", stderr); - return 1; - } + if (ifile != NULL && ofile != NULL) + errx(1, "-i and -o are exclusive"); /* second port makes sense only for port-to-port transfers */ - if (port1 != NULL && !(ifile == NULL && ofile == NULL)) { - fputs("too many -q options\n", stderr); - return 1; - } + if (port1 != NULL && !(ifile == NULL && ofile == NULL)) + errx(1, "too many -q options"); /* if there're neither files nor ports, then we've nothing to do */ if (port0 == NULL && ifile == NULL && ofile == NULL) @@ -97,10 +91,8 @@ ifd = STDIN_FILENO; } else { ifd = open(ifile, O_RDONLY); - if (ifd == -1) { - perror(ifile); - return 1; - } + if (ifd == -1) + err(1, "%s", ifile); } } else if (ofile) { if (strcmp(ofile, "-") == 0) { @@ -108,10 +100,8 @@ ofd = STDOUT_FILENO; } else { ofd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (ofd == -1) { - perror(ofile); - return 1; - } + if (ofd == -1) + err(1, "%s", ofile); } } @@ -125,20 +115,16 @@ else mode = MIO_IN; ih = mio_open(port0, mode, 0); - if (ih == NULL) { - fprintf(stderr, "%s: couldn't open port\n", port0); - return 1; - } + if (ih == NULL) + errx(1, "%s: couldn't open port", port0); /* open second port, output only */ if (port1 == NULL) oh = ih; else { oh = mio_open(port1, MIO_OUT, 0); - if (oh == NULL) { - fprintf(stderr, "%s: couldn't open port\n", port1); - exit(1); - } + if (oh == NULL) + errx(1, "%s: couldn't open port", port1); } if (pledge("stdio", NULL) == -1) @@ -151,26 +137,26 @@ if (len == 0) break; if (len == -1) { - perror("stdin"); + warn("%s", ifile); break; } } else { len = mio_read(ih, buf, sizeof(buf)); if (len == 0) { - fprintf(stderr, "%s: disconnected\n", port0); + warnx("%s: disconnected", port0); break; } } if (ofile != NULL) { n = write(ofd, buf, len); if (n != len) { - fprintf(stderr, "%s: short write\n", ofile); + warn("%s: short write", ofile); break; } } else { n = mio_write(oh, buf, len); if (n != len) { - fprintf(stderr, "%s: disconnected\n", port1); + warnx("%s: disconnected", port1); break; } }