OLD | NEW |
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 |
11 #include "webrtc/base/unixfilesystem.h" | 11 #include "webrtc/base/unixfilesystem.h" |
12 | 12 |
13 #include <errno.h> | 13 #include <errno.h> |
14 #include <fcntl.h> | 14 #include <fcntl.h> |
15 #include <stdlib.h> | 15 #include <stdlib.h> |
16 #include <sys/stat.h> | 16 #include <sys/stat.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
18 | 18 |
19 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 19 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
20 #include <CoreFoundation/CoreFoundation.h> | 20 #include <Carbon/Carbon.h> |
21 #include <IOKit/IOCFBundle.h> | 21 #include <IOKit/IOCFBundle.h> |
22 #include <sys/statvfs.h> | 22 #include <sys/statvfs.h> |
23 #include "webrtc/base/macutils.h" | 23 #include "webrtc/base/macutils.h" |
24 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 24 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
25 | 25 |
26 #if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) || defined(WEBRTC_IOS) | 26 #if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) || defined(WEBRTC_IOS) |
27 #include <sys/types.h> | 27 #include <sys/types.h> |
28 #if defined(WEBRTC_ANDROID) | 28 #if defined(WEBRTC_ANDROID) |
29 #include <sys/statfs.h> | 29 #include <sys/statfs.h> |
30 #elif !defined(__native_client__) | 30 #elif !defined(__native_client__) |
(...skipping 12 matching lines...) Expand all Loading... |
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/arraysize.h" |
48 #include "webrtc/base/fileutils.h" | 48 #include "webrtc/base/fileutils.h" |
49 #include "webrtc/base/pathutils.h" | 49 #include "webrtc/base/pathutils.h" |
50 #include "webrtc/base/stream.h" | 50 #include "webrtc/base/stream.h" |
51 #include "webrtc/base/stringutils.h" | 51 #include "webrtc/base/stringutils.h" |
52 | 52 |
53 #if defined(WEBRTC_MAC) | 53 #if defined(WEBRTC_IOS) |
54 // Defined in applefilesystem.mm. No header file to discourage use | 54 // Defined in iosfilesystem.mm. No header file to discourage use |
55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in | 55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in |
56 // this file. Don't copy/paste. I mean it. | 56 // this file. Don't copy/paste. I mean it. |
57 char* AppleDataDirectory(); | 57 char* IOSDataDirectory(); |
58 char* AppleTempDirectory(); | 58 char* IOSTempDirectory(); |
59 void AppleAppName(rtc::Pathname* path); | 59 void IOSAppName(rtc::Pathname* path); |
60 #endif | 60 #endif |
61 | 61 |
62 namespace rtc { | 62 namespace rtc { |
63 | 63 |
64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) | 64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) |
65 char* UnixFilesystem::app_temp_path_ = NULL; | 65 char* UnixFilesystem::app_temp_path_ = NULL; |
66 #else | 66 #else |
67 char* UnixFilesystem::provided_app_data_folder_ = NULL; | 67 char* UnixFilesystem::provided_app_data_folder_ = NULL; |
68 char* UnixFilesystem::provided_app_temp_folder_ = NULL; | 68 char* UnixFilesystem::provided_app_temp_folder_ = NULL; |
69 | 69 |
70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { | 70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { |
71 delete [] provided_app_data_folder_; | 71 delete [] provided_app_data_folder_; |
72 provided_app_data_folder_ = CopyString(folder); | 72 provided_app_data_folder_ = CopyString(folder); |
73 } | 73 } |
74 | 74 |
75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { | 75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { |
76 delete [] provided_app_temp_folder_; | 76 delete [] provided_app_temp_folder_; |
77 provided_app_temp_folder_ = CopyString(folder); | 77 provided_app_temp_folder_ = CopyString(folder); |
78 } | 78 } |
79 #endif | 79 #endif |
80 | 80 |
81 UnixFilesystem::UnixFilesystem() { | 81 UnixFilesystem::UnixFilesystem() { |
82 #if defined(WEBRTC_IOS) | 82 #if defined(WEBRTC_IOS) |
83 if (!provided_app_data_folder_) | 83 if (!provided_app_data_folder_) |
84 provided_app_data_folder_ = AppleDataDirectory(); | 84 provided_app_data_folder_ = IOSDataDirectory(); |
85 if (!provided_app_temp_folder_) | 85 if (!provided_app_temp_folder_) |
86 provided_app_temp_folder_ = AppleTempDirectory(); | 86 provided_app_temp_folder_ = IOSTempDirectory(); |
87 #endif | 87 #endif |
88 } | 88 } |
89 | 89 |
90 UnixFilesystem::~UnixFilesystem() {} | 90 UnixFilesystem::~UnixFilesystem() {} |
91 | 91 |
92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { | 92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { |
93 std::string pathname(path.pathname()); | 93 std::string pathname(path.pathname()); |
94 int len = pathname.length(); | 94 int len = pathname.length(); |
95 if ((len == 0) || (pathname[len - 1] != '/')) | 95 if ((len == 0) || (pathname[len - 1] != '/')) |
96 return false; | 96 return false; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 case FTT_ACCESSED: | 350 case FTT_ACCESSED: |
351 *time = st.st_atime; | 351 *time = st.st_atime; |
352 break; | 352 break; |
353 default: | 353 default: |
354 return false; | 354 return false; |
355 } | 355 } |
356 return true; | 356 return true; |
357 } | 357 } |
358 | 358 |
359 bool UnixFilesystem::GetAppPathname(Pathname* path) { | 359 bool UnixFilesystem::GetAppPathname(Pathname* path) { |
360 #if defined(__native_client__) | 360 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 361 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 362 CFDictionaryRef procinfo = ProcessInformationCopyDictionary(&psn, |
| 363 kProcessDictionaryIncludeAllInformationMask); |
| 364 if (NULL == procinfo) |
| 365 return false; |
| 366 CFStringRef cfpath = (CFStringRef) CFDictionaryGetValue(procinfo, |
| 367 kIOBundleExecutableKey); |
| 368 std::string path8; |
| 369 bool success = ToUtf8(cfpath, &path8); |
| 370 CFRelease(procinfo); |
| 371 if (success) |
| 372 path->SetPathname(path8); |
| 373 return success; |
| 374 #elif defined(__native_client__) |
361 return false; | 375 return false; |
362 #elif defined(WEBRTC_MAC) | 376 #elif WEBRTC_IOS |
363 AppleAppName(path); | 377 IOSAppName(path); |
364 return true; | 378 return true; |
365 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) | 379 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) |
366 char buffer[PATH_MAX + 2]; | 380 char buffer[PATH_MAX + 2]; |
367 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); | 381 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); |
368 if ((len <= 0) || (len == PATH_MAX + 1)) | 382 if ((len <= 0) || (len == PATH_MAX + 1)) |
369 return false; | 383 return false; |
370 buffer[len] = '\0'; | 384 buffer[len] = '\0'; |
371 path->SetPathname(buffer); | 385 path->SetPathname(buffer); |
372 return true; | 386 return true; |
373 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 387 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 565 |
552 } // namespace rtc | 566 } // namespace rtc |
553 | 567 |
554 #if defined(__native_client__) | 568 #if defined(__native_client__) |
555 extern "C" int __attribute__((weak)) | 569 extern "C" int __attribute__((weak)) |
556 link(const char* oldpath, const char* newpath) { | 570 link(const char* oldpath, const char* newpath) { |
557 errno = EACCES; | 571 errno = EACCES; |
558 return -1; | 572 return -1; |
559 } | 573 } |
560 #endif | 574 #endif |
OLD | NEW |