From d5866987ff5c457ba732f2b52803000c213c26eb Mon Sep 17 00:00:00 2001 From: James Zern Date: Sat, 15 Mar 2014 12:35:44 -0700 Subject: [PATCH] y4minput: add more error reporting on read failure Change-Id: Iedb136e4019ec3eb3005ea567efb33902dccfb8d --- y4minput.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/y4minput.c b/y4minput.c index 15186f86f..90c5310a1 100644 --- a/y4minput.c +++ b/y4minput.c @@ -22,13 +22,14 @@ static int file_read(void *buf, size_t size, FILE *file) { const int kMaxRetries = 5; int retry_count = 0; + int file_error; size_t len = 0; do { const size_t n = fread((uint8_t*)buf + len, 1, size - len, file); len += n; - if (ferror(file)) { + file_error = ferror(file); + if (file_error) { if (errno == EINTR || errno == EAGAIN) { - ++retry_count; clearerr(file); continue; } else { @@ -37,7 +38,14 @@ static int file_read(void *buf, size_t size, FILE *file) { return 0; } } - } while (!feof(file) && len < size && retry_count < kMaxRetries); + } while (!feof(file) && len < size && ++retry_count < kMaxRetries); + + if (!feof(file) && len != size) { + fprintf(stderr, "Error reading file: %u of %u bytes read," + " error: %d, retries: %d, %d: %s\n", + (uint32_t)len, (uint32_t)size, file_error, retry_count, + errno, strerror(errno)); + } return len == size; }