aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/read.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libbb/read.c b/libbb/read.c
index 5906bc225..a342506a8 100644
--- a/libbb/read.c
+++ b/libbb/read.c
@@ -12,9 +12,17 @@ ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count)
{
ssize_t n;
- do {
+ for (;;) {
n = read(fd, buf, count);
- } while (n < 0 && errno == EINTR);
+ if (n >= 0 || errno != EINTR)
+ break;
+ /* Some callers set errno=0, are upset when they see EINTR.
+ * Returning EINTR is wrong since we retry read(),
+ * the "error" was transient.
+ */
+ errno = 0;
+ /* repeat the read() */
+ }
return n;
}