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 <junkio@cox.net>
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user