From f1db0a1204d235fd13ea7b1ad6a3aca640125954 Mon Sep 17 00:00:00 2001 From: Mikael Larsson Date: Tue, 28 Sep 2010 16:49:50 +0200 Subject: Fix mmc_read_cmd_file mmc_read_cmd_file broke with the latest changes in fat and mmc. This makes it work again. Change-Id: I9bd0fee41bc4dfe790166415bb856104ab412536 Signed-off-by: Mikael Larsson Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/5765 Reviewed-by: Ulf HANSSON Reviewed-by: Michael BRANDT --- fs/fat/rockbox_wrapper.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'fs/fat') diff --git a/fs/fat/rockbox_wrapper.c b/fs/fat/rockbox_wrapper.c index cfd46d602..dd91d3831 100644 --- a/fs/fat/rockbox_wrapper.c +++ b/fs/fat/rockbox_wrapper.c @@ -337,22 +337,20 @@ file_fat_read(const char *filename, void *buffer, unsigned long maxsize) return -1; } + file_size = filesize(fd); + if (file_size < 0) { + fat_eprintf("Call to filesize() failed\n"); + return -1; + } + /* * If the number of bytes to read is zero, read the entire file. */ - if (maxsize == 0) { - file_size = filesize(fd); - if (file_size < 0) { - fat_eprintf("Call to filesize() failed\n"); - return -1; - } + if ((maxsize != 0) && (maxsize < file_size)) + file_size = maxsize; - maxsize = (unsigned long) file_size; - fat_dprintf("Reading entire file (%lu bytes)\n", maxsize); - } - - bytes = (long) read(fd, buffer, (size_t) maxsize); - if ((unsigned long) bytes != maxsize) { + bytes = (long) read(fd, buffer, (size_t) file_size); + if ((unsigned long) bytes != file_size) { #ifdef CONFIG_STRERROR fprintf(stderr, "Read error: %s\n", strerror(errno)); #endif -- cgit v1.2.3