1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
12 // Copied from linux libc sys/stat.h:
13 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
14 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
19 explicit dirent(const wchar_t *wsFilePath) {
21 auto slen = wcslen(wsFilePath);
22 d_name = static_cast<char *>(malloc(slen + 1));
23 wcstombs_s(&i, d_name, slen + 1, wsFilePath, slen);
31 WIN32_FIND_DATA FindFileData;
36 DIR(const DIR &other) = delete;
37 DIR(DIR &&other) = delete;
38 DIR& operator=(const DIR &other) = delete;
39 DIR& operator=(DIR &&other) = delete;
41 explicit DIR(const char *dirPath) : next(nullptr) {
43 // swprintf(ws, 1024, L"%hs\\*", dirPath);
44 std::string ws = dirPath;
45 if (InferenceEngine::details::endsWith(ws, "\\"))
49 hFind = FindFirstFile(ws.c_str(), &FindFileData);
50 FindFileData.dwReserved0 = hFind != INVALID_HANDLE_VALUE;
54 if (!next) delete next;
59 bool isValid() const {
60 return (hFind != INVALID_HANDLE_VALUE && FindFileData.dwReserved0);
64 if (next != nullptr) delete next;
67 if (!FindFileData.dwReserved0) return nullptr;
72 mbstowcs_s(&outSize, wbuf, 4094, FindFileData.cFileName, 4094);
73 next = new dirent(wbuf);
74 FindFileData.dwReserved0 = FindNextFile(hFind, &FindFileData);
80 static DIR* opendir(const char *dirPath) {
81 auto dp = new DIR(dirPath);
89 static struct dirent* readdir(DIR *dp) {
93 static void closedir(DIR *dp) {
98 #include <sys/types.h>