From 5e0db6dd658f4f791d67de4a7b00d8fc159af15a Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Tue, 10 Mar 2015 17:02:02 -0400 Subject: [PATCH] partial handling of input errors Signed-off-by: Nicolas Williams --- util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index 6e0ab27..31a1768 100644 --- 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) -- 2.40.0