--- coreutils/coreutils-8.28/src/fmt.c 2017-09-01 00:11:03.000000000 -0700 +++ coreutils_modified/coreutils-8.28/src/fmt.c 2018-12-11 16:18:50.296134362 -0800 @@ -320,7 +320,7 @@ bool ok = true; char const *max_width_option = NULL; char const *goal_width_option = NULL; - + struct stat fileinfo; initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); @@ -423,27 +423,41 @@ fmt (stdin); else { - FILE *in_stream; - in_stream = fopen (file, "r"); - if (in_stream != NULL) - { - fmt (in_stream); - if (fclose (in_stream) == EOF) - { - error (0, errno, "%s", quotef (file)); - ok = false; + if (stat(file, &fileinfo) == 0) + { + if (S_ISBLK(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) || S_ISFIFO(fileinfo.st_mode)) + { + error (0, errno, _("unsupported filetype detected for %s"), quoteaf (file)); + ok = false; + } + else + { + FILE *in_stream; + in_stream = fopen (file, "r"); + if (in_stream != NULL) + { + fmt (in_stream); + if (fclose (in_stream) == EOF) + { + error (0, errno, "%s", quotef (file)); + ok = false; + } + } + else + { + error (0, errno, _("cannot open %s for reading"), quoteaf (file)); + ok = false; + } } - } - else - { - error (0, errno, _("cannot open %s for reading"), - quoteaf (file)); - ok = false; - } + } + else + { + error (0, errno, _("error applying stat on file %s"), quoteaf (file)); + ok = false; + } } } - } - + } return ok ? EXIT_SUCCESS : EXIT_FAILURE; } ---------------------------------------------------------------------------------------------------- --- coreutils_modified/coreutils-8.28/tests/fmt/base.pl 2018-12-11 18:17:02.770372487 -0800 +++ coreutils/coreutils-8.28/tests/fmt/base.pl 2017-09-01 00:11:03.000000000 -0700 @@ -35,7 +35,7 @@ ['bad-suffix', '-72x', {IN=> ''}, {ERR => "fmt: invalid width: '72x'\n"}, {EXIT => 1}], ['no-file', 'no-such-file', - {ERR => "fmt: error applying stat on file 'no-such-file':" + {ERR => "fmt: cannot open 'no-such-file' for reading:" . " No such file or directory\n"}, {EXIT => 1}], ['obs-1', '-c -72', {ERR => "fmt: invalid option -- 7; -WIDTH is recognized only when it"