Skip to content

Commit

Permalink
Cleanup read_cache_from error handling.
Browse files Browse the repository at this point in the history
When I converted the mmap() call to xmmap() I failed to cleanup the
way this routine handles errors and left some crufty code behind.
This is a small cleanup, suggested by Johannes.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Dec 29, 2006
1 parent c4712e4 commit 5fe5c83
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,16 +793,16 @@ int read_cache_from(const char *path)
die("index file open failed (%s)", strerror(errno));
}

cache_mmap = MAP_FAILED;
if (!fstat(fd, &st)) {
cache_mmap_size = st.st_size;
errno = EINVAL;
if (cache_mmap_size >= sizeof(struct cache_header) + 20)
cache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
}
else
die("index file smaller than expected");
} else
die("cannot stat the open index (%s)", strerror(errno));
close(fd);
if (cache_mmap == MAP_FAILED)
die("index file mmap failed (%s)", strerror(errno));

hdr = cache_mmap;
if (verify_hdr(hdr, cache_mmap_size) < 0)
Expand Down

0 comments on commit 5fe5c83

Please sign in to comment.