27 HANDLE searchHandle{INVALID_HANDLE_VALUE};
29 char currentName[MAX_PATH * 3];
33 return FindClose(searchHandle) ? 0 : -1;
37 wchar_t patternBuf[MAX_PATH + 3];
40 if (pattern.empty()) {
44 if (mbstowcs_s(&len, patternBuf, MAX_PATH, pattern.c_str(), MAX_PATH - 2)) {
52 if (len && patternBuf[len - 1] !=
'/' && patternBuf[len - 1] !=
'\\') {
53 patternBuf[len++] =
'\\';
55 patternBuf[len++] =
'*';
58 WIN32_FIND_DATAW fdata;
59 HANDLE
h = FindFirstFileW(patternBuf, &fdata);
60 if (h == INVALID_HANDLE_VALUE) {
65 dir.d_name = currentName;
66 if (wcstombs(currentName, fdata.cFileName, MAX_PATH * 3) == (
size_t)-1) {
70 setEntryType(fdata.dwFileAttributes);
76 WIN32_FIND_DATAW fdata;
77 if (!FindNextFileW(searchHandle, &fdata)) {
81 if (wcstombs(currentName, fdata.cFileName, MAX_PATH * 3) == (
size_t)-1) {
85 setEntryType(fdata.dwFileAttributes);
93 void setEntryType(DWORD attr) {
94 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
103 int closedir(DIR* dir) {
104 auto ret = dir->close();
109 DIR* opendir(
const char*
name) {
110 auto dir =
new DIR();
119 dirent* readdir(DIR* dir) {
120 return dir->nextDir();
123 int readdir_r(DIR* dir, dirent* buf, dirent** ent) {
124 if (!dir || !buf || !ent) {
127 *ent = dir->nextDir();
137 void rewinddir(DIR* dir) {
int close(NetworkSocket s)