From 5cbcd907072028d2d8b13926af8edc70d4170eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Wed, 23 Dec 2015 21:20:26 -0300 Subject: [PATCH] (retro_file.c) Get rid of uneeded error messages in retro_read_file() fseek/ftell lie about the file size in some filesystems (like sysfs) and this makes the function complain about incomplete read when the file has been fully read. --- libretro-common/file/retro_file.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libretro-common/file/retro_file.c b/libretro-common/file/retro_file.c index 73ec9608f5..2417d2ebd8 100644 --- a/libretro-common/file/retro_file.c +++ b/libretro-common/file/retro_file.c @@ -454,7 +454,10 @@ int retro_read_file(const char *path, void **buf, ssize_t *len) RFILE *file = retro_fopen(path, RFILE_MODE_READ, -1); if (!file) + { + fprintf(stderr, "%s: Failed to open %s: %s\n", __FUNCTION__, path, strerror(errno)); goto error; + } if (retro_fseek(file, 0, SEEK_END) != 0) goto error; @@ -470,11 +473,14 @@ int retro_read_file(const char *path, void **buf, ssize_t *len) if (!content_buf) goto error; - if ((ret = retro_fread(file, content_buf, content_buf_size)) < content_buf_size) - printf("Didn't read whole file: %s.\n", path); - - if (!content_buf) + ret = retro_fread(file, content_buf, content_buf_size); + if (ret < 0) + { + fprintf(stderr, "%s: Failed to read %s: %s\n", __FUNCTION__, path, strerror(errno)); goto error; + } + + retro_fclose(file); *buf = content_buf; @@ -482,16 +488,14 @@ int retro_read_file(const char *path, void **buf, ssize_t *len) * Will only work with sane character formatting (Unix). */ ((char*)content_buf)[content_buf_size] = '\0'; - if (retro_fclose(file) != 0) - printf("Failed to close file stream.\n"); - if (len) *len = ret; return 1; error: - retro_fclose(file); + if (file) + retro_fclose(file); if (content_buf) free(content_buf); if (len)