coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] yes: avoid redundant diagnostics on write error


From: Pádraig Brady
Subject: [PATCH] yes: avoid redundant diagnostics on write error
Date: Mon, 4 Apr 2016 13:20:20 +0100

* src/yes.c (main): For large inputs only write a single
diagnostic for write errors.
* tests/misc/yes.sh: Test when /dev/full is available.
---
 src/yes.c         |  2 ++
 tests/misc/yes.sh | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/yes.c b/src/yes.c
index 31424cf..1d2c612 100644
--- a/src/yes.c
+++ b/src/yes.c
@@ -121,6 +121,7 @@ main (int argc, char **argv)
       if ((pbuf - buf) && fwrite (buf, pbuf - buf, 1, stdout) != 1)
         {
           error (0, errno, _("standard output"));
+          clearerr (stdout);
           return EXIT_FAILURE;
         }
       for (j = i; j < argc; j++)
@@ -128,6 +129,7 @@ main (int argc, char **argv)
             || putchar (j == argc - 1 ? '\n' : ' ') == EOF)
           {
             error (0, errno, _("standard output"));
+            clearerr (stdout);
             return EXIT_FAILURE;
           }
     }
diff --git a/tests/misc/yes.sh b/tests/misc/yes.sh
index 1371593..4b0d320 100755
--- a/tests/misc/yes.sh
+++ b/tests/misc/yes.sh
@@ -40,4 +40,17 @@ if external true $(seq 4000); then
   done
 fi
 
+# Check a single appropriate diagnostic is output on write error
+if test -w /dev/full && test -c /dev/full; then
+  # The single output diagnostic expected,
+  # (without the possibly varying :strerror(ENOSPC) suffix).
+  printf '%s\n' "yes: standard output" > exp
+
+  for size in 1 16384; do
+    returns_ 1 yes "$(printf %${size}s '')" >/dev/full 2>errt
+    sed 's/\(yes:.*\):.*/\1/' errt > err
+    compare exp err || fail=1
+  done
+fi
+
 Exit $fail
-- 
2.5.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]