Chromium Code Reviews| Index: webrtc/test/testsupport/fileutils.cc |
| diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc |
| index 02ef06580bbcec4203d46ac1c23f42d4e279ebd6..463d6dea507f657a3effa71ac6da3d187f576b04 100644 |
| --- a/webrtc/test/testsupport/fileutils.cc |
| +++ b/webrtc/test/testsupport/fileutils.cc |
| @@ -24,6 +24,7 @@ |
| #include "webrtc/base/win32.h" |
| #define GET_CURRENT_DIR _getcwd |
| #else |
| +#include <dirent.h> |
| #include <unistd.h> |
| #define GET_CURRENT_DIR getcwd |
| @@ -40,6 +41,7 @@ |
| #include <memory> |
| +#include "webrtc/base/checks.h" |
| #include "webrtc/typedefs.h" // For architecture defines |
| namespace webrtc { |
| @@ -126,7 +128,7 @@ std::string WorkingDir() { |
| return kRootDirName; |
| } |
| -#else // WEBRTC_ANDROID |
| +#else // WEBRTC_ANDROID |
|
kwiberg-webrtc
2017/05/29 12:11:36
Irrelevant cleanup?
AleBzk
2017/05/29 13:04:48
Yes.
|
| std::string ProjectRootPath() { |
| #if defined(WEBRTC_IOS) |
| @@ -212,6 +214,47 @@ std::string TempFilename(const std::string &dir, const std::string &prefix) { |
| #endif |
| } |
| +bool ReadDirectory(std::string path, std::vector<std::string>* output) { |
| + RTC_DCHECK(output); |
| + if (path.length() == 0) return false; |
|
kwiberg-webrtc
2017/05/29 12:11:36
Did you git cl format?
AleBzk
2017/05/29 13:04:48
Done.
|
| + output->clear(); |
| +#if defined(WEBRTC_WIN) |
|
kwiberg-webrtc
2017/05/29 12:11:36
Please make separate functions for the win and non
AleBzk
2017/05/29 13:04:48
Done.
|
| + // Append separator character if needed. |
| + if (path.back() != '\\') path += '\\'; |
| + |
| + // Init. |
| + WIN32_FIND_DATA data; |
| + HANDLE handle = ::FindFirstFile(rtc::ToUtf16(path + '*').c_str(), &data); |
| + if (handle == INVALID_HANDLE_VALUE) return false; |
| + |
| + // Populate output. |
| + do { |
| + const std::string name = rtc::ToUtf8(data.cFileName); |
| + if (name != "." && name != "..") output->emplace_back(path + name); |
| + } while (::FindNextFile(handle, &data) == TRUE); |
| + |
| + // Release resources. |
| + if (handle != INVALID_HANDLE_VALUE) ::FindClose(handle); |
| +#else |
| + // Append separator character if needed. |
| + if (path.back() != '/') path += '/'; |
| + |
| + // Init. |
| + DIR *dir = ::opendir(path.c_str()); |
| + if (dir == nullptr) return false; |
| + |
| + // Populate output. |
| + while (struct dirent* dirent = readdir(dir)) { |
|
kwiberg-webrtc
2017/05/29 12:11:36
This is C++---there's no need to say "struct".
AleBzk
2017/05/29 13:04:48
Acknowledged.
|
| + const std::string& name = dirent->d_name; |
| + if (name != "." && name != "..") output->emplace_back(path + name); |
| + } |
| + |
| + // Release resources. |
| + closedir(dir); |
| +#endif |
| + return true; |
| +} |
| + |
| bool CreateDir(const std::string& directory_name) { |
| struct stat path_info = {0}; |
| // Check if the path exists already: |