* gets_fromFile
*
* Gets a line of noninteractive input from a file (which could be stdin).
- * The result is a malloc'd string.
+ * The result is a malloc'd string, or NULL on EOF or input error.
*
* Caller *must* have set up sigint_interrupt_jmp before calling.
*
/* Disable SIGINT again */
sigint_interrupt_enabled = false;
- /* EOF? */
+ /* EOF or error? */
if (result == NULL)
+ {
+ if (ferror(source))
+ {
+ psql_error("could not read from input file: %s\n", strerror(errno));
+ return NULL;
+ }
break;
+ }
appendPQExpBufferStr(buffer, line);
line = gets_interactive(get_prompt(prompt_status));
}
else
+ {
line = gets_fromFile(source);
+ if (!line && ferror(source))
+ successResult = EXIT_FAILURE;
+ }
/*
* query_buf holds query already accumulated. line is the malloc'd