(foreign-declare " #include #include #include #include ") ;; EAGAIN may be signaled even when partial data is sent, but the caller expects EAGAIN ;; to mean zero bytes sent, so we return the number of bytes sent when non-zero. (define %sendfile-implementation (foreign-lambda* ssize_t ((integer src) (integer dst) (ssize_t offset) (ssize_t to_send)) " off_t res = to_send; if(sendfile(src,dst,offset,&res,NULL,0) < 0) { if(errno == EAGAIN || errno == EINTR) { C_return(res == 0 ? -2 : offset + res); }else { C_return(-1); } } C_return(offset + res); "))