void jq_util_input_set_parser(jq_util_input_state, jv_parser *, int);
void jq_util_input_free(jq_util_input_state *);
void jq_util_input_add_input(jq_util_input_state, jv);
-int jq_util_input_open_errors(jq_util_input_state);
+int jq_util_input_errors(jq_util_input_state);
jv jq_util_input_next_input(jq_util_input_state);
jv jq_util_input_next_input_cb(jq_state *, void *);
ret = process(jq, jv_null(), jq_flags, dumpopts);
} else {
jv value;
- while (jq_util_input_open_errors(input_state) == 0 &&
+ while (jq_util_input_errors(input_state) == 0 &&
(jv_is_valid((value = jq_util_input_next_input(input_state))) || jv_invalid_has_msg(jv_copy(value)))) {
if (jv_is_valid(value)) {
ret = process(jq, value, jq_flags, dumpopts);
}
}
- if (jq_util_input_open_errors(input_state) != 0)
+ if (jq_util_input_errors(input_state) != 0)
ret = 2;
out:
jv_parser *parser;
FILE* current_input;
jv files;
- int open_failures;
+ int failures;
jv slurped;
char buf[4096];
size_t buf_valid_len;
state->files = jv_array_append(state->files, fname);
}
-int jq_util_input_open_errors(jq_util_input_state state) {
- return state->open_failures;
+int jq_util_input_errors(jq_util_input_state state) {
+ return state->failures;
}
static jv next_file(jq_util_input_state state) {
state->current_input = fopen(jv_string_value(f), "r");
if (!state->current_input) {
state->err_cb(state->err_cb_data, jv_copy(f));
- state->open_failures++;
+ state->failures++;
}
}
jv_free(f);
state->buf[0] = 0;
state->buf_valid_len = 0;
if (state->current_input) {
+ char *res;
memset(state->buf, 0, sizeof(state->buf));
- if (!fgets(state->buf, sizeof(state->buf), state->current_input)) {
+
+ while (!(res = fgets(state->buf, sizeof(state->buf), state->current_input)) &&
+ ferror(state->current_input) && errno == EINTR)
+ clearerr(state->current_input);
+ if (res == NULL) {
state->buf[0] = 0;
+ if (ferror(state->current_input))
+ state->failures++;
} else {
const char *p = memchr(state->buf, '\n', sizeof(state->buf));
*
* We can't use getline() because there need not be any newlines
* in the input. The only entirely correct choices are: use
- * fgetc() or read(), and of those the latter will be the
- * best-performing.
+ * fgetc() or fread(). Using fread() will complicate buffer
+ * management here.
*
* For now we guess how much fgets() read.
*/