From fa3814ddf1512ff756f11f31d3d59e2f8e75218d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 25 Nov 2022 09:55:42 -0800
Subject: [PATCH] Removed SDL_rwops.h dependency on stdio.h
---
include/SDL_rwops.h | 23 +++++------------------
src/dynapi/SDL_dynapi_procs.h | 2 +-
src/file/SDL_rwops.c | 18 +++++++++---------
3 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h
index b8da8fcbf830..a9cc2b8783e3 100644
--- a/include/SDL_rwops.h
+++ b/include/SDL_rwops.h
@@ -112,13 +112,12 @@ typedef struct SDL_RWops
} windowsio;
#endif
-#ifdef HAVE_STDIO_H
struct
{
SDL_bool autoclose;
- FILE *fp;
+ void *fp;
} stdio;
-#endif
+
struct
{
Uint8 *base;
@@ -206,25 +205,15 @@ typedef struct SDL_RWops
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
const char *mode);
-#ifdef HAVE_STDIO_H
-
-extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
-
-#else
-
/**
* Use this function to create an SDL_RWops structure from a standard I/O file
- * pointer (stdio.h's `FILE*`).
+ * pointer (stdio.h's `FILE *`).
*
* This function is not available on Windows, since files opened in an
* application on that platform cannot be used by a dynamically linked
* library.
*
- * On some platforms, the first parameter is a `void*`, on others, it's a
- * `FILE*`, depending on what system headers are available to SDL. It is
- * always intended to be the `FILE*` type from the C runtime's stdio.h.
- *
- * \param fp the `FILE*` that feeds the SDL_RWops stream
+ * \param fp the `FILE *` that feeds the SDL_RWops stream
* \param autoclose SDL_TRUE to close the `FILE*` when closing the SDL_RWops,
* SDL_FALSE to leave the `FILE*` open when the RWops is
* closed
@@ -242,9 +231,7 @@ extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
* \sa SDL_RWtell
* \sa SDL_RWwrite
*/
-extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
- SDL_bool autoclose);
-#endif
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void *fp, SDL_bool autoclose);
/**
* Use this function to prepare a read-write memory buffer for use with
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index f4cf8aed60e2..778d8ed79f70 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -55,7 +55,7 @@ SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *
#endif
#ifdef HAVE_STDIO_H
-SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(FILE *a, SDL_bool b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
#else
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
#endif
diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c
index 9dc137948663..dfb43b596e0e 100644
--- a/src/file/SDL_rwops.c
+++ b/src/file/SDL_rwops.c
@@ -386,8 +386,8 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
}
#endif
- if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
- Sint64 pos = ftell(context->hidden.stdio.fp);
+ if (fseek((FILE *)context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
+ Sint64 pos = ftell((FILE *)context->hidden.stdio.fp);
if (pos < 0) {
return SDL_SetError("Couldn't get stream offset");
}
@@ -401,8 +401,8 @@ stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{
size_t nread;
- nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
- if (nread == 0 && ferror(context->hidden.stdio.fp)) {
+ nread = fread(ptr, size, maxnum, (FILE *)context->hidden.stdio.fp);
+ if (nread == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
SDL_Error(SDL_EFREAD);
}
return nread;
@@ -413,8 +413,8 @@ stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{
size_t nwrote;
- nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
- if (nwrote == 0 && ferror(context->hidden.stdio.fp)) {
+ nwrote = fwrite(ptr, size, num, (FILE *)context->hidden.stdio.fp);
+ if (nwrote == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
SDL_Error(SDL_EFWRITE);
}
return nwrote;
@@ -427,7 +427,7 @@ stdio_close(SDL_RWops * context)
if (context) {
if (context->hidden.stdio.autoclose) {
/* WARNING: Check the return value here! */
- if (fclose(context->hidden.stdio.fp) != 0) {
+ if (fclose((FILE *)context->hidden.stdio.fp) != 0) {
status = SDL_Error(SDL_EFWRITE);
}
}
@@ -616,7 +616,7 @@ SDL_RWFromFile(const char *file, const char *mode)
#ifdef HAVE_STDIO_H
SDL_RWops *
-SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
+SDL_RWFromFP(void *fp, SDL_bool autoclose)
{
SDL_RWops *rwops = NULL;
@@ -635,7 +635,7 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
}
#else
SDL_RWops *
-SDL_RWFromFP(void * fp, SDL_bool autoclose)
+SDL_RWFromFP(void *fp, SDL_bool autoclose)
{
SDL_SetError("SDL not compiled with stdio support");
return NULL;