main (register int argc, register char **argv)
{
int optchar;
- FILE *infile;
program_name = argv[0];
setlocale (LC_ALL, "");
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);
}