libbb/xwrite: print errno on "short write" errors
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Sep 2016 13:20:10 +0000 (15:20 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Sep 2016 13:20:10 +0000 (15:20 +0200)
Lauri Kasanen:
:: Over at TinyCore, we receive a huge number of questions of the type "I
:: got "short write", what does it mean?". Mostly for the rpi port and when
:: using bb wget.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/xfuncs_printf.c

index e9222f690654441bd7dfc5f61c66348154593ac9..1b11caf6b1001555138e88c02ee46099aea0c1b1 100644 (file)
@@ -235,8 +235,16 @@ void FAST_FUNC xwrite(int fd, const void *buf, size_t count)
 {
        if (count) {
                ssize_t size = full_write(fd, buf, count);
-               if ((size_t)size != count)
-                       bb_error_msg_and_die("short write");
+               if ((size_t)size != count) {
+                       /*
+                        * Two cases: write error immediately;
+                        * or some writes succeeded, then we hit an error.
+                        * In either case, errno is set.
+                        */
+                       bb_perror_msg_and_die(
+                               size >= 0 ? "short write" : "write error"
+                       );
+               }
        }
 }
 void FAST_FUNC xwrite_str(int fd, const char *str)