Skip to content

Commit c6cf7f0

Browse files
authored
Merge pull request libgit2#5769 from lhchavez/pwrite-pread
Use `p_pwrite`/`p_pread` consistently throughout the codebase
2 parents 81c98af + ff6f675 commit c6cf7f0

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

src/indexer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
656656
size_t page_offset;
657657
off64_t page_start;
658658
off64_t current_size = idx->pack->mwf.size;
659-
int fd = idx->pack->mwf.fd;
660659
int error;
661660

662661
if (!size)
@@ -673,8 +672,7 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
673672
page_offset = new_size % mmap_alignment;
674673
page_start = new_size - page_offset;
675674

676-
if (p_lseek(fd, page_start + mmap_alignment - 1, SEEK_SET) < 0 ||
677-
p_write(idx->pack->mwf.fd, data, 1) < 0) {
675+
if (p_pwrite(idx->pack->mwf.fd, data, 1, page_start + mmap_alignment - 1) < 0) {
678676
git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name);
679677
return -1;
680678
}

src/midx.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,7 @@ bool git_midx_needs_refresh(
353353
return true;
354354
}
355355

356-
if (p_lseek(fd, -GIT_OID_RAWSZ, SEEK_END) < 0) {
357-
p_close(fd);
358-
return true;
359-
}
360-
361-
bytes_read = p_read(fd, &idx_checksum, GIT_OID_RAWSZ);
356+
bytes_read = p_pread(fd, &idx_checksum, GIT_OID_RAWSZ, st.st_size - GIT_OID_RAWSZ);
362357
p_close(fd);
363358

364359
if (bytes_read != GIT_OID_RAWSZ)

src/pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,7 @@ static int packfile_open_locked(struct git_pack_file *p)
11301130

11311131
/* Verify the pack matches its index. */
11321132
if (p->num_objects != ntohl(hdr.hdr_entries) ||
1133-
p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1 ||
1134-
p_read(p->mwf.fd, sha1.id, GIT_OID_RAWSZ) < 0)
1133+
p_pread(p->mwf.fd, sha1.id, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
11351134
goto cleanup;
11361135

11371136
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;

0 commit comments

Comments
 (0)