@matheusbsbs / matheus-bagliano / commits / 4e61b2214d
Fork 0

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 <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Dec 26, 2019 at 10:42 UTC 4e61b2214d333a47ec56eb0806be1774f7ac1b7d
1 file changed +2 -3
packfile.c
+2 -3
@@ -555,9 +555,8 @@ static int open_packed_git_1(struct packed_git *p)
555 " while index indicates %"PRIu32" objects",
556 p->pack_name, ntohl(hdr.hdr_entries),
557 p->num_objects);
558 - if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1)
559 - return error("end of packfile %s is unavailable", p->pack_name);
560 - read_result = read_in_full(p->pack_fd, hash, hashsz);
558 + read_result = pread_in_full(p->pack_fd, hash, hashsz,
559 + p->pack_size - hashsz);
560 if (read_result < 0)
561 return error_errno("error reading from %s", p->pack_name);
562 if (read_result != hashsz)