Don't probe for copy_file_range, we already have an #ifdef.

This commit is contained in:
Rob Landley 2022-05-29 17:47:33 -05:00
parent 6d4847934f
commit 6ef2431a0f
2 changed files with 12 additions and 27 deletions

View File

@ -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);
}

View File

@ -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 <sys/syscall.h>
#include <unistd.h>
int main(void) { syscall(__NR_copy_file_range, 0, 0, 1, 0, 123, 0); }
EOF
probesymbol TOYBOX_HASTIMERS << EOF
#include <signal.h>
#include <time.h>