Files
AnyPS5/core/libs/prx/libSceLibcInternal/Directory.cpp
T
xXPBSXxandClaude Sonnet 5.5 7535eb45fc fix(libSceLibcInternal): start fdopendir at the descriptor position and set FD_CLOEXEC
fdopendir listed the directory from its first entry whatever position the
descriptor had, and left FD_CLOEXEC unchanged. FreeBSD 11.4 fdopendir sets
FD_CLOEXEC on the descriptor and preserves the initial seek position (lib/libc/gen/opendir.c).
The Windows directory handle now skips the entries the descriptor already
consumed, the Linux handle duplicates the descriptor, and the test requires both.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 03:11:14 +02:00

22 lines
887 B
C++

#include "prx/libc/include/GuestDirectory.hpp"
#include "prx/libkernel/File/include/DirectoryDescriptor.hpp"
#include <cerrno>
#include <cstdint>
extern "C" int APS5_VABI close_nid_postfix(int d);
extern "C" int APS5_VABI fcntl_nid_postfix(int descriptor, int command, ...);
extern "C" int* APS5_VABI __error_nid_postfix();
extern "C" void* APS5_VABI fdopendir_nid_postfix(int fd) {
constexpr int SetDescriptorFlags = 2;
constexpr int CloseOnExec = 1;
if (fcntl_nid_postfix(fd, SetDescriptorFlags, CloseOnExec) == -1) return nullptr;
int error = 0;
const char* path = GetDirectoryDescriptorPath_nid_no_patch(fd, &error);
if (path == nullptr) {
*__error_nid_postfix() = error == EBADF ? 9 : 20;
return nullptr;
}
return OpenDescriptorDirectory_nid_no_patch(path, fd, close_nid_postfix, GetDirectoryDescriptorPosition_nid_no_patch(fd));
}