diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/OSUtils.cpp | 15 | ||||
-rw-r--r-- | osdep/OSUtils.hpp | 11 |
2 files changed, 10 insertions, 16 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 1fa2f8b0..60e6d6ba 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -75,38 +75,35 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath) } #endif // __UNIX_LIKE__ -std::map<std::string,bool> OSUtils::listDirectory(const char *path) +std::vector<std::string> OSUtils::listDirectory(const char *path) { - std::map<std::string,bool> r; + std::vector<std::string> r; #ifdef __WINDOWS__ HANDLE hFind; WIN32_FIND_DATAA ffd; if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { do { - if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))) - r[std::string(ffd.cFileName)] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); + if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) + r.push_back(std::string(ffd.cFileName)); } while (FindNextFileA(hFind,&ffd)); FindClose(hFind); } #else struct dirent de; struct dirent *dptr; - DIR *d = opendir(path); if (!d) return r; - dptr = (struct dirent *)0; for(;;) { if (readdir_r(d,&de,&dptr)) break; if (dptr) { - if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))) - r[std::string(dptr->d_name)] = (dptr->d_type == DT_DIR); + if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type != DT_DIR)) + r.push_back(std::string(dptr->d_name)); } else break; } - closedir(d); #endif diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp index a0cb1067..142f0aed 100644 --- a/osdep/OSUtils.hpp +++ b/osdep/OSUtils.hpp @@ -103,16 +103,13 @@ public: /** * List a directory's contents - * - * Keys in returned map are filenames only and don't include the leading - * path. Pseudo-paths like . and .. are not returned. Values are true if - * the item is a directory, false if it's a file. More detailed attributes - * aren't supported since the code that uses this doesn't need them. + * + * This returns only files, not sub-directories. * * @param path Path to list - * @return Map of entries and whether or not they are also directories (empty on failure) + * @return Names of files in directory */ - static std::map<std::string,bool> listDirectory(const char *path); + static std::vector<std::string> listDirectory(const char *path); /** * Set modes on a file to something secure |