31 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
32 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
38 explicit dirent(
const wchar_t *wsFilePath) {
40 auto slen = wcslen(wsFilePath);
41 d_name =
static_cast<char*
>(malloc(slen + 1));
42 wcstombs_s(&i, d_name, slen + 1, wsFilePath, slen);
51 WIN32_FIND_DATAA FindFileData;
55 static inline bool endsWith(
const std::string &src,
const char *with) {
56 int wl =
static_cast<int>(strlen(with));
57 int so =
static_cast<int>(src.length()) - wl;
58 if (so < 0)
return false;
59 return 0 == strncmp(with, &src[so], wl);
63 explicit DIR(
const char *dirPath) : next(
nullptr) {
64 std::string ws = dirPath;
65 if (endsWith(ws,
"\\"))
69 hFind = FindFirstFileA(ws.c_str(), &FindFileData);
70 FindFileData.dwReserved0 = hFind != INVALID_HANDLE_VALUE;
74 if (!next)
delete next;
78 bool isValid()
const {
79 return (hFind != INVALID_HANDLE_VALUE && FindFileData.dwReserved0);
83 if (next !=
nullptr)
delete next;
86 if (!FindFileData.dwReserved0)
return nullptr;
91 mbstowcs_s(&outSize, wbuf, 4094, FindFileData.cFileName, 4094);
93 FindFileData.dwReserved0 = FindNextFileA(hFind, &FindFileData);
99 static DIR *opendir(
const char* dirPath) {
100 auto dp =
new DIR(dirPath);
101 if (!dp->isValid()) {
109 return dp->nextEnt();
112 static void closedir(
DIR *dp) {
Definition: w_dirent.hpp:50
Definition: w_dirent.hpp:35