OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 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 // This file only exists because various iOS system APIs are only | 11 // This file only exists because various iOS and macOS system APIs are only |
12 // available from Objective-C. See unixfilesystem.cc for the only use | 12 // available from Objective-C. See unixfilesystem.cc for the only use |
13 // (enforced by a lack of a header file). | 13 // (enforced by a lack of a header file). |
14 | 14 |
15 #import <Foundation/NSPathUtilities.h> | 15 #import <Foundation/NSPathUtilities.h> |
16 #import <Foundation/NSProcessInfo.h> | 16 #import <Foundation/NSProcessInfo.h> |
17 #include <string.h> | 17 #include <string.h> |
18 | 18 |
19 #include "webrtc/base/common.h" | 19 #include "webrtc/base/common.h" |
20 #include "webrtc/base/pathutils.h" | 20 #include "webrtc/base/pathutils.h" |
21 | 21 |
22 // Return a new[]'d |char*| copy of the UTF8 representation of |s|. | 22 // Return a new[]'d |char*| copy of the UTF8 representation of |s|. |
23 // Caller owns the returned memory and must use delete[] on it. | 23 // Caller owns the returned memory and must use delete[] on it. |
24 static char* copyString(NSString* s) { | 24 static char* copyString(NSString* s) { |
25 const char* utf8 = [s UTF8String]; | 25 const char* utf8 = [s UTF8String]; |
26 size_t len = strlen(utf8) + 1; | 26 size_t len = strlen(utf8) + 1; |
27 char* copy = new char[len]; | 27 char* copy = new char[len]; |
28 // This uses a new[] + strcpy (instead of strdup) because the | 28 // This uses a new[] + strcpy (instead of strdup) because the |
29 // receiver expects to be able to delete[] the returned pointer | 29 // receiver expects to be able to delete[] the returned pointer |
30 // (instead of free()ing it). | 30 // (instead of free()ing it). |
31 strcpy(copy, utf8); | 31 strcpy(copy, utf8); |
32 return copy; | 32 return copy; |
33 } | 33 } |
34 | 34 |
35 // Return a (leaked) copy of a directory name suitable for application data. | 35 // Return a (leaked) copy of a directory name suitable for application data. |
36 char* IOSDataDirectory() { | 36 char* AppleDataDirectory() { |
37 NSArray* paths = NSSearchPathForDirectoriesInDomains( | 37 NSArray* paths = NSSearchPathForDirectoriesInDomains( |
38 NSApplicationSupportDirectory, NSUserDomainMask, YES); | 38 NSApplicationSupportDirectory, NSUserDomainMask, YES); |
39 ASSERT([paths count] == 1); | 39 ASSERT([paths count] == 1); |
40 return copyString([paths objectAtIndex:0]); | 40 return copyString([paths objectAtIndex:0]); |
41 } | 41 } |
42 | 42 |
43 // Return a (leaked) copy of a directory name suitable for use as a $TEMP. | 43 // Return a (leaked) copy of a directory name suitable for use as a $TEMP. |
44 char* IOSTempDirectory() { | 44 char* AppleTempDirectory() { |
45 return copyString(NSTemporaryDirectory()); | 45 return copyString(NSTemporaryDirectory()); |
46 } | 46 } |
47 | 47 |
48 // Return the binary's path. | 48 // Return the binary's path. |
49 void IOSAppName(rtc::Pathname* path) { | 49 void AppleAppName(rtc::Pathname* path) { |
50 NSProcessInfo *pInfo = [NSProcessInfo processInfo]; | 50 NSProcessInfo* pInfo = [NSProcessInfo processInfo]; |
51 NSString* argv0 = [[pInfo arguments] objectAtIndex:0]; | 51 NSString* argv0 = [[pInfo arguments] objectAtIndex:0]; |
52 path->SetPathname([argv0 UTF8String]); | 52 path->SetPathname([argv0 UTF8String]); |
53 } | 53 } |
OLD | NEW |