summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2022-06-22 19:25:30 +0200
committercgzones <cgzones@googlemail.com>2022-06-28 14:39:11 +0200
commitf3e70ab389879db5b250bab29f14acb543bfd11f (patch)
tree729b829ad49370ab4a0ddc1a891c30ed3911d157
parent393796d75da57983710f8bfdacd272f773fad47b (diff)
Write full buffermain
Retry writing after a short write.
-rw-r--r--CRT.c2
-rw-r--r--XUtils.c23
-rw-r--r--XUtils.h2
3 files changed, 26 insertions, 1 deletions
diff --git a/CRT.c b/CRT.c
index 95f8cc13..c8935add 100644
--- a/CRT.c
+++ b/CRT.c
@@ -834,7 +834,7 @@ static void dumpStderr(void) {
fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n");
header = true;
}
- (void)! write(STDERR_FILENO, buffer, res);
+ full_write(STDERR_FILENO, buffer, res);
}
}
diff --git a/XUtils.c b/XUtils.c
index 2012b6c6..5d84e137 100644
--- a/XUtils.c
+++ b/XUtils.c
@@ -313,3 +313,26 @@ ssize_t xReadfileat(openat_arg_t dirfd, const char* pathname, void* buffer, size
return readfd_internal(fd, buffer, count);
}
+
+ssize_t full_write(int fd, const void *buf, size_t count) {
+ ssize_t written = 0;
+
+ while (count > 0) {
+ ssize_t r = write(fd, buf, count);
+ if (r < 0) {
+ if (errno == EINTR)
+ continue;
+
+ return r;
+ }
+
+ if (r == 0)
+ break;
+
+ written += r;
+ buf = (const unsigned char*)buf + r;
+ count -= (size_t)r;
+ }
+
+ return written;
+}
diff --git a/XUtils.h b/XUtils.h
index 2522a71f..bb80cb23 100644
--- a/XUtils.h
+++ b/XUtils.h
@@ -73,4 +73,6 @@ char* xStrndup(const char* str, size_t len) ATTR_NONNULL ATTR_MALLOC;
ssize_t xReadfile(const char* pathname, void* buffer, size_t count);
ssize_t xReadfileat(openat_arg_t dirfd, const char* pathname, void* buffer, size_t count);
+ssize_t full_write(int fd, const void *buf, size_t count);
+
#endif

© 2014-2022 Faster IT GmbH | imprint | privacy policy