diff options
author | James Youngman <jay@gnu.org> | 2013-12-08 20:58:15 +0000 |
---|---|---|
committer | James Youngman <jay@gnu.org> | 2013-12-08 21:02:51 +0000 |
commit | 8acf1d2ecfda94856a6a65a2307fbec35529f772 (patch) | |
tree | 053efb1b824b0906d4fcc7b442217f2c40d927d0 /xargs | |
parent | d0bba0775bbfa989038190fb2a07a41f178540ec (diff) | |
download | findutils-8acf1d2ecfda94856a6a65a2307fbec35529f772.tar.gz |
Bug #35753: check the success/failure of material I/O operations.
* lib/listfile.c (list_file): Check the result of fprintf to
determine if there was an I/O error on output. Return false (bool
instead of void) if so.
(print_name_without_quoting): Likewise.
(print_name_with_quoting): Likewise.
(print_name): Propagate the result of print_name_without_quoting
or print_name_with_quoting (and make all three functions return bool).
* find/pred.c (is_ok): Check the result of fprintf to
determine if there was an I/O error on output. Exit fatally if
there was a problem (since we cannot expect the user to say "yes"
or "no" to a prompt they will not have seen).
* xargs/xargs.c (print_args): Check the result of fprintf and
fflush to determine if there was an I/O error on output. Exit
fatally for the same reason as above if there is a problem.
* NEWS: Mention this bugfix (now that it is fully fixed).
Diffstat (limited to 'xargs')
-rw-r--r-- | xargs/xargs.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/xargs/xargs.c b/xargs/xargs.c index 17c68bbd..89e78a3a 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -1051,7 +1051,11 @@ print_args (bool ask) size_t i; for (i = 0; i < bc_state.cmd_argc - 1; i++) - fprintf (stderr, "%s ", bc_state.cmd_argv[i]); + { + if (fprintf (stderr, "%s ", bc_state.cmd_argv[i]) < 0) + error (EXIT_FAILURE, errno, _("Failed to write to stderr")); + } + if (ask) { static FILE *tty_stream; @@ -1065,10 +1069,14 @@ print_args (bool ask) _("failed to open /dev/tty for reading")); } fputs ("?...", stderr); - fflush (stderr); + if (fflush (stderr) != 0) + error (EXIT_FAILURE, errno, _("Failed to write to stderr")); + c = savec = getc (tty_stream); while (c != EOF && c != '\n') c = getc (tty_stream); + if (EOF == c) + error (EXIT_FAILURE, errno, _("Failed to read from stdin")); if (savec == 'y' || savec == 'Y') return true; } |