From: Jim Meyering Date: Sat, 13 Dec 1997 23:39:09 +0000 (+0000) Subject: (main): Add some braces. X-Git-Tag: FILEUTILS-3_16g~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b86f6c23087e8d1bf61493c0794f2fdf46dc6e18;p=platform%2Fupstream%2Fcoreutils.git (main): Add some braces. Check return code from fclose of each input file. Close stdout and check for errors. --- diff --git a/src/fmt.c b/src/fmt.c index 29b426f..5323896 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -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); }