diff options
author | John Millaway <john43@users.sourceforge.net> | 2006-02-13 21:18:57 +0000 |
---|---|---|
committer | John Millaway <john43@users.sourceforge.net> | 2006-02-13 21:18:57 +0000 |
commit | c02e0ee42a39beb643455eba57256c8b3c7ee583 (patch) | |
tree | cf33e4d43cf9e763529e669c133265de4bc6519a /main.c | |
parent | 5059f892d999727df92eb5eabe91f952c94d8e12 (diff) |
Fixed double-fclose when input file is empty.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -136,6 +136,7 @@ extern FILE* yyout; static char outfile_path[MAXLINE]; static int outfile_created = 0; static char *skelname = NULL; +static int _stdout_closed = 0; /* flag to prevent double-fclose() on stdout. */ /* For debugging. The max number of filters to apply to skeleton. */ static int preproc_level = 1000; @@ -158,8 +159,10 @@ int flex_main (argc, argv) */ exit_status = setjmp (flex_main_jmp_buf); if (exit_status){ - fflush(stdout); - fclose(stdout); + if (stdout && !_stdout_closed && !ferror(stdout)){ + fflush(stdout); + fclose(stdout); + } while (wait(0) > 0){ } return exit_status - 1; @@ -683,7 +686,7 @@ void flexend (exit_status) lerrsf (_("error writing output file %s"), outfilename); - else if (fclose (stdout)) + else if ((_stdout_closed = 1) && fclose (stdout)) lerrsf (_("error closing output file %s"), outfilename); |