SDL: Handle new SDL_rwops error codes in SDL_LoadFile_RW()

From 1bf1c866fe60adba0a78e2ee24d464ede9d0369d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 12 Jan 2023 06:53:07 -0800
Subject: [PATCH] Handle new SDL_rwops error codes in SDL_LoadFile_RW()

Thanks @BeWorld2018!
---
 src/file/SDL_rwops.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c
index 2ae02bf9451f..ff58f51f141e 100644
--- a/src/file/SDL_rwops.c
+++ b/src/file/SDL_rwops.c
@@ -703,10 +703,22 @@ SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
         }
 
         size_read = SDL_RWread(src, (char *)data + size_total, size - size_total);
+        if (size_read > 0) {
+            size_total += size_read;
+            continue;
+        }
         if (size_read == 0) {
+            /* End of file */
             break;
         }
-        size_total += size_read;
+        if (size_read == -2) {
+            /* Non-blocking I/O, should we wait here? */
+        }
+
+        /* Read error */
+        SDL_free(data);
+        data = NULL;
+        goto done;
     }
 
     if (datasize) {