From 647d8a966d5c96d6e9faf86b52800d361c493951 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Thu, 15 Sep 2022 17:44:41 +0100 Subject: [PATCH 1/2] sdl: don't return error when reading 0 bytes Reaching the end of the file is not an error. This is consistent with stm32/pico. --- 32blit-sdl/File.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/32blit-sdl/File.cpp b/32blit-sdl/File.cpp index 96866cdac..2b5ed9082 100644 --- a/32blit-sdl/File.cpp +++ b/32blit-sdl/File.cpp @@ -62,7 +62,7 @@ int32_t read_file(void *fh, uint32_t offset, uint32_t length, char *buffer) { if(file && SDL_RWseek(file, offset, RW_SEEK_SET) != -1) { size_t bytes_read = SDL_RWread(file, buffer, 1, length); - if(bytes_read > 0) + if(bytes_read >= 0) return (int32_t)bytes_read; } From af7a5c7ee237ecf72afac9be93b432d22d93f712 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Thu, 27 Oct 2022 18:11:14 +0100 Subject: [PATCH 2/2] sdl: check if there's an error after RWread 0 could mean EOF and not an error, clearing and then checking for an error seems to be the only way to check... --- 32blit-sdl/File.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/32blit-sdl/File.cpp b/32blit-sdl/File.cpp index 2b5ed9082..11cd9f4fb 100644 --- a/32blit-sdl/File.cpp +++ b/32blit-sdl/File.cpp @@ -60,9 +60,10 @@ int32_t read_file(void *fh, uint32_t offset, uint32_t length, char *buffer) { auto file = (SDL_RWops *)fh; if(file && SDL_RWseek(file, offset, RW_SEEK_SET) != -1) { + SDL_ClearError(); size_t bytes_read = SDL_RWread(file, buffer, 1, length); - if(bytes_read >= 0) + if(!SDL_GetError()[0]) return (int32_t)bytes_read; }