2 * Copyright (c) 2014 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-2014, 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.
47 #include <NSSystemDirectories.h>
49 CFSearchPathEnumerationState
__CFStartSearchPathEnumeration(CFSearchPathDirectory dir
, CFSearchPathDomainMask domainMask
) {
50 return NSStartSearchPathEnumeration(dir
, domainMask
);
53 CFSearchPathEnumerationState
__CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state
, uint8_t *path
, CFIndex pathSize
) {
54 CFSearchPathEnumerationState result
;
55 // NSGetNextSearchPathEnumeration requires a MAX_PATH size
56 if (pathSize
< PATH_MAX
) {
57 uint8_t tempPath
[PATH_MAX
];
58 result
= NSGetNextSearchPathEnumeration(state
, (char *)tempPath
);
59 strlcpy((char *)path
, (char *)tempPath
, pathSize
);
61 result
= NSGetNextSearchPathEnumeration(state
, (char *)path
);
69 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
71 CFArrayRef
CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory
, CFSearchPathDomainMask domainMask
, Boolean expandTilde
) {
72 CFMutableArrayRef array
;
73 CFSearchPathEnumerationState state
;
75 char cPath
[CFMaxPathSize
], home
[CFMaxPathSize
];
77 array
= CFArrayCreateMutable(kCFAllocatorSystemDefault
, 0, &kCFTypeArrayCallBacks
);
78 state
= __CFStartSearchPathEnumeration(directory
, domainMask
);
79 while ((state
= __CFGetNextSearchPathEnumeration(state
, (uint8_t *)cPath
, sizeof(cPath
)))) {
81 if (expandTilde
&& (cPath
[0] == '~')) {
83 CFURLRef homeURL
= CFCopyHomeDirectoryURLForUser(NULL
);
85 CFURLGetFileSystemRepresentation(homeURL
, true, (uint8_t *)home
, CFMaxPathSize
);
86 homeLen
= strlen(home
);
90 if (homeLen
+ strlen(cPath
) < CFMaxPathSize
) {
92 strlcat(home
, &cPath
[1], sizeof(home
));
93 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault
, (uint8_t *)home
, strlen(home
), true);
96 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault
, (uint8_t *)cPath
, strlen(cPath
), true);
99 CFArrayAppendValue(array
, url
);
110 #undef numApplicationDirs
111 #undef numLibraryDirs
113 #undef invalidDomains
114 #undef invalidDomains