2 * Copyright (c) 2012 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 /* CFSystemDirectories.c
25 Copyright (c) 1997-2011, Apple Inc. All rights reserved.
26 Responsibility: Kevin Perry
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.
36 #include <CoreFoundation/CFPriv.h>
37 #include "CFInternal.h"
39 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
41 /* We use the System framework implementation on Mach.
46 #include <NSSystemDirectories.h>
48 CFSearchPathEnumerationState
__CFStartSearchPathEnumeration(CFSearchPathDirectory dir
, CFSearchPathDomainMask domainMask
) {
49 return NSStartSearchPathEnumeration(dir
, domainMask
);
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
];
57 result
= NSGetNextSearchPathEnumeration(state
, (char *)tempPath
);
58 strlcpy((char *)path
, (char *)tempPath
, pathSize
);
60 result
= NSGetNextSearchPathEnumeration(state
, (char *)path
);
68 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
70 CFArrayRef
CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory
, CFSearchPathDomainMask domainMask
, Boolean expandTilde
) {
71 CFMutableArrayRef array
;
72 CFSearchPathEnumerationState state
;
74 char cPath
[CFMaxPathSize
], home
[CFMaxPathSize
];
76 array
= CFArrayCreateMutable(kCFAllocatorSystemDefault
, 0, &kCFTypeArrayCallBacks
);
77 state
= __CFStartSearchPathEnumeration(directory
, domainMask
);
78 while ((state
= __CFGetNextSearchPathEnumeration(state
, (uint8_t *)cPath
, sizeof(cPath
)))) {
80 if (expandTilde
&& (cPath
[0] == '~')) {
82 CFURLRef homeURL
= CFCopyHomeDirectoryURLForUser(NULL
);
84 CFURLGetFileSystemRepresentation(homeURL
, true, (uint8_t *)home
, CFMaxPathSize
);
85 homeLen
= strlen(home
);
89 if (homeLen
+ strlen(cPath
) < CFMaxPathSize
) {
91 strlcat(home
, &cPath
[1], sizeof(home
));
92 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault
, (uint8_t *)home
, strlen(home
), true);
95 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault
, (uint8_t *)cPath
, strlen(cPath
), true);
98 CFArrayAppendValue(array
, url
);
108 #undef numApplicationDirs
109 #undef numLibraryDirs
111 #undef invalidDomains
112 #undef invalidDomains