On Wed, Nov 30, 2022 at 09:20:26AM -0600, Scott Cheloha wrote: > Couple related things: > > - Use err(3) everywhere. > > For many of these errors we are not currently printing the errno > string. Is there any reason not to do so? The errno string is > useful. > > - Set ifile/ofile to "stdin"/"stdout" if the user passes in > "-" to make the err(3) message a little more obvious. > > - Add a usage() function. > > ok? >
ok except for changes below > @@ -126,20 +114,16 @@ main(int argc, char **argv) > 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) > + err(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) > + err(1, "%s: couldn't open port", port1); The mio_xxx functions don't set errno, so you should use errx() and warnx() here > @@ -152,26 +136,26 @@ main(int argc, char **argv) > 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); > + warn("%s: disconnected", port0); > break; and here > } else { > n = mio_write(oh, buf, len); > if (n != len) { > - fprintf(stderr, "%s: disconnected\n", port1); > + warn("%s: disconnected", port1); > break; and here