2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/singleton.h"
|
|
|
|
#include "core/file_sys/fs.h"
|
2024-04-13 23:35:48 +02:00
|
|
|
#include "core/libraries/libc/libc_stdio.h"
|
2023-11-01 12:02:39 +01:00
|
|
|
|
2024-04-14 16:09:51 +02:00
|
|
|
namespace Libraries::LibC {
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
|
|
|
|
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
2024-03-14 13:18:16 +01:00
|
|
|
FILE* f = std::fopen(mnt->GetHostFile(filename).c_str(), mode);
|
|
|
|
if (f != nullptr) {
|
|
|
|
LOG_INFO(Lib_LibC, "fopen = {}", mnt->GetHostFile(filename).c_str());
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Lib_LibC, "fopen can't open = {}", mnt->GetHostFile(filename).c_str());
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI ps4_fclose(FILE* stream) {
|
|
|
|
LOG_INFO(Lib_LibC, "callled");
|
|
|
|
int ret = 0;
|
|
|
|
if (stream != nullptr) {
|
|
|
|
ret = fclose(stream);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI ps4_setvbuf(FILE* stream, char* buf, int mode, size_t size) {
|
|
|
|
return setvbuf(stream, buf, mode, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI ps4_fseek(FILE* stream, long offset, int whence) {
|
|
|
|
return fseek(stream, offset, whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI ps4_fgetpos(FILE* stream, fpos_t* pos) {
|
|
|
|
return fgetpos(stream, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t nmemb, FILE* stream) {
|
|
|
|
return fread(ptr, size, nmemb, stream);
|
2024-02-27 23:10:34 +01:00
|
|
|
}
|
2023-11-01 12:02:39 +01:00
|
|
|
|
2023-11-16 08:13:50 +01:00
|
|
|
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
|
2023-10-31 14:53:46 +01:00
|
|
|
VA_CTX(ctx);
|
|
|
|
return printf_ctx(&ctx);
|
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2023-11-16 08:13:50 +01:00
|
|
|
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
|
2024-02-14 23:52:57 +01:00
|
|
|
int fd = fileno(file);
|
2024-02-23 21:57:57 +01:00
|
|
|
if (fd == 1 || fd == 2) { // output stdout and stderr to console
|
2023-11-01 12:02:39 +01:00
|
|
|
VA_CTX(ctx);
|
|
|
|
return printf_ctx(&ctx);
|
2024-03-14 13:18:16 +01:00
|
|
|
} else {
|
|
|
|
VA_CTX(ctx);
|
|
|
|
char buf[256];
|
|
|
|
fprintf_ctx(&ctx, buf);
|
|
|
|
return fprintf(file, "%s", buf);
|
2023-11-01 12:02:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-31 14:53:46 +01:00
|
|
|
|
2023-11-16 08:13:50 +01:00
|
|
|
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
|
2023-11-06 00:11:54 +01:00
|
|
|
return vsnprintf_ctx(s, n, format, arg);
|
|
|
|
}
|
2023-10-31 18:08:33 +01:00
|
|
|
|
2023-11-16 08:13:50 +01:00
|
|
|
int PS4_SYSV_ABI ps4_puts(const char* s) {
|
2023-11-06 00:11:54 +01:00
|
|
|
return std::puts(s);
|
|
|
|
}
|
2023-10-31 18:08:33 +01:00
|
|
|
|
2024-05-07 15:25:58 +02:00
|
|
|
long PS4_SYSV_ABI ps4_ftell(FILE* stream) {
|
|
|
|
return ftell(stream);
|
|
|
|
}
|
|
|
|
|
2024-04-14 16:09:51 +02:00
|
|
|
} // namespace Libraries::LibC
|