2 * Copyright (c) 2009 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@
23 /* ForFoundationOnly.h
24 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
27 #if !CF_BUILDING_CF && !NSBUILDINGFOUNDATION
28 #error The header file ForFoundationOnly.h is for the exclusive use of the
29 #error CoreFoundation and Foundation projects. No other project should include it.
32 #if !defined(__COREFOUNDATION_FORFOUNDATIONONLY__)
33 #define __COREFOUNDATION_FORFOUNDATIONONLY__ 1
35 #include <CoreFoundation/CFBase.h>
36 #include <CoreFoundation/CFString.h>
37 #include <CoreFoundation/CFArray.h>
38 #include <CoreFoundation/CFData.h>
39 #include <CoreFoundation/CFDictionary.h>
40 #include <CoreFoundation/CFSet.h>
41 #include <CoreFoundation/CFPriv.h>
42 #include <CoreFoundation/CFPropertyList.h>
43 #include <CoreFoundation/CFError.h>
44 #include <CoreFoundation/CFStringEncodingExt.h>
47 // NOTE: miscellaneous declarations are at the end
49 // ---- CFRuntime material ----------------------------------------
53 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
54 #include <malloc/malloc.h>
59 // ---- CFBundle material ----------------------------------------
61 #include <CoreFoundation/CFBundlePriv.h>
65 CF_EXPORT
const CFStringRef _kCFBundleExecutablePathKey
;
66 CF_EXPORT
const CFStringRef _kCFBundleInfoPlistURLKey
;
67 CF_EXPORT
const CFStringRef _kCFBundleRawInfoPlistURLKey
;
68 CF_EXPORT
const CFStringRef _kCFBundleNumericVersionKey
;
69 CF_EXPORT
const CFStringRef _kCFBundleResourcesFileMappedKey
;
70 CF_EXPORT
const CFStringRef _kCFBundleCFMLoadAsBundleKey
;
71 CF_EXPORT
const CFStringRef _kCFBundleAllowMixedLocalizationsKey
;
72 CF_EXPORT
const CFStringRef _kCFBundleInitialPathKey
;
73 CF_EXPORT
const CFStringRef _kCFBundleResolvedPathKey
;
74 CF_EXPORT
const CFStringRef _kCFBundlePrincipalClassKey
;
76 CF_EXPORT CFArrayRef
_CFFindBundleResources(CFBundleRef bundle
, CFURLRef bundleURL
, CFStringRef subDirName
, CFArrayRef searchLanguages
, CFStringRef resName
, CFArrayRef resTypes
, CFIndex limit
, UInt8 version
);
78 CF_EXPORT UInt8
_CFBundleLayoutVersion(CFBundleRef bundle
);
80 CF_EXPORT CFArrayRef
_CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc
, CFURLRef url
, UInt8
*version
);
81 CF_EXPORT CFArrayRef
_CFBundleGetLanguageSearchList(CFBundleRef bundle
);
83 CF_EXPORT Boolean
_CFBundleLoadExecutableAndReturnError(CFBundleRef bundle
, Boolean forceGlobal
, CFErrorRef
*error
);
84 CF_EXPORT CFErrorRef
_CFBundleCreateError(CFAllocatorRef allocator
, CFBundleRef bundle
, CFIndex code
);
89 // ---- CFPreferences material ----------------------------------------
91 #define DEBUG_PREFERENCES_MEMORY 0
93 #if DEBUG_PREFERENCES_MEMORY
94 #include "../Tests/CFCountingAllocator.h"
99 extern void _CFPreferencesPurgeDomainCache(void);
102 void * (*createDomain
)(CFAllocatorRef allocator
, CFTypeRef context
);
103 void (*freeDomain
)(CFAllocatorRef allocator
, CFTypeRef context
, void *domain
);
104 CFTypeRef (*fetchValue
)(CFTypeRef context
, void *domain
, CFStringRef key
); // Caller releases
105 void (*writeValue
)(CFTypeRef context
, void *domain
, CFStringRef key
, CFTypeRef value
);
106 Boolean (*synchronize
)(CFTypeRef context
, void *domain
);
107 void (*getKeysAndValues
)(CFAllocatorRef alloc
, CFTypeRef context
, void *domain
, void **buf
[], CFIndex
*numKeyValuePairs
);
108 CFDictionaryRef (*copyDomainDictionary
)(CFTypeRef context
, void *domain
);
109 /* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
110 void (*setIsWorldReadable
)(CFTypeRef context
, void *domain
, Boolean isWorldReadable
);
111 } _CFPreferencesDomainCallBacks
;
113 CF_EXPORT CFAllocatorRef
__CFPreferencesAllocator(void);
114 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks
;
115 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks
;
117 typedef struct __CFPreferencesDomain
* CFPreferencesDomainRef
;
119 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesDomainCreate(CFTypeRef context
, const _CFPreferencesDomainCallBacks
*callBacks
);
120 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesStandardDomain(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
122 CF_EXPORT CFTypeRef
_CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain
, CFStringRef key
);
123 CF_EXPORT
void _CFPreferencesDomainSet(CFPreferencesDomainRef domain
, CFStringRef key
, CFTypeRef value
);
124 CF_EXPORT Boolean
_CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain
);
126 CF_EXPORT CFArrayRef
_CFPreferencesCreateDomainList(CFStringRef userName
, CFStringRef hostName
);
127 CF_EXPORT Boolean
_CFSynchronizeDomainCache(void);
129 CF_EXPORT
void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain
, CFDictionaryRef dict
);
130 CF_EXPORT CFDictionaryRef
_CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain
);
131 CF_EXPORT Boolean
_CFPreferencesDomainExists(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
133 /* HACK - this is to work around the fact that individual domains lose the information about their user/host/app triplet at creation time. We should find a better way to propogate this information. REW, 1/13/00 */
134 CF_EXPORT
void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain
, Boolean isWorldReadable
);
137 CFMutableArrayRef _search
; // the search list; an array of _CFPreferencesDomains
138 CFMutableDictionaryRef _dictRep
; // Mutable; a collapsed view of the search list, expressed as a single dictionary
139 CFStringRef _appName
;
140 } _CFApplicationPreferences
;
142 CF_EXPORT _CFApplicationPreferences
*_CFStandardApplicationPreferences(CFStringRef appName
);
143 CF_EXPORT _CFApplicationPreferences
*_CFApplicationPreferencesCreateWithUser(CFStringRef userName
, CFStringRef appName
);
144 CF_EXPORT
void _CFDeallocateApplicationPreferences(_CFApplicationPreferences
*self
);
145 CF_EXPORT CFTypeRef
_CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences
*prefs
, CFStringRef key
);
146 CF_EXPORT
void _CFApplicationPreferencesSet(_CFApplicationPreferences
*self
, CFStringRef defaultName
, CFTypeRef value
);
147 CF_EXPORT
void _CFApplicationPreferencesRemove(_CFApplicationPreferences
*self
, CFStringRef defaultName
);
148 CF_EXPORT Boolean
_CFApplicationPreferencesSynchronize(_CFApplicationPreferences
*self
);
149 CF_EXPORT
void _CFApplicationPreferencesUpdate(_CFApplicationPreferences
*self
); // same as updateDictRep
150 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences
*self
, CFDictionaryRef hint
, CFDictionaryRef insertion
, CFPreferencesDomainRef afterDomain
);
151 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences
*self
, CFDictionaryRef hint
); // same as dictRep
152 CF_EXPORT
void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences
*appPreferences
);
153 CF_EXPORT
void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences
*appPrefs
, CFStringRef appName
);
154 CF_EXPORT
void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
155 CF_EXPORT
void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
157 CF_EXPORT
void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
, Boolean addAtTop
);
158 CF_EXPORT Boolean
_CFApplicationPreferencesContainsDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
159 CF_EXPORT
void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
161 CF_EXPORT CFTypeRef
_CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef stopper
, CFStringRef key
);
168 // ---- CFString material ----------------------------------------
170 #include <CoreFoundation/CFStringEncodingExt.h>
174 /* Create a byte stream from a CFString backing. Can convert a string piece at a
175 time into a fixed size buffer. Returns number of characters converted.
176 Characters that cannot be converted to the specified encoding are represented
177 with the char specified by lossByte; if 0, then lossy conversion is not allowed
178 and conversion stops, returning partial results.
179 generatingExternalFile indicates that any extra stuff to allow this data to be
180 persistent (for instance, BOM) should be included.
181 Pass buffer==NULL if you don't care about the converted string (but just the
182 convertability, or number of bytes required, indicated by usedBufLen).
183 Does not zero-terminate. If you want to create Pascal or C string, allow one
184 extra byte at start or end.
186 CF_EXPORT CFIndex
__CFStringEncodeByteStream(CFStringRef string
, CFIndex rangeLoc
, CFIndex rangeLen
, Boolean generatingExternalFile
, CFStringEncoding encoding
, char lossByte
, UInt8
*buffer
, CFIndex max
, CFIndex
*usedBufLen
);
188 CF_EXPORT CFStringRef
__CFStringCreateImmutableFunnel2(CFAllocatorRef alloc
, const void *bytes
, CFIndex numBytes
, CFStringEncoding encoding
, Boolean possiblyExternalFormat
, Boolean tryToReduceUnicode
, Boolean hasLengthByte
, Boolean hasNullByte
, Boolean noCopy
, CFAllocatorRef contentsDeallocator
);
190 CF_INLINE Boolean
__CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding
) {
191 switch (encoding
& 0x0000FF00) {
192 case 0x0: // MacOS Script range
193 // Symbol & bidi encodings are not ASCII superset
194 if (encoding
== kCFStringEncodingMacJapanese
|| encoding
== kCFStringEncodingMacArabic
|| encoding
== kCFStringEncodingMacHebrew
|| encoding
== kCFStringEncodingMacUkrainian
|| encoding
== kCFStringEncodingMacSymbol
|| encoding
== kCFStringEncodingMacDingbats
) return false;
197 case 0x100: // Unicode range
198 if (encoding
!= kCFStringEncodingUTF8
) return false;
201 case 0x200: // ISO range
202 if (encoding
== kCFStringEncodingISOLatinArabic
) return false;
205 case 0x600: // National standards range
206 if (encoding
!= kCFStringEncodingASCII
) return false;
209 case 0x800: // ISO 2022 range
210 return false; // It's modal encoding
212 case 0xA00: // Misc standard range
213 if ((encoding
== kCFStringEncodingShiftJIS
) || (encoding
== kCFStringEncodingHZ_GB_2312
)) return false;
217 if (encoding
== kCFStringEncodingNonLossyASCII
) return false;
220 case 0xC00: // EBCDIC
224 return ((encoding
& 0x0000FF00) > 0x0C00 ? false : true);
229 /* Desperately using extern here */
230 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding
;
231 CF_EXPORT CFStringEncoding
__CFStringComputeEightBitStringEncoding(void);
233 CF_INLINE CFStringEncoding
__CFStringGetEightBitStringEncoding(void) {
234 if (__CFDefaultEightBitStringEncoding
== kCFStringEncodingInvalidId
) __CFStringComputeEightBitStringEncoding();
235 return __CFDefaultEightBitStringEncoding
;
239 __kCFVarWidthLocalBufferSize
= 1008
242 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
247 Boolean isASCII
; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
248 Boolean shouldFreeChars
; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
251 CFAllocatorRef allocator
; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
252 CFIndex numChars
; /* This is in terms of ascii or unicode; that is, if isASCII, it is number of 7-bit chars; otherwise it is number of UniChars; note that the actual allocated space might be larger */
253 UInt8 localBuffer
[__kCFVarWidthLocalBufferSize
]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
254 } CFVarWidthCharBuffer
;
257 /* Convert a byte stream to ASCII (7-bit!) or Unicode, with a CFVarWidthCharBuffer struct on the stack. false return indicates an error occured during the conversion. Depending on .isASCII, follow .chars.ascii or .chars.unicode. If .shouldFreeChars is returned as true, free the returned buffer when done with it. If useClientsMemoryPtr is provided as non-NULL, and the provided memory can be used as is, this is set to true, and the .ascii or .unicode buffer in CFVarWidthCharBuffer is set to bytes.
258 !!! If the stream is Unicode and has no BOM, the data is assumed to be big endian! Could be trouble on Intel if someone didn't follow that assumption.
259 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
261 CF_EXPORT Boolean
__CFStringDecodeByteStream2(const UInt8
*bytes
, UInt32 len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
);
262 CF_EXPORT Boolean
__CFStringDecodeByteStream3(const UInt8
*bytes
, CFIndex len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
, UInt32 converterFlags
);
265 /* Convert single byte to Unicode; assumes one-to-one correspondence (that is, can only be used with 1-byte encodings). You can use the function if it's not NULL.
267 CF_EXPORT
Boolean (*__CFCharToUniCharFunc
)(UInt32 flags
, UInt8 ch
, UniChar
*unicodeChar
);
269 /* Character class functions UnicodeData-2_1_5.txt
271 CF_INLINE Boolean
__CFIsWhitespace(UniChar theChar
) {
272 return ((theChar
< 0x21) || (theChar
> 0x7E && theChar
< 0xA1) || (theChar
>= 0x2000 && theChar
<= 0x200B) || (theChar
== 0x3000)) ? true : false;
275 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
277 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer
*buf
, CFIndex idx
) {
278 if (buf
->directBuffer
) {
279 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
280 return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
282 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
283 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
284 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
285 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
286 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
287 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
289 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
292 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
294 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer
*buf
, CFIndex idx
) {
295 if (buf
->directBuffer
) return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
296 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
297 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
298 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
299 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
300 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
302 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
306 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
308 CF_EXPORT
void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
);
309 CF_EXPORT CFStringRef
_CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef format
, va_list arguments
);
311 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
313 enum {_CFStringErrNone
= 0, _CFStringErrNotMutable
= 1, _CFStringErrNilArg
= 2, _CFStringErrBounds
= 3};
314 CF_EXPORT
int __CFStringCheckAndReplace(CFMutableStringRef str
, CFRange range
, CFStringRef replacement
);
315 CF_EXPORT Boolean
__CFStringNoteErrors(void); // Should string errors raise?
317 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
319 CF_EXPORT Boolean
__CFStringIsEightBit(CFStringRef str
);
321 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
323 CF_EXPORT
int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str
, CFIndex idx
, UniChar
*ch
);
324 CF_EXPORT
int _CFStringCheckAndGetCharacters(CFStringRef str
, CFRange range
, UniChar
*buffer
);
325 CF_EXPORT CFIndex
_CFStringGetLength2(CFStringRef str
);
326 CF_EXPORT CFHashCode
__CFStringHash(CFTypeRef cf
);
327 CF_EXPORT CFHashCode
CFStringHashISOLatin1CString(const uint8_t *bytes
, CFIndex len
);
328 CF_EXPORT CFHashCode
CFStringHashCString(const uint8_t *bytes
, CFIndex len
);
329 CF_EXPORT CFHashCode
CFStringHashCharacters(const UniChar
*characters
, CFIndex len
);
330 CF_EXPORT CFHashCode
CFStringHashNSString(CFStringRef str
);
336 // ---- Binary plist material ----------------------------------------
338 typedef const struct __CFKeyedArchiverUID
* CFKeyedArchiverUIDRef
;
339 CF_EXPORT CFTypeID
_CFKeyedArchiverUIDGetTypeID(void);
340 CF_EXPORT CFKeyedArchiverUIDRef
_CFKeyedArchiverUIDCreate(CFAllocatorRef allocator
, uint32_t value
);
341 CF_EXPORT
uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid
);
345 kCFBinaryPlistMarkerNull
= 0x00,
346 kCFBinaryPlistMarkerFalse
= 0x08,
347 kCFBinaryPlistMarkerTrue
= 0x09,
348 kCFBinaryPlistMarkerFill
= 0x0F,
349 kCFBinaryPlistMarkerInt
= 0x10,
350 kCFBinaryPlistMarkerReal
= 0x20,
351 kCFBinaryPlistMarkerDate
= 0x33,
352 kCFBinaryPlistMarkerData
= 0x40,
353 kCFBinaryPlistMarkerASCIIString
= 0x50,
354 kCFBinaryPlistMarkerUnicode16String
= 0x60,
355 kCFBinaryPlistMarkerUID
= 0x80,
356 kCFBinaryPlistMarkerArray
= 0xA0,
357 kCFBinaryPlistMarkerSet
= 0xC0,
358 kCFBinaryPlistMarkerDict
= 0xD0
364 } CFBinaryPlistHeader
;
368 uint8_t _sortVersion
;
369 uint8_t _offsetIntSize
;
370 uint8_t _objectRefSize
;
371 uint64_t _numObjects
;
373 uint64_t _offsetTableOffset
;
374 } CFBinaryPlistTrailer
;
377 CF_EXPORT
bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes
, uint64_t datalen
, uint8_t *marker
, uint64_t *offset
, CFBinaryPlistTrailer
*trailer
);
378 CF_EXPORT
bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFIndex idx
, uint64_t *offset
, CFMutableDictionaryRef objects
);
379 CF_EXPORT
bool __CFBinaryPlistGetOffsetForValueFromDictionary3(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFTypeRef key
, uint64_t *koffset
, uint64_t *voffset
, Boolean unused
, CFMutableDictionaryRef objects
);
380 CF_EXPORT
bool __CFBinaryPlistCreateObject(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFAllocatorRef allocator
, CFOptionFlags mutabilityOption
, CFMutableDictionaryRef objects
, CFPropertyListRef
*plist
);
381 CF_EXPORT
bool __CFBinaryPlistCreateObject2(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFAllocatorRef allocator
, CFOptionFlags mutabilityOption
, CFMutableDictionaryRef objects
, CFMutableSetRef set
, CFIndex curDepth
, CFPropertyListRef
*plist
);
382 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStream(CFPropertyListRef plist
, CFTypeRef stream
);
383 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithEstimate(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
); // will be removed soon
384 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithOptions(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
); // will be removed soon
385 CF_EXPORT CFIndex
__CFBinaryPlistWrite(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
, CFErrorRef
*error
);
387 // ---- Used by property list parsing in Foundation
389 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLData(CFAllocatorRef allocator
, CFDataRef xmlData
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
391 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLString(CFAllocatorRef allocator
, CFStringRef xmlString
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
393 CF_EXPORT
bool _CFPropertyListCreateSingleValue(CFAllocatorRef allocator
, CFDataRef data
, CFOptionFlags option
, CFStringRef key
, CFPropertyListRef
*value
, CFErrorRef
*error
);
395 // ---- Sudden Termination material ----------------------------------------
397 #if DEPLOYMENT_TARGET_MACOSX
399 CF_EXPORT
void _CFSuddenTerminationDisable(void);
400 CF_EXPORT
void _CFSuddenTerminationEnable(void);
401 CF_EXPORT
void _CFSuddenTerminationExitIfTerminationEnabled(int exitStatus
);
402 CF_EXPORT
void _CFSuddenTerminationExitWhenTerminationEnabled(int exitStatus
);
403 CF_EXPORT
size_t _CFSuddenTerminationDisablingCount(void);
407 #if DEPLOYMENT_TARGET_WINDOWS
408 // ---- Windows-specific material ---------------------------------------
410 // These are replacements for POSIX calls on Windows, ensuring that the UTF8 parameters are converted to UTF16 before being passed to Windows
411 CF_EXPORT
int _NS_stat(const char *name
, struct _stat
*st
);
412 CF_EXPORT
int _NS_mkdir(const char *name
);
413 CF_EXPORT
int _NS_rmdir(const char *name
);
414 CF_EXPORT
int _NS_chmod(const char *name
, int mode
);
415 CF_EXPORT
int _NS_unlink(const char *name
);
416 CF_EXPORT
char *_NS_getcwd(char *dstbuf
, size_t size
); // Warning: this doesn't support dstbuf as null even though 'getcwd' does
417 CF_EXPORT
char *_NS_getenv(const char *name
);
418 CF_EXPORT
int _NS_rename(const char *oldName
, const char *newName
);
419 CF_EXPORT
int _NS_open(const char *name
, int oflag
, int pmode
);
420 CF_EXPORT
int _NS_mkstemp(char *name
, int bufSize
);
423 // ---- Miscellaneous material ----------------------------------------
425 #include <CoreFoundation/CFBag.h>
426 #include <CoreFoundation/CFSet.h>
431 CF_EXPORT CFTypeID
CFTypeGetTypeID(void);
433 CF_EXPORT CFTypeRef
_CFRetainGC(CFTypeRef cf
);
434 CF_EXPORT
void _CFReleaseGC(CFTypeRef cf
);
436 CF_EXPORT
void _CFArraySetCapacity(CFMutableArrayRef array
, CFIndex cap
);
437 CF_EXPORT
void _CFBagSetCapacity(CFMutableBagRef bag
, CFIndex cap
);
438 CF_EXPORT
void _CFDictionarySetCapacity(CFMutableDictionaryRef dict
, CFIndex cap
);
439 CF_EXPORT
void _CFSetSetCapacity(CFMutableSetRef set
, CFIndex cap
);
441 CF_EXPORT
void CFCharacterSetCompact(CFMutableCharacterSetRef theSet
);
442 CF_EXPORT
void CFCharacterSetFast(CFMutableCharacterSetRef theSet
);
444 CF_EXPORT
const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array
, CFIndex idx
);
445 CF_EXPORT
void _CFArrayReplaceValues(CFMutableArrayRef array
, CFRange range
, const void **newValues
, CFIndex newCount
);
449 Call CFStartSearchPathEnumeration() once, then call
450 CFGetNextSearchPathEnumeration() one or more times with the returned state.
451 The return value of CFGetNextSearchPathEnumeration() should be used as
452 the state next time around.
453 When CFGetNextSearchPathEnumeration() returns 0, you're done.
455 typedef CFIndex CFSearchPathEnumerationState
;
456 CF_EXPORT CFSearchPathEnumerationState
__CFStartSearchPathEnumeration(CFSearchPathDirectory dir
, CFSearchPathDomainMask domainMask
);
457 CF_EXPORT CFSearchPathEnumerationState
__CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state
, UInt8
*path
, CFIndex pathSize
);
459 /* For use by NSNumber and CFNumber.
460 Hashing algorithm for CFNumber:
461 M = Max CFHashCode (assumed to be unsigned)
462 For positive integral values: (N * HASHFACTOR) mod M
463 For negative integral values: ((-N) * HASHFACTOR) mod M
464 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
465 HASHFACTOR is 2654435761, from Knuth's multiplicative method
467 #define HASHFACTOR 2654435761U
469 CF_INLINE CFHashCode
_CFHashInt(long i
) {
470 return ((i
> 0) ? (CFHashCode
)(i
) : (CFHashCode
)(-i
)) * HASHFACTOR
;
473 CF_INLINE CFHashCode
_CFHashDouble(double d
) {
477 CFHashCode integralHash
= HASHFACTOR
* (CFHashCode
)fmod(dInt
, (double)ULONG_MAX
);
478 return (CFHashCode
)(integralHash
+ (CFHashCode
)((d
- dInt
) * ULONG_MAX
));
482 /* These four functions are used by NSError in formatting error descriptions. They take NS or CFError as arguments and return a retained CFString or NULL.
484 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedDescription(CFErrorRef err
);
485 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedFailureReason(CFErrorRef err
);
486 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err
);
487 CF_EXPORT CFStringRef
_CFErrorCreateDebugDescription(CFErrorRef err
);
489 CF_EXPORT CFURLRef
_CFURLAlloc(CFAllocatorRef allocator
);
490 CF_EXPORT
void _CFURLInitWithString(CFURLRef url
, CFStringRef string
, CFURLRef baseURL
);
491 CF_EXPORT
void _CFURLInitFSPath(CFURLRef url
, CFStringRef path
);
492 CF_EXPORT Boolean
_CFStringIsLegalURLString(CFStringRef string
);
493 CF_EXPORT
void *__CFURLReservedPtr(CFURLRef url
);
494 CF_EXPORT
void __CFURLSetReservedPtr(CFURLRef url
, void *ptr
);
495 CF_EXPORT CFStringEncoding
_CFURLGetEncoding(CFURLRef url
);
497 CF_EXPORT Boolean
_CFRunLoopFinished(CFRunLoopRef rl
, CFStringRef mode
);
499 CF_EXPORT CFIndex
_CFStreamInstanceSize(void);
501 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
503 mach_vm_address_t address
;
510 } CFDiscorporateMemory
;
512 extern kern_return_t
_CFDiscorporateMemoryAllocate(CFDiscorporateMemory
*hm
, size_t size
, bool purgeable
);
513 extern kern_return_t
_CFDiscorporateMemoryDeallocate(CFDiscorporateMemory
*hm
);
514 extern kern_return_t
_CFDiscorporateMemoryDematerialize(CFDiscorporateMemory
*hm
);
515 extern kern_return_t
_CFDiscorporateMemoryMaterialize(CFDiscorporateMemory
*hm
);
518 CF_EXPORT CFRange
_CFDataFindBytes(CFDataRef data
, CFDataRef dataToFind
, CFRange searchRange
, CFDataSearchFlags compareOptions
);
521 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
522 #if !defined(__CFReadTSR)
523 #include <mach/mach_time.h>
524 #define __CFReadTSR() mach_absolute_time()
526 #elif DEPLOYMENT_TARGET_WINDOWS
528 CF_INLINE UInt64
__CFReadTSR(void) {
530 QueryPerformanceCounter(&freq
);
531 return freq
.QuadPart
;
539 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */