From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS16276 79.137.64.0/18 X-Spam-Status: No, score=0.7 required=3.0 tests=BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,RDNS_DYNAMIC,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (168.ip-79-137-81.eu [79.137.81.168]) by dcvr.yhbt.net (Postfix) with ESMTP id 1BC601FC43 for ; Sat, 11 Mar 2017 00:57:13 +0000 (UTC) From: Eric Wong To: cmogstored-public@bogomips.org Subject: [PATCH] compat_sendfile: ensure this works without an offset Date: Sat, 11 Mar 2017 00:57:09 +0000 Message-Id: <20170311005709.12605-1-e@80x24.org> List-Id: While we never call sendfile without an offset, some projects may copy our code and want to use it without an offset. --- compat_sendfile.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compat_sendfile.h b/compat_sendfile.h index 8413891..c1cc9e4 100644 --- a/compat_sendfile.h +++ b/compat_sendfile.h @@ -12,14 +12,15 @@ static ssize_t compat_sendfile(int sockfd, int filefd, off_t *off, size_t count) max_pread = MIN(max_pread, count); do { - r = pread(filefd, buf, max_pread, *off); + r = off ? pread(filefd, buf, max_pread, *off) : + read(filefd, buf, max_pread); } while (r < 0 && errno == EINTR); if (r <= 0) return r; w = write(sockfd, buf, r); - if (w > 0) + if (w > 0 && off) *off += w; return w; } -- EW