From 23ab99924f4f4e60615051899c8b6eb6d174c081 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 20 Nov 2023 08:51:18 +0200 Subject: [PATCH] fileio hle calls --- src/core/hle/libraries/libc/libc.cpp | 5 +++ src/core/hle/libraries/libc/libc_stdio.cpp | 42 ++++++++++++++++++---- src/core/hle/libraries/libc/libc_stdio.h | 7 +++- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 8d2736958..719967f3b 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -438,6 +438,11 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf); LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts); LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, ps4_fprintf); + LIB_FUNCTION("xeYO4u7uyJ0", "libc", 1, "libc", 1, 1, ps4_fopen); + LIB_FUNCTION("rQFVBXp-Cxg", "libc", 1, "libc", 1, 1, ps4_fseek); + LIB_FUNCTION("Qazy8LmXTvw", "libc", 1, "libc", 1, 1, ps4_ftell); + LIB_FUNCTION("lbB+UlZqVG0", "libc", 1, "libc", 1, 1, ps4_fread); + LIB_FUNCTION("uodLYyUip20", "libc", 1, "libc", 1, 1, ps4_fclose); // misc LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index b3b5dac28..adbabb0eb 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,6 +1,10 @@ +#include "core/hle/libraries/libc/libc_stdio.h" + +#include + #include "common/debug.h" #include "common/log.h" -#include "core/hle/libraries/libc/libc_stdio.h" +#include "common/singleton.h" namespace Core::Libraries::LibC { @@ -22,12 +26,38 @@ int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) { return 0; } -int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) { - return vsnprintf_ctx(s, n, format, arg); +int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); } + +int PS4_SYSV_ABI ps4_puts(const char* s) { return std::puts(s); } + +FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) { + LOG_INFO_IF(log_file_libc, "fopen filename={} , mode ={}\n", filename, mode); + auto* h = Common::Singleton::Instance(); + auto* mnt = Common::Singleton::Instance(); + + u32 handle = h->createHandle(); + auto* file = h->getFile(handle); + file->m_guest_name = filename; + file->m_host_name = mnt->getHostFile(file->m_guest_name); + FILE* f = std::fopen(file->m_host_name.c_str(), mode); + if (!f) { + LOG_ERROR_IF(log_file_libc, "fopen can't open file={}\n", filename); + } + return f; } -int PS4_SYSV_ABI ps4_puts(const char* s) { - return std::puts(s); +int PS4_SYSV_ABI ps4_fseek(FILE* stream, long int offset, int origin) { return std::fseek(stream, offset, origin); } + +long PS4_SYSV_ABI ps4_ftell(FILE* stream) { return std::ftell(stream); } + +size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t count, FILE* stream) { return std::fread(ptr, size, count, stream); } + +int PS4_SYSV_ABI ps4_fclose(FILE* stream) { + LOG_INFO_IF(log_file_libc, "fclose\n"); + if (stream != nullptr) { + std::fclose(stream); + } + return 0; } -} // namespace Core::Libraries::LibC +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 2992d07f2..fdbbb25c9 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -9,5 +9,10 @@ int PS4_SYSV_ABI ps4_printf(VA_ARGS); int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg); int PS4_SYSV_ABI ps4_puts(const char* s); int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS); +FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode); +int PS4_SYSV_ABI ps4_fseek(FILE* stream, long int offset, int origin); +long PS4_SYSV_ABI ps4_ftell(FILE* stream); +size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t count, FILE* stream); +int PS4_SYSV_ABI ps4_fclose(FILE* stream); -} // namespace Core::Libraries::LibC +} // namespace Core::Libraries::LibC