]> granicus.if.org Git - jq/commitdiff
partial handling of input errors
authorAssaf Gordon <assafgordon@gmail.com>
Tue, 10 Mar 2015 21:02:02 +0000 (17:02 -0400)
committerNicolas Williams <nico@cryptonector.com>
Tue, 24 Mar 2015 19:56:46 +0000 (14:56 -0500)
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
util.c

diff --git a/util.c b/util.c
index 6e0ab27e64d57fca63e9015361ded18f4b8082a4..31a176831687a00e91b99e95f326151c5a6c71ee 100644 (file)
--- a/util.c
+++ b/util.c
@@ -221,7 +221,13 @@ static jv next_file(jq_util_input_state state) {
 }
 
 int jq_util_input_read_more(jq_util_input_state state) {
-  if (!state->current_input || feof(state->current_input)) {
+  if (!state->current_input || feof(state->current_input) || ferror(state->current_input)) {
+    if (state->current_input && ferror(state->current_input)) {
+      // System-level input error on the stream. It will be closed (below).
+      // TODO: report it. Can't use 'state->err_cb()' as it is hard-coded for
+      //       'open' related problems.
+      fprintf(stderr,"Input error: %s\n", strerror(errno));
+    }
     if (state->current_input) {
       if (state->current_input == stdin) {
         clearerr(stdin); // perhaps we can read again; anyways, we don't fclose(stdin)