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 /* ForFoundationOnly.h
25 Copyright (c) 1998-2012, Apple Inc. All rights reserved.
28 #if !CF_BUILDING_CF && !NSBUILDINGFOUNDATION
29 #error The header file ForFoundationOnly.h is for the exclusive use of the
30 #error CoreFoundation and Foundation projects. No other project should include it.
33 #if !defined(__COREFOUNDATION_FORFOUNDATIONONLY__)
34 #define __COREFOUNDATION_FORFOUNDATIONONLY__ 1
36 #include <CoreFoundation/CFBase.h>
37 #include <CoreFoundation/CFString.h>
38 #include <CoreFoundation/CFArray.h>
39 #include <CoreFoundation/CFData.h>
40 #include <CoreFoundation/CFDictionary.h>
41 #include <CoreFoundation/CFSet.h>
42 #include <CoreFoundation/CFPriv.h>
43 #include <CoreFoundation/CFPropertyList.h>
44 #include <CoreFoundation/CFError.h>
45 #include <CoreFoundation/CFStringEncodingExt.h>
48 // NOTE: miscellaneous declarations are at the end
50 // ---- CFRuntime material ----------------------------------------
54 #if DEPLOYMENT_TARGET_LINUX
56 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
57 #include <malloc/malloc.h>
62 // ---- CFBundle material ----------------------------------------
64 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
65 #include <CoreFoundation/CFBundlePriv.h>
69 CF_EXPORT
const CFStringRef _kCFBundleExecutablePathKey
;
70 CF_EXPORT
const CFStringRef _kCFBundleInfoPlistURLKey
;
71 CF_EXPORT
const CFStringRef _kCFBundleRawInfoPlistURLKey
;
72 CF_EXPORT
const CFStringRef _kCFBundleNumericVersionKey
;
73 CF_EXPORT
const CFStringRef _kCFBundleResourcesFileMappedKey
;
74 CF_EXPORT
const CFStringRef _kCFBundleAllowMixedLocalizationsKey
;
75 CF_EXPORT
const CFStringRef _kCFBundleInitialPathKey
;
76 CF_EXPORT
const CFStringRef _kCFBundleResolvedPathKey
;
77 CF_EXPORT
const CFStringRef _kCFBundlePrincipalClassKey
;
80 CF_EXPORT CFArrayRef
_CFFindBundleResources(CFBundleRef bundle
, CFURLRef bundleURL
, CFStringRef subDirName
, CFArrayRef searchLanguages
, CFStringRef resName
, CFArrayRef resTypes
, CFIndex limit
, Boolean (^predicate
)(CFStringRef filename
, Boolean
*stop
), UInt8 version
);
81 // new look up algorithm is in place (look for CFBUNDLE_NEWLOOKUP)
82 CF_EXPORT CFTypeRef
_CFBundleCopyFindResources(CFBundleRef bundle
, CFURLRef bundleURL
, CFArrayRef languages
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subPath
, CFStringRef lproj
, Boolean returnArray
, Boolean localized
, Boolean (^predicate
)(CFStringRef filename
, Boolean
*stop
));
85 CF_EXPORT UInt8
_CFBundleLayoutVersion(CFBundleRef bundle
);
87 CF_EXPORT CFArrayRef
_CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc
, CFURLRef url
, UInt8
*version
);
88 CF_EXPORT CFArrayRef
_CFBundleGetLanguageSearchList(CFBundleRef bundle
);
90 CF_EXPORT Boolean
_CFBundleLoadExecutableAndReturnError(CFBundleRef bundle
, Boolean forceGlobal
, CFErrorRef
*error
);
91 CF_EXPORT CFErrorRef
_CFBundleCreateError(CFAllocatorRef allocator
, CFBundleRef bundle
, CFIndex code
);
97 // ---- CFPreferences material ----------------------------------------
99 #define DEBUG_PREFERENCES_MEMORY 0
101 #if DEBUG_PREFERENCES_MEMORY
102 #include "../Tests/CFCountingAllocator.h"
107 extern void _CFPreferencesPurgeDomainCache(void);
110 void * (*createDomain
)(CFAllocatorRef allocator
, CFTypeRef context
);
111 void (*freeDomain
)(CFAllocatorRef allocator
, CFTypeRef context
, void *domain
);
112 CFTypeRef (*fetchValue
)(CFTypeRef context
, void *domain
, CFStringRef key
); // Caller releases
113 void (*writeValue
)(CFTypeRef context
, void *domain
, CFStringRef key
, CFTypeRef value
);
114 Boolean (*synchronize
)(CFTypeRef context
, void *domain
);
115 void (*getKeysAndValues
)(CFAllocatorRef alloc
, CFTypeRef context
, void *domain
, void **buf
[], CFIndex
*numKeyValuePairs
);
116 CFDictionaryRef (*copyDomainDictionary
)(CFTypeRef context
, void *domain
);
117 /* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
118 void (*setIsWorldReadable
)(CFTypeRef context
, void *domain
, Boolean isWorldReadable
);
119 } _CFPreferencesDomainCallBacks
;
121 CF_EXPORT CFAllocatorRef
__CFPreferencesAllocator(void);
122 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks
;
123 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks
;
125 typedef struct __CFPreferencesDomain
* CFPreferencesDomainRef
;
127 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesDomainCreate(CFTypeRef context
, const _CFPreferencesDomainCallBacks
*callBacks
);
128 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesStandardDomain(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
130 CF_EXPORT CFTypeRef
_CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain
, CFStringRef key
);
131 CF_EXPORT
void _CFPreferencesDomainSet(CFPreferencesDomainRef domain
, CFStringRef key
, CFTypeRef value
);
132 CF_EXPORT Boolean
_CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain
);
134 CF_EXPORT CFArrayRef
_CFPreferencesCreateDomainList(CFStringRef userName
, CFStringRef hostName
);
135 CF_EXPORT Boolean
_CFSynchronizeDomainCache(void);
137 CF_EXPORT
void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain
, CFDictionaryRef dict
);
138 CF_EXPORT CFDictionaryRef
_CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain
);
139 CF_EXPORT Boolean
_CFPreferencesDomainExists(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
141 /* 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 */
142 CF_EXPORT
void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain
, Boolean isWorldReadable
);
145 CFMutableArrayRef _search
; // the search list; an array of _CFPreferencesDomains
146 CFMutableDictionaryRef _dictRep
; // Mutable; a collapsed view of the search list, expressed as a single dictionary
147 CFStringRef _appName
;
148 } _CFApplicationPreferences
;
150 CF_EXPORT _CFApplicationPreferences
*_CFStandardApplicationPreferences(CFStringRef appName
);
151 CF_EXPORT _CFApplicationPreferences
*_CFApplicationPreferencesCreateWithUser(CFStringRef userName
, CFStringRef appName
);
152 CF_EXPORT
void _CFDeallocateApplicationPreferences(_CFApplicationPreferences
*self
);
153 CF_EXPORT CFTypeRef
_CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences
*prefs
, CFStringRef key
);
154 CF_EXPORT
void _CFApplicationPreferencesSet(_CFApplicationPreferences
*self
, CFStringRef defaultName
, CFTypeRef value
);
155 CF_EXPORT
void _CFApplicationPreferencesRemove(_CFApplicationPreferences
*self
, CFStringRef defaultName
);
156 CF_EXPORT Boolean
_CFApplicationPreferencesSynchronize(_CFApplicationPreferences
*self
);
157 CF_EXPORT
void _CFApplicationPreferencesUpdate(_CFApplicationPreferences
*self
); // same as updateDictRep
158 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences
*self
, CFDictionaryRef hint
, CFDictionaryRef insertion
, CFPreferencesDomainRef afterDomain
);
159 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences
*self
, CFDictionaryRef hint
); // same as dictRep
160 CF_EXPORT
void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences
*appPreferences
);
161 CF_EXPORT
void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences
*appPrefs
, CFStringRef appName
);
162 CF_EXPORT
void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
163 CF_EXPORT
void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
165 CF_EXPORT
void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
, Boolean addAtTop
);
166 CF_EXPORT Boolean
_CFApplicationPreferencesContainsDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
167 CF_EXPORT
void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
169 CF_EXPORT CFTypeRef
_CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef stopper
, CFStringRef key
);
176 // ---- CFString material ----------------------------------------
178 #include <CoreFoundation/CFStringEncodingExt.h>
182 /* Create a byte stream from a CFString backing. Can convert a string piece at a
183 time into a fixed size buffer. Returns number of characters converted.
184 Characters that cannot be converted to the specified encoding are represented
185 with the char specified by lossByte; if 0, then lossy conversion is not allowed
186 and conversion stops, returning partial results.
187 generatingExternalFile indicates that any extra stuff to allow this data to be
188 persistent (for instance, BOM) should be included.
189 Pass buffer==NULL if you don't care about the converted string (but just the
190 convertability, or number of bytes required, indicated by usedBufLen).
191 Does not zero-terminate. If you want to create Pascal or C string, allow one
192 extra byte at start or end.
194 CF_EXPORT CFIndex
__CFStringEncodeByteStream(CFStringRef string
, CFIndex rangeLoc
, CFIndex rangeLen
, Boolean generatingExternalFile
, CFStringEncoding encoding
, char lossByte
, UInt8
*buffer
, CFIndex max
, CFIndex
*usedBufLen
);
196 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
);
198 CF_EXPORT
void __CFStringAppendBytes(CFMutableStringRef str
, const char *cStr
, CFIndex appendedLength
, CFStringEncoding encoding
);
200 CF_INLINE Boolean
__CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding
) {
201 switch (encoding
& 0x0000FF00) {
202 case 0x0: // MacOS Script range
203 // Symbol & bidi encodings are not ASCII superset
204 if (encoding
== kCFStringEncodingMacJapanese
|| encoding
== kCFStringEncodingMacArabic
|| encoding
== kCFStringEncodingMacHebrew
|| encoding
== kCFStringEncodingMacUkrainian
|| encoding
== kCFStringEncodingMacSymbol
|| encoding
== kCFStringEncodingMacDingbats
) return false;
207 case 0x100: // Unicode range
208 if (encoding
!= kCFStringEncodingUTF8
) return false;
211 case 0x200: // ISO range
212 if (encoding
== kCFStringEncodingISOLatinArabic
) return false;
215 case 0x600: // National standards range
216 if (encoding
!= kCFStringEncodingASCII
) return false;
219 case 0x800: // ISO 2022 range
220 return false; // It's modal encoding
222 case 0xA00: // Misc standard range
223 if ((encoding
== kCFStringEncodingShiftJIS
) || (encoding
== kCFStringEncodingHZ_GB_2312
) || (encoding
== kCFStringEncodingUTF7_IMAP
)) return false;
227 if (encoding
== kCFStringEncodingNonLossyASCII
) return false;
230 case 0xC00: // EBCDIC
234 return ((encoding
& 0x0000FF00) > 0x0C00 ? false : true);
239 /* Desperately using extern here */
240 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding
;
241 CF_EXPORT CFStringEncoding
__CFStringComputeEightBitStringEncoding(void);
243 CF_INLINE CFStringEncoding
__CFStringGetEightBitStringEncoding(void) {
244 if (__CFDefaultEightBitStringEncoding
== kCFStringEncodingInvalidId
) __CFStringComputeEightBitStringEncoding();
245 return __CFDefaultEightBitStringEncoding
;
249 __kCFVarWidthLocalBufferSize
= 1008
252 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
257 Boolean isASCII
; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
258 Boolean shouldFreeChars
; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
261 CFAllocatorRef allocator
; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
262 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 */
263 UInt8 localBuffer
[__kCFVarWidthLocalBufferSize
]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
264 } CFVarWidthCharBuffer
;
267 /* 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.
268 !!! 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.
269 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
271 CF_EXPORT Boolean
__CFStringDecodeByteStream2(const UInt8
*bytes
, UInt32 len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
);
272 CF_EXPORT Boolean
__CFStringDecodeByteStream3(const UInt8
*bytes
, CFIndex len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
, UInt32 converterFlags
);
275 /* 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.
277 CF_EXPORT
Boolean (*__CFCharToUniCharFunc
)(UInt32 flags
, UInt8 ch
, UniChar
*unicodeChar
);
279 /* Character class functions UnicodeData-2_1_5.txt
281 CF_INLINE Boolean
__CFIsWhitespace(UniChar theChar
) {
282 return ((theChar
< 0x21) || (theChar
> 0x7E && theChar
< 0xA1) || (theChar
>= 0x2000 && theChar
<= 0x200B) || (theChar
== 0x3000)) ? true : false;
285 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
287 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer
*buf
, CFIndex idx
) {
288 if (buf
->directBuffer
) {
289 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
290 return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
292 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
293 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
294 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
295 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
296 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
297 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
299 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
302 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
304 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer
*buf
, CFIndex idx
) {
305 if (buf
->directBuffer
) return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
306 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
307 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
308 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
309 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
310 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
312 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
316 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
318 CF_EXPORT
void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
);
319 CF_EXPORT CFStringRef
_CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef format
, va_list arguments
);
321 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
323 enum {_CFStringErrNone
= 0, _CFStringErrNotMutable
= 1, _CFStringErrNilArg
= 2, _CFStringErrBounds
= 3};
324 CF_EXPORT
int __CFStringCheckAndReplace(CFMutableStringRef str
, CFRange range
, CFStringRef replacement
);
325 CF_EXPORT Boolean
__CFStringNoteErrors(void); // Should string errors raise?
327 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
329 CF_EXPORT Boolean
__CFStringIsEightBit(CFStringRef str
);
331 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
333 CF_EXPORT
int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str
, CFIndex idx
, UniChar
*ch
);
334 CF_EXPORT
int _CFStringCheckAndGetCharacters(CFStringRef str
, CFRange range
, UniChar
*buffer
);
335 CF_EXPORT CFIndex
_CFStringGetLength2(CFStringRef str
);
336 CF_EXPORT CFHashCode
__CFStringHash(CFTypeRef cf
);
337 CF_EXPORT CFHashCode
CFStringHashISOLatin1CString(const uint8_t *bytes
, CFIndex len
);
338 CF_EXPORT CFHashCode
CFStringHashCString(const uint8_t *bytes
, CFIndex len
);
339 CF_EXPORT CFHashCode
CFStringHashCharacters(const UniChar
*characters
, CFIndex len
);
340 CF_EXPORT CFHashCode
CFStringHashNSString(CFStringRef str
);
346 // ---- Binary plist material ----------------------------------------
348 typedef const struct __CFKeyedArchiverUID
* CFKeyedArchiverUIDRef
;
349 CF_EXPORT CFTypeID
_CFKeyedArchiverUIDGetTypeID(void);
350 CF_EXPORT CFKeyedArchiverUIDRef
_CFKeyedArchiverUIDCreate(CFAllocatorRef allocator
, uint32_t value
);
351 CF_EXPORT
uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid
);
355 kCFBinaryPlistMarkerNull
= 0x00,
356 kCFBinaryPlistMarkerFalse
= 0x08,
357 kCFBinaryPlistMarkerTrue
= 0x09,
358 kCFBinaryPlistMarkerFill
= 0x0F,
359 kCFBinaryPlistMarkerInt
= 0x10,
360 kCFBinaryPlistMarkerReal
= 0x20,
361 kCFBinaryPlistMarkerDate
= 0x33,
362 kCFBinaryPlistMarkerData
= 0x40,
363 kCFBinaryPlistMarkerASCIIString
= 0x50,
364 kCFBinaryPlistMarkerUnicode16String
= 0x60,
365 kCFBinaryPlistMarkerUID
= 0x80,
366 kCFBinaryPlistMarkerArray
= 0xA0,
367 kCFBinaryPlistMarkerSet
= 0xC0,
368 kCFBinaryPlistMarkerDict
= 0xD0
374 } CFBinaryPlistHeader
;
378 uint8_t _sortVersion
;
379 uint8_t _offsetIntSize
;
380 uint8_t _objectRefSize
;
381 uint64_t _numObjects
;
383 uint64_t _offsetTableOffset
;
384 } CFBinaryPlistTrailer
;
387 CF_EXPORT
bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes
, uint64_t datalen
, uint8_t *marker
, uint64_t *offset
, CFBinaryPlistTrailer
*trailer
);
388 CF_EXPORT
bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFIndex idx
, uint64_t *offset
, CFMutableDictionaryRef objects
);
389 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
);
390 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
);
391 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStream(CFPropertyListRef plist
, CFTypeRef stream
);
392 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithEstimate(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
); // will be removed soon
393 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithOptions(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
); // will be removed soon
394 CF_EXPORT CFIndex
__CFBinaryPlistWrite(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
, CFErrorRef
*error
);
396 // ---- Used by property list parsing in Foundation
398 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLData(CFAllocatorRef allocator
, CFDataRef xmlData
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
400 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLString(CFAllocatorRef allocator
, CFStringRef xmlString
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
402 // ---- Sudden Termination material ----------------------------------------
404 #if DEPLOYMENT_TARGET_MACOSX
406 CF_EXPORT
void _CFSuddenTerminationDisable(void);
407 CF_EXPORT
void _CFSuddenTerminationEnable(void);
408 CF_EXPORT
void _CFSuddenTerminationExitIfTerminationEnabled(int exitStatus
);
409 CF_EXPORT
void _CFSuddenTerminationExitWhenTerminationEnabled(int exitStatus
);
410 CF_EXPORT
size_t _CFSuddenTerminationDisablingCount(void);
414 // ---- Thread-specific data --------------------------------------------
416 // Get some thread specific data from a pre-assigned slot.
417 CF_EXPORT
void *_CFGetTSD(uint32_t slot
);
419 // Set some thread specific data in a pre-assigned slot. Don't pick a random value. Make sure you're using a slot that is unique. Pass in a destructor to free this data, or NULL if none is needed. Unlike pthread TSD, the destructor is per-thread.
420 CF_EXPORT
void *_CFSetTSD(uint32_t slot
, void *newVal
, void (*destructor
)(void *));
422 #if DEPLOYMENT_TARGET_WINDOWS
423 // ---- Windows-specific material ---------------------------------------
425 // These are replacements for POSIX calls on Windows, ensuring that the UTF8 parameters are converted to UTF16 before being passed to Windows
426 CF_EXPORT
int _NS_stat(const char *name
, struct _stat
*st
);
427 CF_EXPORT
int _NS_mkdir(const char *name
);
428 CF_EXPORT
int _NS_rmdir(const char *name
);
429 CF_EXPORT
int _NS_chmod(const char *name
, int mode
);
430 CF_EXPORT
int _NS_unlink(const char *name
);
431 CF_EXPORT
char *_NS_getcwd(char *dstbuf
, size_t size
); // Warning: this doesn't support dstbuf as null even though 'getcwd' does
432 CF_EXPORT
char *_NS_getenv(const char *name
);
433 CF_EXPORT
int _NS_rename(const char *oldName
, const char *newName
);
434 CF_EXPORT
int _NS_open(const char *name
, int oflag
, int pmode
);
435 CF_EXPORT
int _NS_mkstemp(char *name
, int bufSize
);
438 // ---- Miscellaneous material ----------------------------------------
440 #include <CoreFoundation/CFBag.h>
441 #include <CoreFoundation/CFSet.h>
446 CF_EXPORT CFTypeID
CFTypeGetTypeID(void);
448 CF_EXPORT
void _CFArraySetCapacity(CFMutableArrayRef array
, CFIndex cap
);
449 CF_EXPORT
void _CFBagSetCapacity(CFMutableBagRef bag
, CFIndex cap
);
450 CF_EXPORT
void _CFDictionarySetCapacity(CFMutableDictionaryRef dict
, CFIndex cap
);
451 CF_EXPORT
void _CFSetSetCapacity(CFMutableSetRef set
, CFIndex cap
);
453 CF_EXPORT
void CFCharacterSetCompact(CFMutableCharacterSetRef theSet
);
454 CF_EXPORT
void CFCharacterSetFast(CFMutableCharacterSetRef theSet
);
456 CF_EXPORT
const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array
, CFIndex idx
);
457 CF_EXPORT
void _CFArrayReplaceValues(CFMutableArrayRef array
, CFRange range
, const void **newValues
, CFIndex newCount
);
461 Call CFStartSearchPathEnumeration() once, then call
462 CFGetNextSearchPathEnumeration() one or more times with the returned state.
463 The return value of CFGetNextSearchPathEnumeration() should be used as
464 the state next time around.
465 When CFGetNextSearchPathEnumeration() returns 0, you're done.
467 typedef CFIndex CFSearchPathEnumerationState
;
468 CF_EXPORT CFSearchPathEnumerationState
__CFStartSearchPathEnumeration(CFSearchPathDirectory dir
, CFSearchPathDomainMask domainMask
);
469 CF_EXPORT CFSearchPathEnumerationState
__CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state
, UInt8
*path
, CFIndex pathSize
);
471 /* For use by NSNumber and CFNumber.
472 Hashing algorithm for CFNumber:
473 M = Max CFHashCode (assumed to be unsigned)
474 For positive integral values: (N * HASHFACTOR) mod M
475 For negative integral values: ((-N) * HASHFACTOR) mod M
476 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
477 HASHFACTOR is 2654435761, from Knuth's multiplicative method
479 #define HASHFACTOR 2654435761U
481 CF_INLINE CFHashCode
_CFHashInt(long i
) {
482 return ((i
> 0) ? (CFHashCode
)(i
) : (CFHashCode
)(-i
)) * HASHFACTOR
;
485 CF_INLINE CFHashCode
_CFHashDouble(double d
) {
489 CFHashCode integralHash
= HASHFACTOR
* (CFHashCode
)fmod(dInt
, (double)ULONG_MAX
);
490 return (CFHashCode
)(integralHash
+ (CFHashCode
)((d
- dInt
) * ULONG_MAX
));
494 /* 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.
496 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedDescription(CFErrorRef err
);
497 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedFailureReason(CFErrorRef err
);
498 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err
);
499 CF_EXPORT CFStringRef
_CFErrorCreateDebugDescription(CFErrorRef err
);
501 CF_EXPORT CFURLRef
_CFURLAlloc(CFAllocatorRef allocator
);
502 CF_EXPORT
void _CFURLInitWithString(CFURLRef url
, CFStringRef string
, CFURLRef baseURL
);
503 CF_EXPORT
void _CFURLInitFSPath(CFURLRef url
, CFStringRef path
);
504 CF_EXPORT Boolean
_CFStringIsLegalURLString(CFStringRef string
);
505 CF_EXPORT
void *__CFURLReservedPtr(CFURLRef url
);
506 CF_EXPORT
void __CFURLSetReservedPtr(CFURLRef url
, void *ptr
);
507 CF_EXPORT CFStringEncoding
_CFURLGetEncoding(CFURLRef url
);
509 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
510 CF_EXPORT Boolean
_CFRunLoopFinished(CFRunLoopRef rl
, CFStringRef mode
);
513 CF_EXPORT CFIndex
_CFStreamInstanceSize(void);
515 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
517 mach_vm_address_t address
;
524 } CFDiscorporateMemory
;
526 extern kern_return_t
_CFDiscorporateMemoryAllocate(CFDiscorporateMemory
*hm
, size_t size
, bool purgeable
);
527 extern kern_return_t
_CFDiscorporateMemoryDeallocate(CFDiscorporateMemory
*hm
);
528 extern kern_return_t
_CFDiscorporateMemoryDematerialize(CFDiscorporateMemory
*hm
);
529 extern kern_return_t
_CFDiscorporateMemoryMaterialize(CFDiscorporateMemory
*hm
);
533 kCFNumberFormatterOrdinalStyle
= 6,
534 kCFNumberFormatterDurationStyle
= 7,
537 CF_EXPORT CFRange
_CFDataFindBytes(CFDataRef data
, CFDataRef dataToFind
, CFRange searchRange
, CFDataSearchFlags compareOptions
);
540 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
541 #if !defined(__CFReadTSR)
542 #include <mach/mach_time.h>
543 #define __CFReadTSR() mach_absolute_time()
545 #elif DEPLOYMENT_TARGET_WINDOWS
547 CF_INLINE UInt64
__CFReadTSR(void) {
549 QueryPerformanceCounter(&freq
);
550 return freq
.QuadPart
;
558 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */