aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2024-06-17 07:23:18 +0000
committerOmar Polo <op@omarpolo.com>2024-06-17 07:23:18 +0000
commit0a7192ddc76de4ee32eb017306ab5971d902d638 (patch)
tree10df081c3780a10e36db6735050e5cd65e719222
parentbc5e9ae52576c9a0673dd2b7b7ddaadd05dd976e (diff)
titan: improve error checking
Not only the reading, but the writing can fail too so bail out early in that case. Also, even if it's just a pro forma, check the error flag on stdin too.
-rw-r--r--titan.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/titan.c b/titan.c
index d9736c1..9f060f2 100644
--- a/titan.c
+++ b/titan.c
@@ -181,9 +181,10 @@ open_input_file(int argc, char **argv)
r = fread(buf, 1, sizeof(buf), stdin);
if (r == 0)
break;
- fwrite(buf, 1, r, fp);
+ if (fwrite(buf, 1, r, fp) != r)
+ break;
}
- if (ferror(fp))
+ if (ferror(fp) || ferror(stdin))
err(1, "I/O error");
if (fseeko(fp, 0, SEEK_SET) == -1)