mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 16:43:05 -05:00
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>
22 lines
887 B
C++
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));
|
|
}
|