scc

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

commit 8948e258c4224a0a7e2ee5cced431b76f912e4d8
parent 7e122c00108551cc8fd259faacdcfcc8712c1e65
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; }