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 <Carbon/Carbon.h> | 20 #include <CoreFoundation/CoreFoundation.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_IOS) | 53 #if defined(WEBRTC_MAC) |
54 // Defined in iosfilesystem.mm. No header file to discourage use | 54 // Defined in applefilesystem.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* IOSDataDirectory(); | 57 char* AppleDataDirectory(); |
58 char* IOSTempDirectory(); | 58 char* AppleTempDirectory(); |
59 void IOSAppName(rtc::Pathname* path); | 59 void AppleAppName(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_ = IOSDataDirectory(); | 84 provided_app_data_folder_ = AppleDataDirectory(); |
85 if (!provided_app_temp_folder_) | 85 if (!provided_app_temp_folder_) |
86 provided_app_temp_folder_ = IOSTempDirectory(); | 86 provided_app_temp_folder_ = AppleTempDirectory(); |
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(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 360 #if defined(__native_client__) |
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__) | |
375 return false; | 361 return false; |
376 #elif WEBRTC_IOS | 362 #elif defined(WEBRTC_MAC) |
377 IOSAppName(path); | 363 AppleAppName(path); |
378 return true; | 364 return true; |
379 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) | 365 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) |
380 char buffer[PATH_MAX + 2]; | 366 char buffer[PATH_MAX + 2]; |
381 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); | 367 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); |
382 if ((len <= 0) || (len == PATH_MAX + 1)) | 368 if ((len <= 0) || (len == PATH_MAX + 1)) |
383 return false; | 369 return false; |
384 buffer[len] = '\0'; | 370 buffer[len] = '\0'; |
385 path->SetPathname(buffer); | 371 path->SetPathname(buffer); |
386 return true; | 372 return true; |
387 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 373 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 | 551 |
566 } // namespace rtc | 552 } // namespace rtc |
567 | 553 |
568 #if defined(__native_client__) | 554 #if defined(__native_client__) |
569 extern "C" int __attribute__((weak)) | 555 extern "C" int __attribute__((weak)) |
570 link(const char* oldpath, const char* newpath) { | 556 link(const char* oldpath, const char* newpath) { |
571 errno = EACCES; | 557 errno = EACCES; |
572 return -1; | 558 return -1; |
573 } | 559 } |
574 #endif | 560 #endif |
OLD | NEW |