aboutsummaryrefslogtreecommitdiff
path: root/libbb/fclose_nonstdin.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/fclose_nonstdin.c')
-rw-r--r--libbb/fclose_nonstdin.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libbb/fclose_nonstdin.c b/libbb/fclose_nonstdin.c
index 88e8474f2..768ee946d 100644
--- a/libbb/fclose_nonstdin.c
+++ b/libbb/fclose_nonstdin.c
@@ -16,8 +16,10 @@
int fclose_if_not_stdin(FILE *f)
{
- if (f != stdin) {
- return fclose(f);
- }
- return 0;
+ /* Some more paranoid applets want ferror() check too */
+ int r = ferror(f); /* NB: does NOT set errno! */
+ if (r) errno = EIO; /* so we'll help it */
+ if (f != stdin)
+ return (r | fclose(f)); /* fclose does set errno on error */
+ return r;
}