Skip to content

Commit 4e61b22

Browse files
Eric Wonggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 280738c commit 4e61b22

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

packfile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,8 @@ static int open_packed_git_1(struct packed_git *p)
555555
" while index indicates %"PRIu32" objects",
556556
p->pack_name, ntohl(hdr.hdr_entries),
557557
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);
561560
if (read_result < 0)
562561
return error_errno("error reading from %s", p->pack_name);
563562
if (read_result != hashsz)

0 commit comments

Comments
 (0)