From bb324087a8b10f9cc0cb2132ae2b0527363ad062 Mon Sep 17 00:00:00 2001 From: "Christopher M. Punches" Date: Thu, 8 Feb 2024 10:45:26 +0000 Subject: [PATCH] Update src/lcpex/helpers.h --- src/lcpex/helpers.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lcpex/helpers.h b/src/lcpex/helpers.h index 7c458b7..802a8da 100644 --- a/src/lcpex/helpers.h +++ b/src/lcpex/helpers.h @@ -16,6 +16,18 @@ enum CHILD_PIPE_NAMES { #define BUFFER_SIZE 1024 -ssize_t write_all(int fd, const void *buf, size_t count); +ssize_t write_all(int fd, const void *buf, size_t count) { + const char *p = (const char *)buf; + while (count > 0) { + ssize_t written = write(fd, p, count); + if (written == -1) { + if (errno == EINTR || errno == EAGAIN) continue; // Retry + return -1; // Other errors + } + count -= written; + p += written; + } + return 0; +} #endif //LCPEX_HELPERS_H