OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/test/testsupport/fileutils.h" | 11 #include "webrtc/test/testsupport/fileutils.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #ifdef WIN32 | 15 #ifdef WIN32 |
16 #include <direct.h> | 16 #include <direct.h> |
17 #include <tchar.h> | 17 #include <tchar.h> |
18 #include <windows.h> | 18 #include <windows.h> |
19 #include <algorithm> | 19 #include <algorithm> |
20 | 20 |
21 #include "Shlwapi.h" | 21 #include "Shlwapi.h" |
22 #include "WinDef.h" | 22 #include "WinDef.h" |
23 | 23 |
24 #include "webrtc/base/win32.h" | 24 #include "webrtc/base/win32.h" |
25 #define GET_CURRENT_DIR _getcwd | 25 #define GET_CURRENT_DIR _getcwd |
26 #else | 26 #else |
27 #include <dirent.h> | |
27 #include <unistd.h> | 28 #include <unistd.h> |
28 | 29 |
29 #define GET_CURRENT_DIR getcwd | 30 #define GET_CURRENT_DIR getcwd |
30 #endif | 31 #endif |
31 | 32 |
32 #include <sys/stat.h> // To check for directory existence. | 33 #include <sys/stat.h> // To check for directory existence. |
33 #ifndef S_ISDIR // Not defined in stat.h on Windows. | 34 #ifndef S_ISDIR // Not defined in stat.h on Windows. |
34 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | 35 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) |
35 #endif | 36 #endif |
36 | 37 |
37 #include <stdio.h> | 38 #include <stdio.h> |
38 #include <stdlib.h> | 39 #include <stdlib.h> |
39 #include <string.h> | 40 #include <string.h> |
40 | 41 |
41 #include <memory> | 42 #include <memory> |
42 | 43 |
44 #include "webrtc/base/checks.h" | |
43 #include "webrtc/typedefs.h" // For architecture defines | 45 #include "webrtc/typedefs.h" // For architecture defines |
44 | 46 |
45 namespace webrtc { | 47 namespace webrtc { |
46 namespace test { | 48 namespace test { |
47 | 49 |
48 #if defined(WEBRTC_IOS) | 50 #if defined(WEBRTC_IOS) |
49 // Defined in iosfileutils.mm. No header file to discourage use elsewhere. | 51 // Defined in iosfileutils.mm. No header file to discourage use elsewhere. |
50 std::string IOSOutputPath(); | 52 std::string IOSOutputPath(); |
51 std::string IOSRootPath(); | 53 std::string IOSRootPath(); |
52 std::string IOSResourcePath(std::string name, std::string extension); | 54 std::string IOSResourcePath(std::string name, std::string extension); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 121 } |
120 | 122 |
121 std::string OutputPath() { | 123 std::string OutputPath() { |
122 return kRootDirName; | 124 return kRootDirName; |
123 } | 125 } |
124 | 126 |
125 std::string WorkingDir() { | 127 std::string WorkingDir() { |
126 return kRootDirName; | 128 return kRootDirName; |
127 } | 129 } |
128 | 130 |
129 #else // WEBRTC_ANDROID | 131 #else // WEBRTC_ANDROID |
kwiberg-webrtc
2017/05/29 12:11:36
Irrelevant cleanup?
AleBzk
2017/05/29 13:04:48
Yes.
| |
130 | 132 |
131 std::string ProjectRootPath() { | 133 std::string ProjectRootPath() { |
132 #if defined(WEBRTC_IOS) | 134 #if defined(WEBRTC_IOS) |
133 return IOSRootPath(); | 135 return IOSRootPath(); |
134 #else | 136 #else |
135 std::string path = WorkingDir(); | 137 std::string path = WorkingDir(); |
136 if (path == kFallbackPath) { | 138 if (path == kFallbackPath) { |
137 return kCannotFindProjectRootDir; | 139 return kCannotFindProjectRootDir; |
138 } | 140 } |
139 if (relative_dir_path_set) { | 141 if (relative_dir_path_set) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 assert(false); | 207 assert(false); |
206 return ""; | 208 return ""; |
207 } else { | 209 } else { |
208 ::close(fd); | 210 ::close(fd); |
209 } | 211 } |
210 std::string ret(tempname.get()); | 212 std::string ret(tempname.get()); |
211 return ret; | 213 return ret; |
212 #endif | 214 #endif |
213 } | 215 } |
214 | 216 |
217 bool ReadDirectory(std::string path, std::vector<std::string>* output) { | |
218 RTC_DCHECK(output); | |
219 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.
| |
220 output->clear(); | |
221 #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.
| |
222 // Append separator character if needed. | |
223 if (path.back() != '\\') path += '\\'; | |
224 | |
225 // Init. | |
226 WIN32_FIND_DATA data; | |
227 HANDLE handle = ::FindFirstFile(rtc::ToUtf16(path + '*').c_str(), &data); | |
228 if (handle == INVALID_HANDLE_VALUE) return false; | |
229 | |
230 // Populate output. | |
231 do { | |
232 const std::string name = rtc::ToUtf8(data.cFileName); | |
233 if (name != "." && name != "..") output->emplace_back(path + name); | |
234 } while (::FindNextFile(handle, &data) == TRUE); | |
235 | |
236 // Release resources. | |
237 if (handle != INVALID_HANDLE_VALUE) ::FindClose(handle); | |
238 #else | |
239 // Append separator character if needed. | |
240 if (path.back() != '/') path += '/'; | |
241 | |
242 // Init. | |
243 DIR *dir = ::opendir(path.c_str()); | |
244 if (dir == nullptr) return false; | |
245 | |
246 // Populate output. | |
247 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.
| |
248 const std::string& name = dirent->d_name; | |
249 if (name != "." && name != "..") output->emplace_back(path + name); | |
250 } | |
251 | |
252 // Release resources. | |
253 closedir(dir); | |
254 #endif | |
255 return true; | |
256 } | |
257 | |
215 bool CreateDir(const std::string& directory_name) { | 258 bool CreateDir(const std::string& directory_name) { |
216 struct stat path_info = {0}; | 259 struct stat path_info = {0}; |
217 // Check if the path exists already: | 260 // Check if the path exists already: |
218 if (stat(directory_name.c_str(), &path_info) == 0) { | 261 if (stat(directory_name.c_str(), &path_info) == 0) { |
219 if (!S_ISDIR(path_info.st_mode)) { | 262 if (!S_ISDIR(path_info.st_mode)) { |
220 fprintf(stderr, "Path %s exists but is not a directory! Remove this " | 263 fprintf(stderr, "Path %s exists but is not a directory! Remove this " |
221 "file and re-run to create the directory.\n", | 264 "file and re-run to create the directory.\n", |
222 directory_name.c_str()); | 265 directory_name.c_str()); |
223 return false; | 266 return false; |
224 } | 267 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 if (fseek(f, 0, SEEK_END) == 0) { | 343 if (fseek(f, 0, SEEK_END) == 0) { |
301 size = ftell(f); | 344 size = ftell(f); |
302 } | 345 } |
303 fclose(f); | 346 fclose(f); |
304 } | 347 } |
305 return size; | 348 return size; |
306 } | 349 } |
307 | 350 |
308 } // namespace test | 351 } // namespace test |
309 } // namespace webrtc | 352 } // namespace webrtc |
OLD | NEW |