ref: 3aa27c3da9cf49c6f8082f09a295b7cf241c9a65
parent: 1d08a435776de0dd4f776cca9f2643570972809e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 6 03:07:10 EST 2019
[strip] Simplify error handling
--- a/src/cmd/strip.c
+++ b/src/cmd/strip.c
@@ -32,15 +32,14 @@
FILE *fp, *tmp;
Obj *obj;
+ errno = 0;
filename = fname;
- if ((tmp = fopen("strip.tmp", "wb")) == NULL) {
- error(strerror(errno));
+
+ fp = fopen(fname, "rb");
+ tmp = tmpfile();
+ if (!fp || !tmp)
goto err;
- }
- if ((fp = fopen(fname, "rb")) == NULL) {
- error(strerror(errno));
- goto err1;
- }
+
if ((type = objtype(fp, NULL)) < 0) {
error("file format not recognized");
goto err2;
@@ -79,6 +78,9 @@
fclose(tmp);
remove("strip.tmp");
err:
+ if (errno)
+ error(strerror(errno));
+
return;
}