mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 03:24:49 +00:00
added fopen and fclose functions
This commit is contained in:
parent
a1e5fcf0c5
commit
30e9012914
3 changed files with 32 additions and 3 deletions
|
@ -36,6 +36,20 @@ std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
std::string MntPoints::getHostFile(const std::string& guest_file) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
for (auto& pair : m_mnt_pairs) {
|
||||
//horrible code but it works :D
|
||||
int find = guest_file.find(pair.guest_path);
|
||||
if (find == 0) {
|
||||
std::string npath = guest_file.substr(pair.guest_path.size(), guest_file.size()-1);
|
||||
std::replace(pair.host_path.begin(), pair.host_path.end(), '\\', '/');
|
||||
return pair.host_path + npath;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
int HandleTable::createHandle() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto* file = new File{};
|
||||
|
|
|
@ -20,6 +20,7 @@ class MntPoints {
|
|||
void unmount(const std::string& path);
|
||||
void unmountAll();
|
||||
std::string getHostDirectory(const std::string& guest_directory);
|
||||
std::string MntPoints::getHostFile(const std::string& guest_file);
|
||||
|
||||
private:
|
||||
std::vector<MntPair> m_mnt_pairs;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
|
@ -38,11 +40,23 @@ int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
|
|||
int PS4_SYSV_ABI puts(const char* s) { return std::puts(s); }
|
||||
|
||||
FILE* PS4_SYSV_ABI fopen(const char* filename, const char* mode) {
|
||||
LOG_ERROR_IF(log_file_libc, "Unimplemented fopen filename={} , mode ={}\n", filename, mode);
|
||||
return nullptr;
|
||||
LOG_ERROR_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);
|
||||
return f;
|
||||
}
|
||||
int PS4_SYSV_ABI fclose(FILE* stream) {
|
||||
LOG_ERROR_IF(log_file_libc, "Unimplemented fclose\n");
|
||||
LOG_ERROR_IF(log_file_libc, "fclose\n");
|
||||
if (stream != nullptr)
|
||||
{
|
||||
std::fclose(stream);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace Core::Libraries::LibC
|
||||
|
|
Loading…
Add table
Reference in a new issue