| 1035 | /* Close FP, whose name is FILE, and report any errors. */ |
| 1036 | |
| 1037 | static void |
| 1038 | xfclose (FILE *fp, char const *file) |
| 1039 | { |
| 1040 | switch (fileno (fp)) |
| 1041 | { |
| 1042 | case STDIN_FILENO: |
| 1043 | /* Allow reading stdin from tty more than once. */ |
| 1044 | clearerr (fp); |
| 1045 | break; |
| 1046 | |
| 1047 | case STDOUT_FILENO: |
| 1048 | /* Don't close stdout just yet. close_stdout does that. */ |
| 1049 | if (fflush (fp) != 0) |
| 1050 | sort_die (_("fflush failed"), file); |
| 1051 | break; |
| 1052 | |
| 1053 | default: |
| 1054 | if (fclose (fp) != 0) |
| 1055 | sort_die (_("close failed"), file); |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | /* Move OLDFD to NEWFD. If OLDFD != NEWFD, NEWFD is not close-on-exec. */ |
| 1061 | |