From 49090c1ba55add4d4b0bed279efe49daaf98f0e4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 13 Nov 2023 12:22:41 +0200 Subject: [PATCH] sprintf implementation --- src/core/hle/libraries/libc/libc.cpp | 2 +- src/core/hle/libraries/libc/libc_stdio.cpp | 5 +++++ src/core/hle/libraries/libc/libc_stdio.h | 3 ++- src/core/hle/libraries/libc/printf.h | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 170bd2021..f3113ecb0 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -441,7 +441,7 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, fprintf); LIB_FUNCTION("eLdDw6l0-bU", "libc", 1, "libc", 1, 1, snprintf); - + LIB_FUNCTION("tcVi5SivF7Q", "libc", 1, "libc", 1, 1, sprintf); // misc LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); LIB_OBJ("2sWzhYqFH4E","libc", 1, "libc", 1, 1,stdout); diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index 0b86287f8..b5374ec0d 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -27,6 +27,11 @@ int PS4_SYSV_ABI snprintf(char* s, size_t n, VA_ARGS) { return snprintf_ctx(s, n, &ctx); } +int PS4_SYSV_ABI sprintf(char* s,VA_ARGS) { + VA_CTX(ctx); + return sprintf_ctx(s,&ctx); +} + int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); } diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 961328551..4e4f64ff4 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -10,4 +10,5 @@ int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg); int PS4_SYSV_ABI puts(const char* s); int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS); int PS4_SYSV_ABI snprintf(char* s, size_t n, VA_ARGS); -} // namespace Core::Libraries::LibC +int PS4_SYSV_ABI sprintf(char* s, VA_ARGS); +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/printf.h b/src/core/hle/libraries/libc/printf.h index 4a7d0089f..632138830 100644 --- a/src/core/hle/libraries/libc/printf.h +++ b/src/core/hle/libraries/libc/printf.h @@ -702,6 +702,14 @@ static int snprintf_ctx(char* s, size_t n,VaCtx* ctx) { return result; } +static int sprintf_ctx(char* s, VaCtx* ctx) { + const char* format = vaArgPtr(&ctx->va_list); + char buffer[256]; // it is big enough? + int result = _vsnprintf(_out_buffer, buffer, format, &ctx->va_list); + std::strcpy(s, buffer); + return result; +} + static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) { char buffer[n]; int result = _vsnprintf(_out_buffer, buffer, format, arg);