]>
Commit | Line | Data |
---|---|---|
d8925383 | 1 | /* |
8ca704e1 | 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. |
d8925383 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
f64f9b69 | 23 | |
d8925383 | 24 | /* CFSystemDirectories.c |
8ca704e1 A |
25 | Copyright (c) 1997-2011, Apple Inc. All rights reserved. |
26 | Responsibility: Kevin Perry | |
d8925383 A |
27 | */ |
28 | ||
29 | /* | |
30 | This file defines CFCopySearchPathForDirectoriesInDomains(). | |
31 | On MacOS 8, this function returns empty array. | |
32 | On Mach, it calls the System.framework enumeration functions. | |
33 | On Windows, it calls the enumeration functions defined here. | |
34 | */ | |
35 | ||
36 | #include <CoreFoundation/CFPriv.h> | |
37 | #include "CFInternal.h" | |
38 | ||
cf7d2af9 | 39 | #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED |
d8925383 A |
40 | |
41 | /* We use the System framework implementation on Mach. | |
42 | */ | |
43 | #include <libc.h> | |
44 | #include <stdio.h> | |
45 | #include <stdlib.h> | |
46 | #include <NSSystemDirectories.h> | |
47 | ||
48 | CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask) { | |
49 | return NSStartSearchPathEnumeration(dir, domainMask); | |
50 | } | |
51 | ||
52 | CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, uint8_t *path, CFIndex pathSize) { | |
53 | CFSearchPathEnumerationState result; | |
54 | // NSGetNextSearchPathEnumeration requires a MAX_PATH size | |
55 | if (pathSize < PATH_MAX) { | |
56 | uint8_t tempPath[PATH_MAX]; | |
bd5b749c A |
57 | result = NSGetNextSearchPathEnumeration(state, (char *)tempPath); |
58 | strlcpy((char *)path, (char *)tempPath, pathSize); | |
d8925383 | 59 | } else { |
bd5b749c | 60 | result = NSGetNextSearchPathEnumeration(state, (char *)path); |
d8925383 A |
61 | } |
62 | return result; | |
63 | } | |
64 | ||
65 | #endif | |
66 | ||
67 | ||
8ca704e1 | 68 | #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS |
d8925383 A |
69 | |
70 | CFArrayRef CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory, CFSearchPathDomainMask domainMask, Boolean expandTilde) { | |
71 | CFMutableArrayRef array; | |
72 | CFSearchPathEnumerationState state; | |
73 | CFIndex homeLen = -1; | |
74 | char cPath[CFMaxPathSize], home[CFMaxPathSize]; | |
75 | ||
bd5b749c | 76 | array = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeArrayCallBacks); |
d8925383 | 77 | state = __CFStartSearchPathEnumeration(directory, domainMask); |
bd5b749c | 78 | while ((state = __CFGetNextSearchPathEnumeration(state, (uint8_t *)cPath, sizeof(cPath)))) { |
d8925383 A |
79 | CFURLRef url = NULL; |
80 | if (expandTilde && (cPath[0] == '~')) { | |
81 | if (homeLen < 0) { | |
82 | CFURLRef homeURL = CFCopyHomeDirectoryURLForUser(NULL); | |
83 | if (homeURL) { | |
bd5b749c | 84 | CFURLGetFileSystemRepresentation(homeURL, true, (uint8_t *)home, CFMaxPathSize); |
d8925383 A |
85 | homeLen = strlen(home); |
86 | CFRelease(homeURL); | |
87 | } | |
88 | } | |
89 | if (homeLen + strlen(cPath) < CFMaxPathSize) { | |
90 | home[homeLen] = '\0'; | |
bd5b749c A |
91 | strlcat(home, &cPath[1], sizeof(home)); |
92 | url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)home, strlen(home), true); | |
d8925383 A |
93 | } |
94 | } else { | |
bd5b749c | 95 | url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)cPath, strlen(cPath), true); |
d8925383 A |
96 | } |
97 | if (url) { | |
98 | CFArrayAppendValue(array, url); | |
99 | CFRelease(url); | |
100 | } | |
101 | } | |
102 | return array; | |
103 | } | |
104 | ||
105 | #endif | |
106 | ||
107 | #undef numDirs | |
108 | #undef numApplicationDirs | |
109 | #undef numLibraryDirs | |
110 | #undef numDomains | |
111 | #undef invalidDomains | |
112 | #undef invalidDomains | |
113 |