From c126925dd974df84747bf8af10262987b590a15d Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 1 Nov 2023 13:02:39 +0200 Subject: [PATCH] libc fprintf implementation for stdout,stderr case (needed from undertale) --- src/core/hle/libraries/libc/libc.cpp | 3 +++ src/core/hle/libraries/libc/libc_stdio.cpp | 15 +++++++++++++++ src/core/hle/libraries/libc/libc_stdio.h | 1 + 3 files changed, 19 insertions(+) diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 6074f2c6..ce7d9bc9 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -109,9 +109,12 @@ void libcSymbolsRegister(SymbolsResolver* sym) { LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, printf); LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, vsnprintf); LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); + LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, fprintf); // misc LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); + LIB_OBJ("2sWzhYqFH4E","libc", 1, "libc", 1, 1,stdout); + LIB_OBJ("H8AprKeZtNg", "libc", 1, "libc", 1, 1, stderr); LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index f4039574..f82a0ca3 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,10 +1,25 @@ #include "libc_stdio.h" +#include +#include + namespace Core::Libraries::LibC { +constexpr bool log_file_libc = true; // disable it to disable logging + int PS4_SYSV_ABI printf(VA_ARGS) { VA_CTX(ctx); return printf_ctx(&ctx); } +int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) { + int fd = _fileno(file); + if (fd == 1 || fd == 2) { // output stdout and stderr to console + VA_CTX(ctx); + return printf_ctx(&ctx); + } + LOG_ERROR_IF(log_file_libc, "libc:Unimplemented fprintf case\n"); + BREAKPOINT(); + return 0; +} 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 36d1991d..0546a7bc 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -8,4 +8,5 @@ namespace Core::Libraries::LibC { int PS4_SYSV_ABI printf(VA_ARGS); 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); } // namespace Core::Libraries::LibC \ No newline at end of file