From: Ramkumar Ramachandra Date: Fri, 20 May 2011 08:30:23 GMT Subject: [RFC PATCH] wrapper: Introduce xclose to restart close on EINTR Message-ID: <1305880223-7542-3-git-send-email-artagnon@gmail.com> In-Reply-To: <1305880223-7542-1-git-send-email-artagnon@gmail.com> Suggested-by: Jonathan Nieder Signed-off-by: Ramkumar Ramachandra --- git-compat-util.h | 1 + wrapper.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index 40498b3..6e06ad4 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -428,6 +428,7 @@ extern void *xcalloc(size_t nmemb, size_t size); extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); extern ssize_t xread(int fd, void *buf, size_t len); extern ssize_t xwrite(int fd, const void *buf, size_t len); +extern int xclose(int fd); extern int xdup(int fd); extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); diff --git a/wrapper.c b/wrapper.c index 2829000..717e989 100644 --- a/wrapper.c +++ b/wrapper.c @@ -141,6 +141,21 @@ ssize_t xwrite(int fd, const void *buf, size_t len) } } +/* + * xclose() is the same a close(), but it automatically restarts close() + * operations with a recoverable error (EINTR). + */ +int xclose(int fd) +{ + int ret; + while (1) { + ret = close(fd); + if ((ret < 0) && errno == EINTR) + continue; + return ret; + } +} + ssize_t read_in_full(int fd, void *buf, size_t count) { char *p = buf; -- 1.7.5.GIT