| 947 | of characters in this file. */ |
| 948 | |
| 949 | static void |
| 950 | close_output_file (void) |
| 951 | { |
| 952 | if (output_stream) |
| 953 | { |
| 954 | if (ferror (output_stream)) |
| 955 | { |
| 956 | error (0, 0, _("write error for %s"), quoteaf (output_filename)); |
| 957 | output_stream = NULL; |
| 958 | cleanup_fatal (); |
| 959 | } |
| 960 | if (fclose (output_stream) != 0) |
| 961 | { |
| 962 | error (0, errno, "%s", quotef (output_filename)); |
| 963 | output_stream = NULL; |
| 964 | cleanup_fatal (); |
| 965 | } |
| 966 | if (bytes_written == 0 && elide_empty_files) |
| 967 | { |
| 968 | sigset_t oldset; |
| 969 | bool unlink_ok; |
| 970 | int unlink_errno; |
| 971 | |
| 972 | /* Remove the output file in a critical section, to avoid races. */ |
| 973 | sigprocmask (SIG_BLOCK, &caught_signals, &oldset); |
| 974 | unlink_ok = (unlink (output_filename) == 0); |
| 975 | unlink_errno = errno; |
| 976 | files_created--; |
| 977 | sigprocmask (SIG_SETMASK, &oldset, NULL); |
| 978 | |
| 979 | if (! unlink_ok && unlink_errno != ENOENT) |
| 980 | error (0, unlink_errno, "%s", quotef (output_filename)); |
| 981 | } |
| 982 | else |
| 983 | { |
| 984 | if (!suppress_count) |
| 985 | fprintf (stdout, "%jd\n", bytes_written); |
| 986 | } |
| 987 | output_stream = NULL; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | /* Save line LINE to the output file and |
| 992 | increment the character count for the current file. */ |
no test coverage detected