shadPS4/src/core/libraries/libc/libc_stdio.cpp

78 lines
2.1 KiB
C++
Raw Normal View History

2024-02-23 22:32:32 +01:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#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"
namespace Libraries::LibC {
2023-11-06 00:11:54 +01:00
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
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);
}
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
VA_CTX(ctx);
return printf_ctx(&ctx);
}
2023-11-06 00:11:54 +01:00
int PS4_SYSV_ABI ps4_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);
} else {
VA_CTX(ctx);
char buf[256];
fprintf_ctx(&ctx, buf);
return fprintf(file, "%s", buf);
}
}
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
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);
}
} // namespace Libraries::LibC