fileio hle calls

This commit is contained in:
georgemoralis 2023-11-20 08:51:18 +02:00
parent f57f668c92
commit 23ab99924f
3 changed files with 47 additions and 7 deletions

View File

@ -438,6 +438,11 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf); LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf);
LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts); LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts);
LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, ps4_fprintf); 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 // misc
LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc);

View File

@ -1,6 +1,10 @@
#include "core/hle/libraries/libc/libc_stdio.h"
#include <core/file_sys/fs.h>
#include "common/debug.h" #include "common/debug.h"
#include "common/log.h" #include "common/log.h"
#include "core/hle/libraries/libc/libc_stdio.h" #include "common/singleton.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
@ -22,12 +26,38 @@ int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
return 0; return 0;
} }
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) { int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, 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<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::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) { int PS4_SYSV_ABI ps4_fseek(FILE* stream, long int offset, int origin) { return std::fseek(stream, offset, origin); }
return std::puts(s);
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

View File

@ -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_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_puts(const char* s);
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS); 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