scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 3aa27c3da9cf49c6f8082f09a295b7cf241c9a65
parent 1d08a435776de0dd4f776cca9f2643570972809e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  6 Feb 2019 08:07:10 +0000

[strip] Simplify error handling

Diffstat:
Msrc/cmd/strip.c | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/cmd/strip.c b/src/cmd/strip.c @@ -32,15 +32,14 @@ strip(char *fname) 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 @@ err1: fclose(tmp); remove("strip.tmp"); err: + if (errno) + error(strerror(errno)); + return; }