MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / ReadDir

Method ReadDir

src/core/unixfsservices.cpp:193–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191{
192#else
193void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector<TSTRING>& v, bool bFullPaths) const
194{
195 TSTRING strFilename = cDevicePath::AsNative(strFilenameC);
196#endif
197
198 //Get all the filenames
199 DIR* dp = 0;
200
201#if defined(O_DIRECTORY) && defined(O_NOATIME)
202 //dfd will be autoclosed by closedir(), should not be explicitly closed.
203 int dfd = open(strFilename.c_str(), O_RDONLY | O_DIRECTORY | O_NOATIME);
204 if (dfd > 0)
205 dp = fdopendir(dfd);
206#else
207 dp = opendir(strFilename.c_str());
208#endif
209
210 if (dp == NULL)
211 {
212 throw eFSServicesGeneric(strFilename, iFSServices::GetInstance()->GetErrString());
213 return;
214 }
215
216 struct dirent* d;
217
218 while ((d = readdir(dp)) != NULL)
219 {
220 if ((strcmp(d->d_name, _T(".")) != 0) && (strcmp(d->d_name, _T("..")) != 0))
221 {
222 if (bFullPaths)
223 {
224 //Create the full pathname
225 TSTRING strNewName = strFilename;
226
227 // get full path of dir entry
228 util_TrailingSep(strNewName, true);
229 strNewName += d->d_name;
230
231 // save full path name
232 v.push_back(strNewName);
233 }
234 else
235 v.push_back(d->d_name);
236 }
237 }
238
239 //Close the directory
240 closedir(dp);
241}
242
243/* needs to and with S_IFMT, check EQUALITY with S_*, and return more types
244cFSStatArgs::FileType cUnixFSServices::GetFileType(const cFCOName &filename)

Callers 2

TestReadDirFunction · 0.80
GetChildrenNamesMethod · 0.80

Calls 3

util_TrailingSepFunction · 0.85
c_strMethod · 0.80
GetErrStringMethod · 0.80

Tested by 1

TestReadDirFunction · 0.64