diff options
author | Richard Maw <richard.maw@gmail.com> | 2014-11-12 12:54:56 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2014-11-12 14:47:08 +0000 |
commit | 501a039172d066d0b0ea9071c5d82467e89de9a6 (patch) | |
tree | 29d01891f0736d57d98e0cb614b910ad66b17ea7 | |
parent | 2a019b5fee65a738bdd38717b0b84eea638a776d (diff) | |
download | morph-501a039172d066d0b0ea9071c5d82467e89de9a6.tar.gz |
test-shell: Report write failures
-rw-r--r-- | scripts/test-shell.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/test-shell.c b/scripts/test-shell.c index 2f8ecbd8..f4ac6bfa 100644 --- a/scripts/test-shell.c +++ b/scripts/test-shell.c @@ -10,6 +10,7 @@ #include <stdint.h> #include <ftw.h> #include <errno.h> +#include <err.h> char *readlinka(char const *path){ size_t buflen = BUFSIZ; @@ -113,8 +114,8 @@ int copy_file_objects(FILE *source, FILE *target) { do { read = fread(buffer, 1, sizeof(buffer), source); fwrite(buffer, 1, read, target); - } while (!feof(source)); - return ferror(source) ? -1 : 0; + } while (!feof(source) && !feof(target)); + return (ferror(source) || ferror(target)) ? -1 : 0; } int run_commands(FILE *cmdstream){ @@ -145,8 +146,14 @@ int run_commands(FILE *cmdstream){ } else if (strstr(line, "create file ") == line) { char const *filename = line + sizeof("create file ") -1; FILE *outfile = fopen(filename, "w"); + if (outfile == NULL){ + ret = 1; + err(errno, "Opening %s for write failed", filename); + break; + } if (copy_file_objects(cmdstream, outfile) < 0) { ret = 1; + err(errno, "Writing to %s failed", filename); fclose(outfile); break; } |