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