Pádraig Brady <[email protected]> writes: > * src/fmt.c (fmt): Pass errno to error() so that > the particular error is diagnosed. > * NEWS: Mention the improvement. > --- > NEWS | 3 +++ > src/fmt.c | 4 ++-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/NEWS b/NEWS > index 1ccc52426..78f15884a 100644 > --- a/NEWS > +++ b/NEWS > @@ -81,6 +81,9 @@ GNU coreutils NEWS -*- > outline -*- > 'du' now processes directories with 10,000 or more entries up to 9 times > faster on the Lustre file system. > > + 'fmt' did now correctly diagnoses read errors. > + Previously fmt generated a generic error for any read error. > + > 'pinky' will now exit immediately upon receiving a write error, which is > significant when reading large plan or project files. > > diff --git a/src/fmt.c b/src/fmt.c > index ae689ec28..8928a32b4 100644 > --- a/src/fmt.c > +++ b/src/fmt.c > @@ -501,9 +501,9 @@ fmt (FILE *f, char const *file) > if (0 <= err) > { > if (f == stdin) > - error (0, err, _("read error")); > + error (0, errno, _("read error")); > else > - error (0, err, _("error reading %s"), quoteaf (file)); > + error (0, errno, _("error reading %s"), quoteaf (file)); > } > return err < 0; > }
Ah, it would just say something like the "fmt: read error" with no more description, right? I ran into something similar with my recent 'ls' patch, which you mentioned was a bit awkward since it checked "ferror (stdout)" in multiple places. The issue there was that the directory being entered was printed, which may set the error flag, but then readdir was called afterwards. We set errno to zero before that to check if readdir fails or if it just finds no entries. Later on no entries would need to be printed, so errno would be zero or an error given by readdir. It is certainly worth testing to avoid unhelpful error messages. Thanks, Collin
