From 1c15afb9343bca82e687d008ec983a9110ac9c40 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 19 Dec 2005 16:18:28 -0800 Subject: xread/xwrite: do not worry about EINTR at calling sites. We had errno==EINTR check after read(2)/write(2) sprinkled all over the places, always doing continue. Consolidate them into xread()/xwrite() wrapper routines. Credits for suggestion goes to HPA -- bugs are mine. Signed-off-by: Junio C Hamano --- git-compat-util.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index ead0ede587..0c98c9937d 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -84,6 +84,28 @@ static inline void *xcalloc(size_t nmemb, size_t size) return ret; } +static inline ssize_t xread(int fd, void *buf, size_t len) +{ + ssize_t nr; + while (1) { + nr = read(fd, buf, len); + if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) + continue; + return nr; + } +} + +static inline ssize_t xwrite(int fd, const void *buf, size_t len) +{ + ssize_t nr; + while (1) { + nr = write(fd, buf, len); + if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) + continue; + return nr; + } +} + /* Sane ctype - no locale, and works with signed chars */ #undef isspace #undef isdigit -- cgit v1.2.3