diff --git a/External/FEXCore/Source/Interface/Config/Config.cpp b/External/FEXCore/Source/Interface/Config/Config.cpp index 37c7eac91..324ca219a 100644 --- a/External/FEXCore/Source/Interface/Config/Config.cpp +++ b/External/FEXCore/Source/Interface/Config/Config.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -315,7 +314,7 @@ namespace JSON { // Expand relative path to absolute char ExistsTempPath[PATH_MAX]; - char *RealPath = realpath(PathName.c_str(), ExistsTempPath); + char *RealPath = FHU::Filesystem::Absolute(PathName.c_str(), ExistsTempPath); if (RealPath) { PathName = RealPath; } diff --git a/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h b/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h index 757a7a4d2..2b0fcc570 100644 --- a/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h +++ b/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h @@ -8,7 +8,12 @@ #include #include #include +#ifndef _WIN32 +#include #include +#else +#include +#endif #include #include @@ -40,6 +45,7 @@ namespace FHU::Filesystem { * * @return Result enum depending. */ +#ifndef _WIN32 inline CreateDirectoryResult CreateDirectory(const fextl::string &Path) { auto Result = ::mkdir(Path.c_str(), 0777); if (Result == 0) { @@ -60,6 +66,19 @@ namespace FHU::Filesystem { // Couldn't create, or the path that existed wasn't a folder. return CreateDirectoryResult::ERROR; } +#else + // TODO: Should be rewritten using WIN32 specific APIs. + inline CreateDirectoryResult CreateDirectory(const fextl::string &Path) { + std::error_code ec; + if (std::filesystem::exists(Path, ec)) { + return CreateDirectoryResult::EXISTS; + } + + return std::filesystem::create_directory(Path, ec) ? + CreateDirectoryResult::CREATED : + CreateDirectoryResult::ERROR; + } +#endif /** * @brief Creates a directory tree with the provided path. @@ -152,6 +171,7 @@ namespace FHU::Filesystem { * * @return True if the copy succeeded, false otherwise. */ +#ifndef _WIN32 inline bool CopyFile(const fextl::string &From, const fextl::string &To, CopyOptions Options = CopyOptions::NONE) { const bool DestExists = Exists(To); if (Options == CopyOptions::SKIP_EXISTING && DestExists) { @@ -199,6 +219,22 @@ namespace FHU::Filesystem { return false; } +#else + // TODO: Should be rewritten using WIN32 specific APIs. + inline bool CopyFile(const fextl::string &From, const fextl::string &To, CopyOptions Options = CopyOptions::NONE) { + std::filesystem::copy_options options{}; + if (Options == CopyOptions::SKIP_EXISTING) { + options = std::filesystem::copy_options::skip_existing; + } + else if (Options == CopyOptions::OVERWRITE_EXISTING) { + options = std::filesystem::copy_options::overwrite_existing; + } + + std::error_code ec; + return std::filesystem::copy_file(From, To, options, ec); + } + +#endif /** * @brief Renames a file and overwrites if it already exists. @@ -311,4 +347,23 @@ namespace FHU::Filesystem { fmt::join(Parts, "/"), NeedsFinalSeparator ? "/" : ""); } + +#ifndef _WIN32 + inline char *Absolute(const char *Path, char Fill[PATH_MAX]) { + return realpath(Path, Fill); + } +#else + // TODO: Should be rewritten using WIN32 specific APIs. + inline char *Absolute(const char *Path, char Fill[PATH_MAX]) { + std::error_code ec; + const auto PathAbsolute = std::filesystem::absolute(Path, ec); + if (!ec) { + strncpy(Fill, PathAbsolute.string().c_str(), sizeof(*Fill)); + return Fill; + } + + return nullptr; + } +#endif + } diff --git a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h index d51e89be9..9d8dec6c3 100644 --- a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h +++ b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h @@ -1,9 +1,16 @@ #pragma once + +#include + #include #include #include #include +#ifndef _WIN32 #include +#else +#include +#endif #include #include @@ -43,6 +50,7 @@ namespace FHU::Syscalls { #define SYS_pidfd_open 434 #endif +#ifndef _WIN32 inline int32_t getcpu(uint32_t *cpu, uint32_t *node) { // Third argument is unused #if defined(HAS_SYSCALL_GETCPU) && HAS_SYSCALL_GETCPU @@ -87,5 +95,23 @@ inline int32_t renameat2(int olddirfd, const char *oldpath, int newdirfd, const inline int32_t pidfd_open(pid_t pid, unsigned int flags) { return ::syscall(SYS_pidfd_open, pid, flags); } +#else + +inline int32_t getcpu(uint32_t *cpu, uint32_t *node) { + *cpu = GetCurrentProcessorNumber(); + *node = 0; + return 0; +} + +inline int32_t tgkill(pid_t tgid, pid_t tid, int sig) { + ERROR_AND_DIE_FMT("Unsupported"); + return 0; +} + +inline int32_t gettid() { + return GetCurrentThreadId(); +} + +#endif }