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

Side by Side Diff: webrtc/base/unixfilesystem.cc

Issue 1405023016: Convert usage of ARRAY_SIZE to arraysize. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: static_cast<int> Created 5 years, 1 month 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/base/testutils.h ('k') | webrtc/base/urlencode_unittest.cc » ('j') | 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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 26 matching lines...) Expand all
37 37
38 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 38 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
39 #include <ctype.h> 39 #include <ctype.h>
40 #include <algorithm> 40 #include <algorithm>
41 #endif 41 #endif
42 42
43 #if defined(__native_client__) && !defined(__GLIBC__) 43 #if defined(__native_client__) && !defined(__GLIBC__)
44 #include <sys/syslimits.h> 44 #include <sys/syslimits.h>
45 #endif 45 #endif
46 46
47 #include "webrtc/base/arraysize.h"
47 #include "webrtc/base/fileutils.h" 48 #include "webrtc/base/fileutils.h"
48 #include "webrtc/base/pathutils.h" 49 #include "webrtc/base/pathutils.h"
49 #include "webrtc/base/stream.h" 50 #include "webrtc/base/stream.h"
50 #include "webrtc/base/stringutils.h" 51 #include "webrtc/base/stringutils.h"
51 52
52 #if defined(WEBRTC_IOS) 53 #if defined(WEBRTC_IOS)
53 // Defined in iosfilesystem.mm. No header file to discourage use 54 // Defined in iosfilesystem.mm. No header file to discourage use
54 // elsewhere; other places should use GetApp{Data,Temp}Folder() in 55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in
55 // this file. Don't copy/paste. I mean it. 56 // this file. Don't copy/paste. I mean it.
56 char* IOSDataDirectory(); 57 char* IOSDataDirectory();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 170 }
170 171
171 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, 172 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create,
172 const std::string *append) { 173 const std::string *append) {
173 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 174 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
174 FSRef fr; 175 FSRef fr;
175 if (0 != FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType, 176 if (0 != FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType,
176 kCreateFolder, &fr)) 177 kCreateFolder, &fr))
177 return false; 178 return false;
178 unsigned char buffer[NAME_MAX+1]; 179 unsigned char buffer[NAME_MAX+1];
179 if (0 != FSRefMakePath(&fr, buffer, ARRAY_SIZE(buffer))) 180 if (0 != FSRefMakePath(&fr, buffer, arraysize(buffer)))
180 return false; 181 return false;
181 pathname.SetPathname(reinterpret_cast<char*>(buffer), ""); 182 pathname.SetPathname(reinterpret_cast<char*>(buffer), "");
182 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 183 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
183 ASSERT(provided_app_temp_folder_ != NULL); 184 ASSERT(provided_app_temp_folder_ != NULL);
184 pathname.SetPathname(provided_app_temp_folder_, ""); 185 pathname.SetPathname(provided_app_temp_folder_, "");
185 #else // !WEBRTC_MAC || WEBRTC_IOS && !WEBRTC_ANDROID 186 #else // !WEBRTC_MAC || WEBRTC_IOS && !WEBRTC_ANDROID
186 if (const char* tmpdir = getenv("TMPDIR")) { 187 if (const char* tmpdir = getenv("TMPDIR")) {
187 pathname.SetPathname(tmpdir, ""); 188 pathname.SetPathname(tmpdir, "");
188 } else if (const char* tmp = getenv("TMP")) { 189 } else if (const char* tmp = getenv("TMP")) {
189 pathname.SetPathname(tmp, ""); 190 pathname.SetPathname(tmp, "");
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 const char* const kTempPrefixes[] = { 297 const char* const kTempPrefixes[] = {
297 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 298 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
298 provided_app_temp_folder_, 299 provided_app_temp_folder_,
299 #else 300 #else
300 "/tmp/", "/var/tmp/", 301 "/tmp/", "/var/tmp/",
301 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 302 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
302 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", 303 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/",
303 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) 304 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
304 #endif // WEBRTC_ANDROID || WEBRTC_IOS 305 #endif // WEBRTC_ANDROID || WEBRTC_IOS
305 }; 306 };
306 for (size_t i = 0; i < ARRAY_SIZE(kTempPrefixes); ++i) { 307 for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) {
307 if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i], 308 if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i],
308 strlen(kTempPrefixes[i]))) 309 strlen(kTempPrefixes[i])))
309 return true; 310 return true;
310 } 311 }
311 return false; 312 return false;
312 } 313 }
313 314
314 bool UnixFilesystem::IsFile(const Pathname& pathname) { 315 bool UnixFilesystem::IsFile(const Pathname& pathname) {
315 struct stat st; 316 struct stat st;
316 int res = ::stat(pathname.pathname().c_str(), &st); 317 int res = ::stat(pathname.pathname().c_str(), &st);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (success) 371 if (success)
371 path->SetPathname(path8); 372 path->SetPathname(path8);
372 return success; 373 return success;
373 #elif defined(__native_client__) 374 #elif defined(__native_client__)
374 return false; 375 return false;
375 #elif IOS 376 #elif IOS
376 IOSAppName(path); 377 IOSAppName(path);
377 return true; 378 return true;
378 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) 379 #else // WEBRTC_MAC && !defined(WEBRTC_IOS)
379 char buffer[PATH_MAX + 2]; 380 char buffer[PATH_MAX + 2];
380 ssize_t len = readlink("/proc/self/exe", buffer, ARRAY_SIZE(buffer) - 1); 381 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1);
381 if ((len <= 0) || (len == PATH_MAX + 1)) 382 if ((len <= 0) || (len == PATH_MAX + 1))
382 return false; 383 return false;
383 buffer[len] = '\0'; 384 buffer[len] = '\0';
384 path->SetPathname(buffer); 385 path->SetPathname(buffer);
385 return true; 386 return true;
386 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) 387 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
387 } 388 }
388 389
389 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { 390 bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) {
390 ASSERT(!organization_name_.empty()); 391 ASSERT(!organization_name_.empty());
391 ASSERT(!application_name_.empty()); 392 ASSERT(!application_name_.empty());
392 393
393 // First get the base directory for app data. 394 // First get the base directory for app data.
394 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 395 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
395 if (per_user) { 396 if (per_user) {
396 // Use ~/Library/Application Support/<orgname>/<appname>/ 397 // Use ~/Library/Application Support/<orgname>/<appname>/
397 FSRef fr; 398 FSRef fr;
398 if (0 != FSFindFolder(kUserDomain, kApplicationSupportFolderType, 399 if (0 != FSFindFolder(kUserDomain, kApplicationSupportFolderType,
399 kCreateFolder, &fr)) 400 kCreateFolder, &fr))
400 return false; 401 return false;
401 unsigned char buffer[NAME_MAX+1]; 402 unsigned char buffer[NAME_MAX+1];
402 if (0 != FSRefMakePath(&fr, buffer, ARRAY_SIZE(buffer))) 403 if (0 != FSRefMakePath(&fr, buffer, arraysize(buffer)))
403 return false; 404 return false;
404 path->SetPathname(reinterpret_cast<char*>(buffer), ""); 405 path->SetPathname(reinterpret_cast<char*>(buffer), "");
405 } else { 406 } else {
406 // TODO 407 // TODO
407 return false; 408 return false;
408 } 409 }
409 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) // && !WEBRTC_MAC || WEBRT C_IOS 410 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) // && !WEBRTC_MAC || WEBRT C_IOS
410 ASSERT(provided_app_data_folder_ != NULL); 411 ASSERT(provided_app_data_folder_ != NULL);
411 path->SetPathname(provided_app_data_folder_, ""); 412 path->SetPathname(provided_app_data_folder_, "");
412 #elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) // && !WEBRTC_MAC && !W EBRTC_IOS && !WEBRTC_ANDROID 413 #elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) // && !WEBRTC_MAC && !W EBRTC_IOS && !WEBRTC_ANDROID
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 #else 481 #else
481 ASSERT(!application_name_.empty()); 482 ASSERT(!application_name_.empty());
482 // TODO: Consider whether we are worried about thread safety. 483 // TODO: Consider whether we are worried about thread safety.
483 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) { 484 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) {
484 path->SetPathname(app_temp_path_); 485 path->SetPathname(app_temp_path_);
485 return true; 486 return true;
486 } 487 }
487 488
488 // Create a random directory as /tmp/<appname>-<pid>-<timestamp> 489 // Create a random directory as /tmp/<appname>-<pid>-<timestamp>
489 char buffer[128]; 490 char buffer[128];
490 sprintfn(buffer, ARRAY_SIZE(buffer), "-%d-%d", 491 sprintfn(buffer, arraysize(buffer), "-%d-%d",
491 static_cast<int>(getpid()), 492 static_cast<int>(getpid()),
492 static_cast<int>(time(0))); 493 static_cast<int>(time(0)));
493 std::string folder(application_name_); 494 std::string folder(application_name_);
494 folder.append(buffer); 495 folder.append(buffer);
495 if (!GetTemporaryFolder(*path, true, &folder)) 496 if (!GetTemporaryFolder(*path, true, &folder))
496 return false; 497 return false;
497 498
498 delete [] app_temp_path_; 499 delete [] app_temp_path_;
499 app_temp_path_ = CopyString(path->pathname()); 500 app_temp_path_ = CopyString(path->pathname());
500 // TODO: atexit(DeleteFolderAndContents(app_temp_path_)); 501 // TODO: atexit(DeleteFolderAndContents(app_temp_path_));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 565
565 } // namespace rtc 566 } // namespace rtc
566 567
567 #if defined(__native_client__) 568 #if defined(__native_client__)
568 extern "C" int __attribute__((weak)) 569 extern "C" int __attribute__((weak))
569 link(const char* oldpath, const char* newpath) { 570 link(const char* oldpath, const char* newpath) {
570 errno = EACCES; 571 errno = EACCES;
571 return -1; 572 return -1;
572 } 573 }
573 #endif 574 #endif
OLDNEW
« no previous file with comments | « webrtc/base/testutils.h ('k') | webrtc/base/urlencode_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698