From ff4eac94b48c111b31ca124e2cbb4577fef72bd8 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 2 Dec 2021 11:55:24 +0300
Subject: [PATCH] workaround MSVC and newer libmpg123 woes.
Fixes https://github.com/libsdl-org/SDL_mixer/issues/340
---
src/codecs/music_mpg123.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c
index d32734c8..43d11dc2 100644
--- a/src/codecs/music_mpg123.c
+++ b/src/codecs/music_mpg123.c
@@ -31,6 +31,11 @@
#include <stdio.h> /* For SEEK_SET */
#include <mpg123.h>
+#ifdef _MSC_VER
+typedef ptrdiff_t MIX_SSIZE_T;
+#else
+typedef ssize_t MIX_SSIZE_T;
+#endif
typedef struct {
@@ -49,7 +54,7 @@ typedef struct {
const char* (*mpg123_plain_strerror)(int errcode);
void (*mpg123_rates)(const long **list, size_t *number);
int (*mpg123_read)(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done );
- int (*mpg123_replace_reader_handle)( mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*) );
+ int (*mpg123_replace_reader_handle)( mpg123_handle *mh, MIX_SSIZE_T (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*) );
off_t (*mpg123_seek)( mpg123_handle *mh, off_t sampleoff, int whence );
off_t (*mpg123_tell)( mpg123_handle *mh);
off_t (*mpg123_length)(mpg123_handle *mh);
@@ -98,7 +103,7 @@ static int MPG123_Load(void)
FUNCTION_LOADER(mpg123_plain_strerror, const char* (*)(int errcode))
FUNCTION_LOADER(mpg123_rates, void (*)(const long **list, size_t *number))
FUNCTION_LOADER(mpg123_read, int (*)(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done ))
- FUNCTION_LOADER(mpg123_replace_reader_handle, int (*)( mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*) ))
+ FUNCTION_LOADER(mpg123_replace_reader_handle, int (*)( mpg123_handle *mh, MIX_SSIZE_T (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*) ))
FUNCTION_LOADER(mpg123_seek, off_t (*)( mpg123_handle *mh, off_t sampleoff, int whence ))
FUNCTION_LOADER(mpg123_tell, off_t (*)( mpg123_handle *mh))
FUNCTION_LOADER(mpg123_length, off_t (*)(mpg123_handle *mh))
@@ -187,9 +192,9 @@ static char const* mpg_err(mpg123_handle* mpg, int result)
}
/* we're gonna override mpg123's I/O with these wrappers for RWops */
-static ssize_t rwops_read(void* p, void* dst, size_t n)
+static MIX_SSIZE_T rwops_read(void* p, void* dst, size_t n)
{
- return (ssize_t)MP3_RWread((struct mp3file_t *)p, dst, 1, n);
+ return (MIX_SSIZE_T)MP3_RWread((struct mp3file_t *)p, dst, 1, n);
}
static off_t rwops_seek(void* p, off_t offset, int whence)