From eefe4db0186940474ee3a5cb37f3d176f7f400c7 Mon Sep 17 00:00:00 2001 From: MarcZX100 Date: Mon, 12 Oct 2026 22:56:17 +0000 Subject: [PATCH] fix(libc): return native fopen errors --- core/libs/prx/libc/src/FileAndHeap.cpp | 22 ++-------------------- core/libs/tests/FileStreams.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/core/libs/prx/libc/src/FileAndHeap.cpp b/core/libs/prx/libc/src/FileAndHeap.cpp index ef219f06b..1c14681ec 100644 --- a/core/libs/prx/libc/src/FileAndHeap.cpp +++ b/core/libs/prx/libc/src/FileAndHeap.cpp @@ -274,29 +274,11 @@ FileStream* APS5_VABI fopen_nid_postfix(const char* filename, const char* mode) } std::filesystem::path fpath; if (const int error = ResolvePathError_nid_no_patch(filename, fpath)) { errno = error; return nullptr; } - const auto abs_path = fpath.string(); std::unique_ptr handle(OpenNative(fpath, parsed->native), std::fclose); if (!handle) { const int error = errno; - if (error == ENOENT || (parsed->exclusive && error == EEXIST)) { - errno = error; - return nullptr; - } - const auto reason = std::strerror(error); - std::error_code ec; - std::filesystem::path sibling; - for (const auto& entry : std::filesystem::directory_iterator(fpath.parent_path(), ec)) { - if (ec) break; - if (entry.path().stem() == fpath.stem() && entry.path().extension() != fpath.extension()) { - sibling = std::filesystem::absolute(entry.path()); - break; - } - } - if (!sibling.empty()) { - // APS5_LOG_OUT("%s: \"%s\": %s. Sibling: \"%s\"", FOPEN_MSG_NOT_FOUND, abs_path.c_str(), reason, sibling.filename().string().c_str()); - return nullptr; - } - throw std::runtime_error(std::string(__func__) + ": " + FOPEN_MSG_OPEN_FAILED + ": \"" + abs_path + "\": " + reason); + errno = error; + return nullptr; } // APS5_LOG_OUT("success: \"%s\"", abs_path.c_str()); if (parsed->append) static_cast(std::fseek(handle.get(), 0, SEEK_END)); diff --git a/core/libs/tests/FileStreams.cpp b/core/libs/tests/FileStreams.cpp index d0431836b..60a760f1c 100644 --- a/core/libs/tests/FileStreams.cpp +++ b/core/libs/tests/FileStreams.cpp @@ -75,6 +75,19 @@ int main(int argc, char** argv) { errno = 0; Require(fopen_nid_postfix(argv[1], "rb") == nullptr); Require(errno == ENOENT); +#ifdef _WIN32 + const std::string directoryMode = "rb"; + constexpr int directoryError = EACCES; +#else + const std::string directoryMode = "wb"; + constexpr int directoryError = EISDIR; +#endif + const std::string directoryName = std::string(argv[1]) + ".dir"; + Require(std::filesystem::create_directory(directoryName)); + errno = 0; + Require(fopen_nid_postfix(directoryName.c_str(), directoryMode.c_str()) == nullptr); + Require(errno == directoryError); + Require(std::filesystem::remove(directoryName)); const std::u8string unicodeName = u8"セーブé.tmp"; const std::string guestName(unicodeName.begin(), unicodeName.end()); const std::filesystem::path hostName(unicodeName);