Cleanup read_cache_from error handling.
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>
Shawn O. Pearce committed
Dec 25, 2006 at 23:40 UTC
5fe5c8300da67a07bd430a33c474ef1498cb1d4b
1 file changed
+4
-4
read-cache.c
+4
-4
@@ -793,16 +793,16 @@ int read_cache_from(const char *path)
793
die("index file open failed (%s)", strerror(errno));
794
}
795
796
- cache_mmap = MAP_FAILED;
796
if (!fstat(fd, &st)) {
797
cache_mmap_size = st.st_size;
798
errno = EINVAL;
799
if (cache_mmap_size >= sizeof(struct cache_header) + 20)
800
cache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
802
- }
801
+ else
802
+ die("index file smaller than expected");
803
+ } else
804
+ die("cannot stat the open index (%s)", strerror(errno));
805
close(fd);
804
- if (cache_mmap == MAP_FAILED)
805
- die("index file mmap failed (%s)", strerror(errno));
806
807
hdr = cache_mmap;
808
if (verify_hdr(hdr, cache_mmap_size) < 0)