diff options
author | Jim Meyering <jim@meyering.net> | 1997-12-13 23:39:09 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1997-12-13 23:39:09 +0000 |
commit | b86f6c23087e8d1bf61493c0794f2fdf46dc6e18 (patch) | |
tree | e64cfe30ac4f6fbeabe14692b89554de2b319b0f /src/fmt.c | |
parent | 444c6da14493b42305fa34183f199e8c6b366b0c (diff) | |
download | coreutils-b86f6c23087e8d1bf61493c0794f2fdf46dc6e18.tar.xz |
(main): Add some braces.
Check return code from fclose of each input file.
Close stdout and check for errors.
Diffstat (limited to 'src/fmt.c')
-rw-r--r-- | src/fmt.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -323,7 +323,6 @@ int main (register int argc, register char **argv) { int optchar; - FILE *infile; program_name = argv[0]; setlocale (LC_ALL, ""); @@ -409,20 +408,30 @@ main (register int argc, register char **argv) if (optind == argc) fmt (stdin); else - for (; optind < argc; optind++) - if (strcmp (argv[optind], "-") == 0) - fmt (stdin); - else + { + for (; optind < argc; optind++) { - infile = fopen (argv[optind], "r"); - if (infile != NULL) + char *file = argv[optind]; + if (strcmp (file, "-") == 0) + fmt (stdin); + else { - fmt (infile); - fclose (infile); + FILE *in_stream; + in_stream = fopen (file, "r"); + if (in_stream != NULL) + { + fmt (in_stream); + if (fclose (in_stream) == EOF) + error (EXIT_FAILURE, errno, file); + } + else + error (0, errno, file); } - else - error (0, errno, argv[optind]); } + } + + if (ferror (stdout) || fclose (stdout) == EOF) + error (EXIT_FAILURE, errno, _("write error")); exit (EXIT_SUCCESS); } |