On Sat, Jul 19, 2014 at 06:40:54PM -0700, Philip Guenther wrote:
> Nice job! Committed (except for the microcode/bwi file where your diff
> revealed another existing bug that we can fix at the same time...)
Thanks! Here's the patch with the existing bug fixed. I checked other
places for err/warn in this file but I think I'm already touching them
all.
Index: sys/dev/microcode/bwi/build/build.c
===================================================================
RCS file: /cvs/src/sys/dev/microcode/bwi/build/build.c,v
retrieving revision 1.3
diff -u -p -d -r1.3 build.c
--- sys/dev/microcode/bwi/build/build.c 12 Jul 2014 19:01:49 -0000 1.3
+++ sys/dev/microcode/bwi/build/build.c 20 Jul 2014 01:56:52 -0000
@@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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);