From b425950f8b13f48bda2fb3672a36737e801b0e06 Mon Sep 17 00:00:00 2001 From: Evan Hempel Date: Thu, 12 Feb 2015 20:32:20 -0500 Subject: [PATCH] Extra debug information for 'fread failed' --- attic/_hashindex.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/attic/_hashindex.c b/attic/_hashindex.c index c0c541287..a1f70699d 100644 --- a/attic/_hashindex.c +++ b/attic/_hashindex.c @@ -135,6 +135,7 @@ hashindex_read(const char *path) { FILE *fd; off_t length; + off_t bytes_read; HashHeader header; HashIndex *index = NULL; @@ -142,8 +143,9 @@ hashindex_read(const char *path) EPRINTF_PATH(path, "fopen failed"); return NULL; } - if(fread(&header, 1, sizeof(HashHeader), fd) != sizeof(HashHeader)) { - EPRINTF_PATH(path, "fread failed"); + bytes_read = fread(&header, 1, sizeof(HashHeader), fd); + if(bytes_read != sizeof(HashHeader)) { + EPRINTF_PATH(path, "fread header failed (expected %ld, got %ld)", sizeof(HashHeader), bytes_read); goto fail; } if(fseek(fd, 0, SEEK_END) < 0) { @@ -176,8 +178,9 @@ hashindex_read(const char *path) index = NULL; goto fail; } - if(fread(index->data, 1, length, fd) != length) { - EPRINTF_PATH(path, "fread failed"); + bytes_read = fread(index->data, 1, length, fd); + if(bytes_read != length) { + EPRINTF_PATH(path, "fread hashindex failed (expected %ld, got %ld)", length, bytes_read); free(index->data); free(index); index = NULL;