Added SDL_RWprintf() and SDL_RWvprintf() to do formatted printing to an SDL_rwops stream

Fixes https://github.com/libsdl-org/SDL/issues/2390
This commit is contained in:
Sam Lantinga committed 2023-11-04 16:46:08 -07:00
1 parent 52c4e3eab3
commit f9d11807c0
7 files changed
+133 -2

No files matched your search

+20
View File
@@ -144,6 +144,16 @@ static void SDL_InitDynamicAPI(void);
va_end(ap); \
return retval; \
} \
_static size_t SDLCALL SDL_RWprintf##name(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \
{ \
size_t retval; \
va_list ap; \
initcall; \
va_start(ap, fmt); \
retval = jump_table.SDL_RWvprintf(context, fmt, ap); \
va_end(ap); \
return retval; \
} \
_static void SDLCALL SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \
{ \
va_list ap; \
@@ -285,6 +295,16 @@ static int SDLCALL SDL_swprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) wchar_t *buf,
va_end(ap);
return retval;
}
_static size_t SDLCALL SDL_RWprintf_LOGSDLCALLS(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
size_t retval;
va_list ap;
SDL_Log_REAL("SDL3CALL SDL_RWprintf");
va_start(ap, fmt);
retval = SDL_RWvprintf_REAL(context, fmt, ap);
va_end(ap);
return retval;
}
static void SDLCALL SDL_Log_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
+2
View File
@@ -922,6 +922,8 @@ SDL3_0.0.0 {
SDL_ClearProperty;
SDL_EnterAppMainCallbacks;
SDL_CleanupEvent;
SDL_RWprintf;
SDL_RWvprintf;
# extra symbols go here (don't modify this line)
local: *;
};
+2
View File
@@ -947,3 +947,5 @@
#define SDL_ClearProperty SDL_ClearProperty_REAL
#define SDL_EnterAppMainCallbacks SDL_EnterAppMainCallbacks_REAL
#define SDL_CleanupEvent SDL_CleanupEvent_REAL
#define SDL_RWprintf SDL_RWprintf_REAL
#define SDL_RWvprintf SDL_RWvprintf_REAL
+2
View File
@@ -43,6 +43,7 @@ SDL_DYNAPI_PROC(int,SDL_asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char
SDL_DYNAPI_PROC(int,SDL_snprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_swprintf,(SDL_OUT_Z_CAP(b) wchar_t *a, size_t b, SDL_PRINTF_FORMAT_STRING const wchar_t *c, ...),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return)
SDL_DYNAPI_PROC(size_t,SDL_RWprintf,(SDL_RWops *a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),return)
#endif
#ifdef SDL_CreateThread
@@ -979,3 +980,4 @@ SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetWindowProperties,(SDL_Window *a),(a),ret
SDL_DYNAPI_PROC(int,SDL_ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_EnterAppMainCallbacks,(int a, char *b[], SDL_AppInit_func c, SDL_AppIterate_func d, SDL_AppEvent_func e, SDL_AppQuit_func f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(void,SDL_CleanupEvent,(SDL_Event *a),(a),)
SDL_DYNAPI_PROC(size_t,SDL_RWvprintf,(SDL_RWops *a, const char *b, va_list c),(a,b,c),return)
+29
View File
@@ -808,6 +808,35 @@ size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size)
return bytes;
}
size_t SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int size;
char *string = NULL;
size_t bytes;
va_start(ap, fmt);
size = SDL_vasprintf(&string, fmt, ap);
va_end(ap);
bytes = SDL_RWwrite(context, string, size);
SDL_free(string);
return bytes;
}
size_t SDL_RWvprintf(SDL_RWops *context, const char *fmt, va_list ap)
{
int size;
char *string = NULL;
size_t bytes;
size = SDL_vasprintf(&string, fmt, ap);
bytes = SDL_RWwrite(context, string, size);
SDL_free(string);
return bytes;
}
int SDL_RWclose(SDL_RWops *context)
{
if (!context) {