gbranden pushed a commit to branch master
in repository groff.
commit 06e5aa407fffefc06fdf44faa4c6933951208bac
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Oct 3 01:27:19 2020 +1000
src/roff/troff/node.cpp: Expand diagnostics.
* src/roff/troff/node.cpp: Make diagnostics slightly more informative in
unusual error cases.
(real_output_file::~real_output_file): If ferror() reports error status
on a stream say that, instead of "error writing". If it does not, but
fflush() fails on the stream, describe the flush as failing, and use
strerror() since fflush() sets errno. If pclose() fails, say that we
were unable to close a pipe instead of repeating the name of the C
library function to the user, who might not be a C programmer. Report
sterror() in this case and for a failing fclose().
(real_output_file::flush): Repeat updated fflush() logic from
previous function.
Also copy a cautionary comment preceding the fflush() failure logic
between the functions.
The changes arose while I was investigating Savannah #59202.
---
ChangeLog | 15 +++++++++++++++
src/roff/troff/node.cpp | 19 +++++++++++++------
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4cd1f40..b0aa742 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2020-10-02 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/node.cpp: Make diagnostics slightly more
+ informative in unusual error cases.
+ (real_output_file::~real_output_file): If ferror() reports error
+ status on a stream say that, instead of "error writing". If it
+ does not, but fflush() fails on the stream, describe the flush
+ as failing, and use strerror() since fflush() sets errno. If
+ pclose() fails, say that we were unable to close a pipe instead
+ of repeating the name of the C library function to the user, who
+ might not be a C programmer. Report sterror() in this case and
+ for a failing fclose().
+ (real_output_file::flush): Repeat updated fflush() logic from
+ previous function.
+
2020-09-30 G. Branden Robinson <[email protected]>
* tmac/an-old.tmac (register setup): Make interaction of \n[C]
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index b2a9982..4a4e7e1 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1658,16 +1658,20 @@ real_output_file::~real_output_file()
// Prevent destructor from recursing; see div.cpp:cleanup_and_exit().
is_dying = true;
// To avoid looping, set fp to 0 before calling fatal().
- if (ferror(fp) || fflush(fp) < 0) {
+ if (ferror(fp)) {
fp = 0;
- fatal("error writing output file");
+ fatal("error on output file stream");
+ }
+ else if (fflush(fp) < 0) {
+ fp = 0;
+ fatal("unable to flush output file: %1", strerror(errno));
}
#ifndef POPEN_MISSING
if (piped) {
int result = pclose(fp);
fp = 0;
if (result < 0)
- fatal("pclose failed");
+ fatal("unable to close pipe: %1", strerror(errno));
if (!WIFEXITED(result))
error("output process '%1' got fatal signal %2",
pipe_command,
@@ -1683,14 +1687,17 @@ real_output_file::~real_output_file()
#endif /* not POPEN MISSING */
if (fclose(fp) < 0) {
fp = 0;
- fatal("error closing output file");
+ fatal("unable to close output file: %1", strerror(errno));
}
}
void real_output_file::flush()
{
- if (fflush(fp) < 0)
- fatal("error writing output file");
+ // To avoid looping, set fp to 0 before calling fatal().
+ if (fflush(fp) < 0) {
+ fp = 0;
+ fatal("unable to flush output file: %1", strerror(errno));
+ }
}
int real_output_file::is_printing()
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit