aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-03-13 02:41:41 -0600
committerRob Landley <rob@landley.net>2021-03-13 02:41:41 -0600
commit4ff131ff958e2bbe7f1cc8a3d0e0acdd4a48c7ee (patch)
treee14392adbd5a4055474eda8c5803958840a6bf8b
parent56ef8fcedc48bed353e3ccc694a8db3f322fae6f (diff)
downloadtoybox-4ff131ff958e2bbe7f1cc8a3d0e0acdd4a48c7ee.tar.gz
Elliott spotted that errno==EAGAIN usually goes with an rc of -1, not 0.
(I hit 0 paired with EAGAIN causing premature pipeline end many years ago when a pipeline was Ctrl-Z then fg, may not still be possible with modern kernels but I left that covered just in case.)
-rw-r--r--lib/portability.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/portability.c b/lib/portability.c
index 0c364c29..f3c3c251 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -622,12 +622,13 @@ long long sendfile_len(int in, int out, long long bytes, long long *consumed)
len = bytes-total;
if (bytes<0 || len>sizeof(libbuf)) len = sizeof(libbuf);
+ errno = 0;
#if CFG_TOYBOX_COPYFILERANGE
len = copy_file_range(in, 0, out, 0, bytes, 0);
#else
ww = len = read(in, libbuf, len);
#endif
- if (!len && errno==EAGAIN) continue;
+ if (len<1 && errno==EAGAIN) continue;
if (len<1) break;
if (consumed) *consumed += len;
if (ww && writeall(out, libbuf, len) != len) return -1;