diff --git a/lib/portability.c b/lib/portability.c index 89744dd04..89ee78e91 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -623,42 +623,34 @@ int get_block_device_size(int fd, unsigned long long* size) } #endif -static ssize_t copy_file_range_wrap(int infd, off_t *inoff, int outfd, - off_t *outoff, size_t len, unsigned flags) -{ - // glibc added this constant in git at the end of 2017, shipped in 2018-02. -#if defined(__NR_copy_file_range) - return syscall(__NR_copy_file_range, infd, inoff, outfd, outoff, len, flags); -#else - errno = EINVAL; - return -1; -#endif -} - // Return bytes copied from in to out. If bytes <0 copy all of in to out. // If consumed isn't null, amount read saved there (return is written or error) long long sendfile_len(int in, int out, long long bytes, long long *consumed) { long long total = 0, len, ww; - int copy_file_range = CFG_TOYBOX_COPYFILERANGE; + int try_cfr = 1; if (consumed) *consumed = 0; - if (in<0) return 0; - while (bytes != total) { + if (in>=0) while (bytes != total) { ww = 0; len = bytes-total; errno = 0; - if (copy_file_range) { + if (try_cfr) { if (bytes<0 || bytes>(1<<30)) len = (1<<30); - len = copy_file_range_wrap(in, 0, out, 0, len, 0); + // glibc added this constant in git at the end of 2017, shipped 2018-02. +#if defined (__NR_copy_file_range) + len = syscall(__NR_copy_file_range, in, 0, out, 0, len, 0); +#else + errno = EINVAL; + len = -1; +#endif if (len < 0 && errno == EINVAL) { - copy_file_range = 0; + try_cfr = 0; continue; } - } - if (!copy_file_range) { + } else { if (bytes<0 || len>sizeof(libbuf)) len = sizeof(libbuf); ww = len = read(in, libbuf, len); } diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index af87c6596..f2be86534 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -100,13 +100,6 @@ EOF int main(void) { char buf[100]; getrandom(buf, 100, 0); } EOF - # glibc requires #define GNU to get the wrapper for this Linux system call, - # so just use syscall(). - probesymbol TOYBOX_COPYFILERANGE << EOF - #include - #include - int main(void) { syscall(__NR_copy_file_range, 0, 0, 1, 0, 123, 0); } -EOF probesymbol TOYBOX_HASTIMERS << EOF #include #include