SDL_mixer: music_mpg123.c: properly return error from read callback

From 49d2e332c54b39e4b5593dfb52b7dc6ac214c7b1 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 30 Aug 2023 01:10:32 +0300
Subject: [PATCH] music_mpg123.c: properly return error from read callback

mpg123 expects POSIX read(2) behavior
---
 src/codecs/music_mpg123.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c
index a2f18a78..e7bb02e8 100644
--- a/src/codecs/music_mpg123.c
+++ b/src/codecs/music_mpg123.c
@@ -197,7 +197,12 @@ static char const* mpg_err(mpg123_handle* mpg, int result)
 /* we're gonna override mpg123's I/O with these wrappers for RWops */
 static MIX_SSIZE_T rwops_read(void* p, void* dst, size_t n)
 {
-    return (MIX_SSIZE_T)MP3_RWread((struct mp3file_t *)p, dst, 1, n);
+    struct mp3file_t *mp3file = (struct mp3file_t *)p;
+    MIX_SSIZE_T r = (MIX_SSIZE_T)MP3_RWread(mp3file, dst, 1, n);
+    if (!r && mp3file->src->status != SDL_RWOPS_STATUS_EOF) {
+        return -1;
+    }
+    return r < 0 ? -1 : r;
 }
 
 static off_t rwops_seek(void* p, off_t offset, int whence)