static bool close_input(compilation_unit_t *unit)
{
- if (unit->input == NULL || unit->input == stdin)
- return true;
-
- if (unit->input_is_pipe) {
- int res = pclose(unit->input);
- if (res != EXIT_SUCCESS)
- return false;
+ assert(unit->input);
+ bool res;
+ if (unit->input == stdin) {
+ res = true;
+ } else if (unit->input_is_pipe) {
+ res = pclose(unit->input) == EXIT_SUCCESS;
} else {
fclose(unit->input);
+ res = true;
}
unit->input = NULL;
unit->name = NULL;
- return true;
+ return res;
}
static void print_error_summary(void)
switch_pp_input(unit->input, unit->name);
parse();
- translation_unit_t *ast = finish_parsing();
- unit->ast = ast;
+ unit->ast = finish_parsing();
check_unclosed_conditionals();
close_pp_input();
bool res = close_input(unit);
close_pp_input();
print_error_summary();
set_preprocessor_output(NULL);
- if (unit->input != stdin) {
- fclose(unit->input);
- unit->input = NULL;
- unit->name = NULL;
- }
if (unit->type == COMPILATION_UNIT_C) {
unit->type = COMPILATION_UNIT_PREPROCESSED_C;