| 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 and macOS 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/checks.h" |
| 19 #include "webrtc/base/common.h" | 20 #include "webrtc/base/common.h" |
| 20 #include "webrtc/base/pathutils.h" | 21 #include "webrtc/base/pathutils.h" |
| 21 | 22 |
| 22 // Return a new[]'d |char*| copy of the UTF8 representation of |s|. | 23 // Return a new[]'d |char*| copy of the UTF8 representation of |s|. |
| 23 // Caller owns the returned memory and must use delete[] on it. | 24 // Caller owns the returned memory and must use delete[] on it. |
| 24 static char* copyString(NSString* s) { | 25 static char* copyString(NSString* s) { |
| 25 const char* utf8 = [s UTF8String]; | 26 const char* utf8 = [s UTF8String]; |
| 26 size_t len = strlen(utf8) + 1; | 27 size_t len = strlen(utf8) + 1; |
| 27 char* copy = new char[len]; | 28 char* copy = new char[len]; |
| 28 // This uses a new[] + strcpy (instead of strdup) because the | 29 // This uses a new[] + strcpy (instead of strdup) because the |
| 29 // receiver expects to be able to delete[] the returned pointer | 30 // receiver expects to be able to delete[] the returned pointer |
| 30 // (instead of free()ing it). | 31 // (instead of free()ing it). |
| 31 strcpy(copy, utf8); | 32 strcpy(copy, utf8); |
| 32 return copy; | 33 return copy; |
| 33 } | 34 } |
| 34 | 35 |
| 35 // Return a (leaked) copy of a directory name suitable for application data. | 36 // Return a (leaked) copy of a directory name suitable for application data. |
| 36 char* AppleDataDirectory() { | 37 char* AppleDataDirectory() { |
| 37 NSArray* paths = NSSearchPathForDirectoriesInDomains( | 38 NSArray* paths = NSSearchPathForDirectoriesInDomains( |
| 38 NSApplicationSupportDirectory, NSUserDomainMask, YES); | 39 NSApplicationSupportDirectory, NSUserDomainMask, YES); |
| 39 ASSERT([paths count] == 1); | 40 RTC_DCHECK([paths count] == 1); |
| 40 return copyString([paths objectAtIndex:0]); | 41 return copyString([paths objectAtIndex:0]); |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Return a (leaked) copy of a directory name suitable for use as a $TEMP. | 44 // Return a (leaked) copy of a directory name suitable for use as a $TEMP. |
| 44 char* AppleTempDirectory() { | 45 char* AppleTempDirectory() { |
| 45 return copyString(NSTemporaryDirectory()); | 46 return copyString(NSTemporaryDirectory()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Return the binary's path. | 49 // Return the binary's path. |
| 49 void AppleAppName(rtc::Pathname* path) { | 50 void AppleAppName(rtc::Pathname* path) { |
| 50 NSProcessInfo* pInfo = [NSProcessInfo processInfo]; | 51 NSProcessInfo* pInfo = [NSProcessInfo processInfo]; |
| 51 NSString* argv0 = [[pInfo arguments] objectAtIndex:0]; | 52 NSString* argv0 = [[pInfo arguments] objectAtIndex:0]; |
| 52 path->SetPathname([argv0 UTF8String]); | 53 path->SetPathname([argv0 UTF8String]); |
| 53 } | 54 } |
| OLD | NEW |