From b170b5b5da436ac79e9e9a8e55b8d04662892aa4 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Wed, 16 Mar 2011 16:24:54 +0100 Subject: [PATCH] Bloody perror messes with errno; need to save errno. --- common/ioall.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/ioall.c b/common/ioall.c index a99a8aa..239f333 100644 --- a/common/ioall.c +++ b/common/ioall.c @@ -25,6 +25,14 @@ #include #include +void perror_wrapper(char * msg) +{ + int prev=errno; + perror(msg); + errno=prev; +} + + int write_all(int fd, void *buf, int size) { int written = 0; @@ -34,7 +42,7 @@ int write_all(int fd, void *buf, int size) if (ret == -1 && errno == EINTR) continue; if (ret <= 0) { - perror("write"); + perror_wrapper("write"); return 0; } written += ret; @@ -57,7 +65,7 @@ int read_all(int fd, void *buf, int size) return 0; } if (ret < 0) { - perror("read"); + perror_wrapper("read"); return 0; } got_read += ret; @@ -77,11 +85,11 @@ int copy_fd_all(int fdout, int fdin) if (!ret) break; if (ret < 0) { - perror("read"); + perror_wrapper("read"); return 0; } if (!write_all(fdout, buf, ret)) { - perror("write"); + perror_wrapper("write"); return 0; } }