From: guenther Date: Sun, 20 Jul 2014 02:03:21 +0000 (+0000) Subject: Make sure the correct errno is reported by warn* or err* and not X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0976a62eed9efa8a56fe08c0e6111f8914501630;p=openbsd Make sure the correct errno is reported by warn* or err* and not the errno of an intervening cleanup operation like close/unlink/etc. Also, the format string for warn* and err* shouldn't end with a newline. Diff from Doug Hogan (doug (at) acyclic.org) --- diff --git a/sys/dev/microcode/bwi/build/build.c b/sys/dev/microcode/bwi/build/build.c index 2869b3ad0cc..41aa6fa5ada 100644 --- a/sys/dev/microcode/bwi/build/build.c +++ b/sys/dev/microcode/bwi/build/build.c @@ -1,4 +1,4 @@ -/* $OpenBSD: build.c,v 1.3 2014/07/12 19:01:49 tedu Exp $ */ +/* $OpenBSD: build.c,v 1.4 2014/07/20 02:03:21 guenther Exp $ */ /* * Copyright (c) 2006 Marcus Glocker @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -104,12 +105,14 @@ main(int argc, char *argv[]) /* write header */ if (write(fdout, &nfiles, sizeof(nfiles)) < 1) { + int saved_errno = errno; close(fdout); - err(1, "write header 1 to output file failed\n"); + errc(1, saved_errno, "write header 1 to output file failed"); } if (write(fdout, h, headersize - sizeof(nfiles)) < 1) { + int saved_errno = errno; close(fdout); - err(1, "write header 2 to output file failed\n"); + errc(1, saved_errno, "write header 2 to output file failed"); } /* network to host byte order */ @@ -122,25 +125,29 @@ main(int argc, char *argv[]) /* write each file */ for (i = 0; i < nfiles; i++) { if ((fdin = open(h[i].filename, O_RDONLY)) == -1) { + int saved_errno = errno; close(fdout); - err(1, "open input file failed\n"); + errc(1, saved_errno, "open input file failed"); } if ((p = malloc(h[i].filesize)) == NULL) { + int saved_errno = errno; close(fdout); close(fdin); - err(1, "malloc"); + errc(1, saved_errno, "malloc"); } if (read(fdin, p, h[i].filesize) < 1) { + int saved_errno = errno; free(p); close(fdout); close(fdin); - err(1, "read input file failed\n"); + errc(1, saved_errno, "read input file failed"); } if (write(fdout, p, h[i].filesize) < 1) { + int saved_errno = errno; free(p); close(fdout); close(fdin); - err(1, "write to output file failed\n"); + errc(1, saved_errno, "write to output file failed"); } free(p); close(fdin);