Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: webrtc/test/testsupport/fileutils.cc

Issue 2685583009: Make functions in fileutils.h use "const std::string&". (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/testsupport/fileutils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 #ifdef WIN32 94 #ifdef WIN32
95 std::replace(temp_path.begin(), temp_path.end(), '/', '\\'); 95 std::replace(temp_path.begin(), temp_path.end(), '/', '\\');
96 #endif 96 #endif
97 97
98 // Trim away the executable name; only store the relative dir path. 98 // Trim away the executable name; only store the relative dir path.
99 temp_path = temp_path.substr(0, temp_path.find_last_of(kPathDelimiter)); 99 temp_path = temp_path.substr(0, temp_path.find_last_of(kPathDelimiter));
100 strncpy(relative_dir_path, temp_path.c_str(), FILENAME_MAX); 100 strncpy(relative_dir_path, temp_path.c_str(), FILENAME_MAX);
101 relative_dir_path_set = true; 101 relative_dir_path_set = true;
102 } 102 }
103 103
104 bool FileExists(std::string& file_name) { 104 bool FileExists(const std::string& file_name) {
105 struct stat file_info = {0}; 105 struct stat file_info = {0};
106 return stat(file_name.c_str(), &file_info) == 0; 106 return stat(file_name.c_str(), &file_info) == 0;
107 } 107 }
108 108
109 #ifdef WEBRTC_ANDROID 109 #ifdef WEBRTC_ANDROID
110 110
111 std::string ProjectRootPath() { 111 std::string ProjectRootPath() {
112 return kRootDirName; 112 return kRootDirName;
113 } 113 }
114 114
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 assert(false); 199 assert(false);
200 return ""; 200 return "";
201 } else { 201 } else {
202 ::close(fd); 202 ::close(fd);
203 } 203 }
204 std::string ret(tempname.get()); 204 std::string ret(tempname.get());
205 return ret; 205 return ret;
206 #endif 206 #endif
207 } 207 }
208 208
209 bool CreateDir(std::string directory_name) { 209 bool CreateDir(const std::string& directory_name) {
210 struct stat path_info = {0}; 210 struct stat path_info = {0};
211 // Check if the path exists already: 211 // Check if the path exists already:
212 if (stat(directory_name.c_str(), &path_info) == 0) { 212 if (stat(directory_name.c_str(), &path_info) == 0) {
213 if (!S_ISDIR(path_info.st_mode)) { 213 if (!S_ISDIR(path_info.st_mode)) {
214 fprintf(stderr, "Path %s exists but is not a directory! Remove this " 214 fprintf(stderr, "Path %s exists but is not a directory! Remove this "
215 "file and re-run to create the directory.\n", 215 "file and re-run to create the directory.\n",
216 directory_name.c_str()); 216 directory_name.c_str());
217 return false; 217 return false;
218 } 218 }
219 } else { 219 } else {
220 #ifdef WIN32 220 #ifdef WIN32
221 return _mkdir(directory_name.c_str()) == 0; 221 return _mkdir(directory_name.c_str()) == 0;
222 #else 222 #else
223 return mkdir(directory_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == 0; 223 return mkdir(directory_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == 0;
224 #endif 224 #endif
225 } 225 }
226 return true; 226 return true;
227 } 227 }
228 228
229 std::string ResourcePath(std::string name, std::string extension) { 229 std::string ResourcePath(const std::string& name,
230 const std::string& extension) {
230 #if defined(WEBRTC_IOS) 231 #if defined(WEBRTC_IOS)
231 return IOSResourcePath(name, extension); 232 return IOSResourcePath(name, extension);
232 #else 233 #else
233 std::string platform = "win"; 234 std::string platform = "win";
234 #ifdef WEBRTC_LINUX 235 #ifdef WEBRTC_LINUX
235 platform = "linux"; 236 platform = "linux";
236 #endif // WEBRTC_LINUX 237 #endif // WEBRTC_LINUX
237 #ifdef WEBRTC_MAC 238 #ifdef WEBRTC_MAC
238 platform = "mac"; 239 platform = "mac";
239 #endif // WEBRTC_MAC 240 #endif // WEBRTC_MAC
(...skipping 23 matching lines...) Expand all
263 resource_file = resources_path + name + "_" + architecture + "." + extension; 264 resource_file = resources_path + name + "_" + architecture + "." + extension;
264 if (FileExists(resource_file)) { 265 if (FileExists(resource_file)) {
265 return resource_file; 266 return resource_file;
266 } 267 }
267 268
268 // Fall back on name without architecture or platform. 269 // Fall back on name without architecture or platform.
269 return resources_path + name + "." + extension; 270 return resources_path + name + "." + extension;
270 #endif // defined (WEBRTC_IOS) 271 #endif // defined (WEBRTC_IOS)
271 } 272 }
272 273
273 size_t GetFileSize(std::string filename) { 274 size_t GetFileSize(const std::string& filename) {
274 FILE* f = fopen(filename.c_str(), "rb"); 275 FILE* f = fopen(filename.c_str(), "rb");
275 size_t size = 0; 276 size_t size = 0;
276 if (f != NULL) { 277 if (f != NULL) {
277 if (fseek(f, 0, SEEK_END) == 0) { 278 if (fseek(f, 0, SEEK_END) == 0) {
278 size = ftell(f); 279 size = ftell(f);
279 } 280 }
280 fclose(f); 281 fclose(f);
281 } 282 }
282 return size; 283 return size;
283 } 284 }
284 285
285 } // namespace test 286 } // namespace test
286 } // namespace webrtc 287 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/testsupport/fileutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698