MCPcopy Create free account
hub / github.com/HexHive/NASS / ListFilesInDirRecursive

Function ListFilesInDirRecursive

fuzz/libfuzzer/FuzzerIOWindows.cpp:113–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
114 std::vector<std::string> *V, bool TopDir) {
115 auto E = GetEpoch(Dir);
116 if (Epoch)
117 if (E && *Epoch >= E) return;
118
119 std::string Path(Dir);
120 assert(!Path.empty());
121 if (Path.back() != '\\')
122 Path.push_back('\\');
123 Path.push_back('*');
124
125 // Get the first directory entry.
126 WIN32_FIND_DATAA FindInfo;
127 HANDLE FindHandle(FindFirstFileA(Path.c_str(), &FindInfo));
128 if (FindHandle == INVALID_HANDLE_VALUE)
129 {
130 if (GetLastError() == ERROR_FILE_NOT_FOUND)
131 return;
132 Printf("No such file or directory: %s; exiting\n", Dir.c_str());
133 exit(1);
134 }
135
136 do {
137 std::string FileName = DirPlusFile(Dir, FindInfo.cFileName);
138
139 if (FindInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
140 size_t FilenameLen = strlen(FindInfo.cFileName);
141 if ((FilenameLen == 1 && FindInfo.cFileName[0] == '.') ||
142 (FilenameLen == 2 && FindInfo.cFileName[0] == '.' &&
143 FindInfo.cFileName[1] == '.'))
144 continue;
145
146 ListFilesInDirRecursive(FileName, Epoch, V, false);
147 }
148 else if (IsFile(FileName, FindInfo.dwFileAttributes))
149 V->push_back(FileName);
150 } while (FindNextFileA(FindHandle, &FindInfo));
151
152 DWORD LastError = GetLastError();
153 if (LastError != ERROR_NO_MORE_FILES)
154 Printf("FindNextFileA failed (Error code: %lu).\n", LastError);
155
156 FindClose(FindHandle);
157
158 if (Epoch && TopDir)
159 *Epoch = E;
160}
161
162void IterateDirRecursive(const std::string &Dir,
163 void (*DirPreCallback)(const std::string &Dir),

Callers

nothing calls this directly

Calls 7

GetEpochFunction · 0.85
DirPlusFileFunction · 0.85
PrintfFunction · 0.70
IsFileFunction · 0.70
emptyMethod · 0.45
push_backMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected