From: Eric Wong Date: Thu, 26 Dec 2019 10:42:20 +0000 (+0000) Subject: packfile: replace lseek+read with pread X-Git-Tag: v2.25.0-rc2~14^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e61b2214d333a47ec56eb0806be1774f7ac1b7d;p=thirdparty%2Fgit.git packfile: replace lseek+read with pread We already have pread emulation for portability, so there's there's no reason to make two syscalls where one suffices. Furthermore, readers of the packfile will be using mmap (or pread to emulate mmap), anyways, so the file description offset does not matter in this case. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- diff --git a/packfile.c b/packfile.c index 518d9d5b54..fdb33fda81 100644 --- a/packfile.c +++ b/packfile.c @@ -555,9 +555,8 @@ static int open_packed_git_1(struct packed_git *p) " while index indicates %"PRIu32" objects", p->pack_name, ntohl(hdr.hdr_entries), p->num_objects); - if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1) - return error("end of packfile %s is unavailable", p->pack_name); - read_result = read_in_full(p->pack_fd, hash, hashsz); + read_result = pread_in_full(p->pack_fd, hash, hashsz, + p->pack_size - hashsz); if (read_result < 0) return error_errno("error reading from %s", p->pack_name); if (read_result != hashsz)