2 * Copyright (c) 2015 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-2014, 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>
46 #include <CoreFoundation/CFNumberFormatter.h>
49 // NOTE: miscellaneous declarations are at the end
51 // ---- CFRuntime material ----------------------------------------
55 #if DEPLOYMENT_TARGET_LINUX
57 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
58 #include <malloc/malloc.h>
63 // ---- CFBundle material ----------------------------------------
65 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
66 #include <CoreFoundation/CFBundlePriv.h>
70 CF_EXPORT
const CFStringRef _kCFBundleExecutablePathKey
;
71 CF_EXPORT
const CFStringRef _kCFBundleInfoPlistURLKey
;
72 CF_EXPORT
const CFStringRef _kCFBundleRawInfoPlistURLKey
;
73 CF_EXPORT
const CFStringRef _kCFBundleNumericVersionKey
;
74 CF_EXPORT
const CFStringRef _kCFBundleResourcesFileMappedKey
;
75 CF_EXPORT
const CFStringRef _kCFBundleAllowMixedLocalizationsKey
;
76 CF_EXPORT
const CFStringRef _kCFBundleInitialPathKey
;
77 CF_EXPORT
const CFStringRef _kCFBundleResolvedPathKey
;
78 CF_EXPORT
const CFStringRef _kCFBundlePrincipalClassKey
;
81 CF_EXPORT CFTypeRef
_CFBundleCopyFindResources(CFBundleRef bundle
, CFURLRef bundleURL
, CFArrayRef _unused_pass_null_
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subPath
, CFStringRef lproj
, Boolean returnArray
, Boolean localized
, Boolean (^predicate
)(CFStringRef filename
, Boolean
*stop
));
84 CF_EXPORT Boolean
_CFBundleLoadExecutableAndReturnError(CFBundleRef bundle
, Boolean forceGlobal
, CFErrorRef
*error
);
85 CF_EXPORT CFErrorRef
_CFBundleCreateError(CFAllocatorRef allocator
, CFBundleRef bundle
, CFIndex code
);
91 // ---- CFPreferences material ----------------------------------------
93 #define DEBUG_PREFERENCES_MEMORY 0
95 #if DEBUG_PREFERENCES_MEMORY
96 #include "../Tests/CFCountingAllocator.h"
101 extern void _CFPreferencesPurgeDomainCache(void);
104 void * (*createDomain
)(CFAllocatorRef allocator
, CFTypeRef context
);
105 void (*freeDomain
)(CFAllocatorRef allocator
, CFTypeRef context
, void *domain
);
106 CFTypeRef (*fetchValue
)(CFTypeRef context
, void *domain
, CFStringRef key
); // Caller releases
107 void (*writeValue
)(CFTypeRef context
, void *domain
, CFStringRef key
, CFTypeRef value
);
108 Boolean (*synchronize
)(CFTypeRef context
, void *domain
);
109 void (*getKeysAndValues
)(CFAllocatorRef alloc
, CFTypeRef context
, void *domain
, void **buf
[], CFIndex
*numKeyValuePairs
);
110 CFDictionaryRef (*copyDomainDictionary
)(CFTypeRef context
, void *domain
);
111 /* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
112 void (*setIsWorldReadable
)(CFTypeRef context
, void *domain
, Boolean isWorldReadable
);
113 } _CFPreferencesDomainCallBacks
;
115 CF_EXPORT CFAllocatorRef
__CFPreferencesAllocator(void);
116 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks
;
117 CF_EXPORT
const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks
;
119 typedef struct __CFPreferencesDomain
* CFPreferencesDomainRef
;
121 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesDomainCreate(CFTypeRef context
, const _CFPreferencesDomainCallBacks
*callBacks
);
122 CF_EXPORT CFPreferencesDomainRef
_CFPreferencesStandardDomain(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
124 CF_EXPORT CFTypeRef
_CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain
, CFStringRef key
);
125 CF_EXPORT
void _CFPreferencesDomainSet(CFPreferencesDomainRef domain
, CFStringRef key
, CFTypeRef value
);
126 CF_EXPORT Boolean
_CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain
);
128 CF_EXPORT CFArrayRef
_CFPreferencesCreateDomainList(CFStringRef userName
, CFStringRef hostName
);
129 CF_EXPORT Boolean
_CFSynchronizeDomainCache(void);
131 CF_EXPORT
void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain
, CFDictionaryRef dict
);
132 CF_EXPORT CFDictionaryRef
_CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain
);
133 CF_EXPORT Boolean
_CFPreferencesDomainExists(CFStringRef domainName
, CFStringRef userName
, CFStringRef hostName
);
135 /* 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 */
136 CF_EXPORT
void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain
, Boolean isWorldReadable
);
139 CFMutableArrayRef _search
; // the search list; an array of _CFPreferencesDomains
140 CFMutableDictionaryRef _dictRep
; // Mutable; a collapsed view of the search list, expressed as a single dictionary
141 CFStringRef _appName
;
142 } _CFApplicationPreferences
;
144 CF_EXPORT _CFApplicationPreferences
*_CFStandardApplicationPreferences(CFStringRef appName
);
145 CF_EXPORT _CFApplicationPreferences
*_CFApplicationPreferencesCreateWithUser(CFStringRef userName
, CFStringRef appName
);
146 CF_EXPORT
void _CFDeallocateApplicationPreferences(_CFApplicationPreferences
*self
);
147 CF_EXPORT CFTypeRef
_CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences
*prefs
, CFStringRef key
);
148 CF_EXPORT
void _CFApplicationPreferencesSet(_CFApplicationPreferences
*self
, CFStringRef defaultName
, CFTypeRef value
);
149 CF_EXPORT
void _CFApplicationPreferencesRemove(_CFApplicationPreferences
*self
, CFStringRef defaultName
);
150 CF_EXPORT Boolean
_CFApplicationPreferencesSynchronize(_CFApplicationPreferences
*self
);
151 CF_EXPORT
void _CFApplicationPreferencesUpdate(_CFApplicationPreferences
*self
); // same as updateDictRep
152 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences
*self
, CFDictionaryRef hint
, CFDictionaryRef insertion
, CFPreferencesDomainRef afterDomain
);
153 CF_EXPORT CFDictionaryRef
_CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences
*self
, CFDictionaryRef hint
); // same as dictRep
154 CF_EXPORT
void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences
*appPreferences
);
155 CF_EXPORT
void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences
*appPrefs
, CFStringRef appName
);
156 CF_EXPORT
void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
157 CF_EXPORT
void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences
*appPrefs
, CFStringRef suiteName
);
159 CF_EXPORT
void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
, Boolean addAtTop
);
160 CF_EXPORT Boolean
_CFApplicationPreferencesContainsDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
161 CF_EXPORT
void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef domain
);
163 CF_EXPORT CFTypeRef
_CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences
*self
, CFPreferencesDomainRef stopper
, CFStringRef key
);
170 // ---- CFString material ----------------------------------------
172 #include <CoreFoundation/CFStringEncodingExt.h>
174 #define NSSTRING_BOUNDSERROR \
175 [NSException raise:NSRangeException format:@"%@: Range or index out of bounds", __CFExceptionProem((id)self, _cmd)]
177 #define NSSTRING_RANGEERROR(range, len) \
178 [NSException raise:NSRangeException format:@"%@: Range {%lu, %lu} out of bounds; string length %lu", __CFExceptionProem((id)self, _cmd), (unsigned long)range.location, (unsigned long)range.length, (unsigned long)len]
180 #define NSSTRING_INDEXERROR(index, len) \
181 [NSException raise:NSRangeException format:@"%@: Index %lu out of bounds; string length %lu", __CFExceptionProem((id)self, _cmd), (unsigned long)index, (unsigned long)len]
183 // This can be made into an exception for post-10.10 apps
184 #define NSSTRING_POSSIBLE_RANGEERROR(range, len) \
185 if (__CFStringNoteErrors()) { \
186 static bool warnonce = false; \
189 CFLog(kCFLogLevelWarning, CFSTR("*** %@: Range {%lu, %lu} out of bounds; string length %lu. This will become an exception for apps linked after 10.10 and iOS 8. Warning shown once per app execution."), __CFExceptionProem((id)self, _cmd), (unsigned long)range.location, (unsigned long)range.length, (unsigned long)len); \
193 #define NSSTRING_ILLEGALREQUESTERROR \
194 [NSException raise:NSInvalidArgumentException format:@"Can't call %s in %@", sel_getName(_cmd), object_getClass((id)self)]
196 #define NSSTRING_INVALIDMUTATIONERROR \
197 [NSException raise:NSInvalidArgumentException format:@"Attempt to mutate immutable object with %s", sel_getName(_cmd)]
199 #define NSSTRING_NULLCSTRINGERROR \
200 [NSException raise:NSInvalidArgumentException format:@"%@: NULL cString", __CFExceptionProem((id)self, _cmd)]
202 #define NSSTRING_NILSTRINGERROR \
203 [NSException raise:NSInvalidArgumentException format:@"%@: nil argument", __CFExceptionProem((id)self, _cmd)]
208 /* Create a byte stream from a CFString backing. Can convert a string piece at a
209 time into a fixed size buffer. Returns number of characters converted.
210 Characters that cannot be converted to the specified encoding are represented
211 with the char specified by lossByte; if 0, then lossy conversion is not allowed
212 and conversion stops, returning partial results.
213 generatingExternalFile indicates that any extra stuff to allow this data to be
214 persistent (for instance, BOM) should be included.
215 Pass buffer==NULL if you don't care about the converted string (but just the
216 convertability, or number of bytes required, indicated by usedBufLen).
217 Does not zero-terminate. If you want to create Pascal or C string, allow one
218 extra byte at start or end.
220 CF_EXPORT CFIndex
__CFStringEncodeByteStream(CFStringRef string
, CFIndex rangeLoc
, CFIndex rangeLen
, Boolean generatingExternalFile
, CFStringEncoding encoding
, char lossByte
, UInt8
*buffer
, CFIndex max
, CFIndex
*usedBufLen
);
222 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
);
224 CF_EXPORT
void __CFStringAppendBytes(CFMutableStringRef str
, const char *cStr
, CFIndex appendedLength
, CFStringEncoding encoding
);
226 CF_INLINE Boolean
__CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding
) {
227 switch (encoding
& 0x0000FF00) {
228 case 0x0: // MacOS Script range
229 // Symbol & bidi encodings are not ASCII superset
230 if (encoding
== kCFStringEncodingMacJapanese
|| encoding
== kCFStringEncodingMacArabic
|| encoding
== kCFStringEncodingMacHebrew
|| encoding
== kCFStringEncodingMacUkrainian
|| encoding
== kCFStringEncodingMacSymbol
|| encoding
== kCFStringEncodingMacDingbats
) return false;
233 case 0x100: // Unicode range
234 if (encoding
!= kCFStringEncodingUTF8
) return false;
237 case 0x200: // ISO range
238 if (encoding
== kCFStringEncodingISOLatinArabic
) return false;
241 case 0x600: // National standards range
242 if (encoding
!= kCFStringEncodingASCII
) return false;
245 case 0x800: // ISO 2022 range
246 return false; // It's modal encoding
248 case 0xA00: // Misc standard range
249 if ((encoding
== kCFStringEncodingShiftJIS
) || (encoding
== kCFStringEncodingHZ_GB_2312
) || (encoding
== kCFStringEncodingUTF7_IMAP
)) return false;
253 if (encoding
== kCFStringEncodingNonLossyASCII
) return false;
256 case 0xC00: // EBCDIC
260 return ((encoding
& 0x0000FF00) > 0x0C00 ? false : true);
265 /* Desperately using extern here */
266 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding
;
267 CF_EXPORT CFStringEncoding
__CFStringComputeEightBitStringEncoding(void);
269 CF_INLINE CFStringEncoding
__CFStringGetEightBitStringEncoding(void) {
270 if (__CFDefaultEightBitStringEncoding
== kCFStringEncodingInvalidId
) __CFStringComputeEightBitStringEncoding();
271 return __CFDefaultEightBitStringEncoding
;
275 __kCFVarWidthLocalBufferSize
= 1008
278 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
283 Boolean isASCII
; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
284 Boolean shouldFreeChars
; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
287 CFAllocatorRef allocator
; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
288 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 */
289 UInt8 localBuffer
[__kCFVarWidthLocalBufferSize
]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
290 } CFVarWidthCharBuffer
;
293 /* 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.
294 !!! 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.
295 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
297 CF_EXPORT Boolean
__CFStringDecodeByteStream2(const UInt8
*bytes
, UInt32 len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
);
298 CF_EXPORT Boolean
__CFStringDecodeByteStream3(const UInt8
*bytes
, CFIndex len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
, UInt32 converterFlags
);
301 /* 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.
303 CF_EXPORT
Boolean (*__CFCharToUniCharFunc
)(UInt32 flags
, UInt8 ch
, UniChar
*unicodeChar
);
305 /* Character class functions UnicodeData-2_1_5.txt
307 CF_INLINE Boolean
__CFIsWhitespace(UniChar theChar
) {
308 return ((theChar
< 0x21) || (theChar
> 0x7E && theChar
< 0xA1) || (theChar
>= 0x2000 && theChar
<= 0x200B) || (theChar
== 0x3000)) ? true : false;
311 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
313 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer
*buf
, CFIndex idx
) {
314 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
315 if (buf
->directUniCharBuffer
) return buf
->directUniCharBuffer
[idx
+ buf
->rangeToBuffer
.location
];
316 if (buf
->directCStringBuffer
) return (UniChar
)(buf
->directCStringBuffer
[idx
+ buf
->rangeToBuffer
.location
]);
317 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
318 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
319 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
320 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
321 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
323 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
326 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
328 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer
*buf
, CFIndex idx
) {
329 if (buf
->directUniCharBuffer
) return buf
->directUniCharBuffer
[idx
+ buf
->rangeToBuffer
.location
];
330 if (buf
->directCStringBuffer
) return (UniChar
)(buf
->directCStringBuffer
[idx
+ buf
->rangeToBuffer
.location
]);
331 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
332 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
333 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
334 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
335 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
337 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
341 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
343 CF_EXPORT
void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
);
344 CF_EXPORT CFStringRef
_CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFDictionaryRef formatOptions
, CFStringRef format
, va_list arguments
);
346 CF_EXPORT
void _CFStringAppendFormatAndArgumentsAux2(CFMutableStringRef outputString
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFStringRef (*contextDescFunc
)(void *, const void *, const void *, bool, bool *), CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
);
347 CF_EXPORT CFStringRef
_CFStringCreateWithFormatAndArgumentsAux2(CFAllocatorRef alloc
, CFStringRef (*copyDescFunc
)(void *, const void *loc
), CFStringRef (*contextDescFunc
)(void *, const void *, const void *, bool, bool *), CFDictionaryRef formatOptions
, CFStringRef format
, va_list arguments
);
349 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
351 enum {_CFStringErrNone
= 0, _CFStringErrNotMutable
= 1, _CFStringErrNilArg
= 2, _CFStringErrBounds
= 3};
352 CF_EXPORT
int __CFStringCheckAndReplace(CFMutableStringRef str
, CFRange range
, CFStringRef replacement
);
353 CF_EXPORT Boolean
__CFStringNoteErrors(void); // Should string errors raise?
355 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
357 CF_EXPORT Boolean
__CFStringIsEightBit(CFStringRef str
);
359 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
361 CF_EXPORT
int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str
, CFIndex idx
, UniChar
*ch
);
362 CF_EXPORT
int _CFStringCheckAndGetCharacters(CFStringRef str
, CFRange range
, UniChar
*buffer
);
363 CF_EXPORT CFIndex
_CFStringGetLength2(CFStringRef str
);
364 CF_EXPORT CFHashCode
__CFStringHash(CFTypeRef cf
);
365 CF_EXPORT CFHashCode
CFStringHashISOLatin1CString(const uint8_t *bytes
, CFIndex len
);
366 CF_EXPORT CFHashCode
CFStringHashCString(const uint8_t *bytes
, CFIndex len
);
367 CF_EXPORT CFHashCode
CFStringHashCharacters(const UniChar
*characters
, CFIndex len
);
368 CF_EXPORT CFHashCode
CFStringHashNSString(CFStringRef str
);
374 // ---- Binary plist material ----------------------------------------
376 typedef const struct __CFKeyedArchiverUID
* CFKeyedArchiverUIDRef
;
377 CF_EXPORT CFTypeID
_CFKeyedArchiverUIDGetTypeID(void);
378 CF_EXPORT CFKeyedArchiverUIDRef
_CFKeyedArchiverUIDCreate(CFAllocatorRef allocator
, uint32_t value
);
379 CF_EXPORT
uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid
);
383 kCFBinaryPlistMarkerNull
= 0x00,
384 kCFBinaryPlistMarkerFalse
= 0x08,
385 kCFBinaryPlistMarkerTrue
= 0x09,
386 kCFBinaryPlistMarkerFill
= 0x0F,
387 kCFBinaryPlistMarkerInt
= 0x10,
388 kCFBinaryPlistMarkerReal
= 0x20,
389 kCFBinaryPlistMarkerDate
= 0x33,
390 kCFBinaryPlistMarkerData
= 0x40,
391 kCFBinaryPlistMarkerASCIIString
= 0x50,
392 kCFBinaryPlistMarkerUnicode16String
= 0x60,
393 kCFBinaryPlistMarkerUID
= 0x80,
394 kCFBinaryPlistMarkerArray
= 0xA0,
395 kCFBinaryPlistMarkerSet
= 0xC0,
396 kCFBinaryPlistMarkerDict
= 0xD0
402 } CFBinaryPlistHeader
;
406 uint8_t _sortVersion
;
407 uint8_t _offsetIntSize
;
408 uint8_t _objectRefSize
;
409 uint64_t _numObjects
;
411 uint64_t _offsetTableOffset
;
412 } CFBinaryPlistTrailer
;
415 CF_EXPORT
bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes
, uint64_t datalen
, uint8_t *marker
, uint64_t *offset
, CFBinaryPlistTrailer
*trailer
);
416 CF_EXPORT
bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes
, uint64_t datalen
, uint64_t startOffset
, const CFBinaryPlistTrailer
*trailer
, CFIndex idx
, uint64_t *offset
, CFMutableDictionaryRef objects
);
417 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
);
418 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
);
419 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStream(CFPropertyListRef plist
, CFTypeRef stream
);
420 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithEstimate(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
); // will be removed soon
421 CF_EXPORT CFIndex
__CFBinaryPlistWriteToStreamWithOptions(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
); // will be removed soon
422 CF_EXPORT CFIndex
__CFBinaryPlistWrite(CFPropertyListRef plist
, CFTypeRef stream
, uint64_t estimate
, CFOptionFlags options
, CFErrorRef
*error
);
424 // ---- Used by property list parsing in Foundation
426 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLData(CFAllocatorRef allocator
, CFDataRef xmlData
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
428 CF_EXPORT CFTypeRef
_CFPropertyListCreateFromXMLString(CFAllocatorRef allocator
, CFStringRef xmlString
, CFOptionFlags option
, CFStringRef
*errorString
, Boolean allowNewTypes
, CFPropertyListFormat
*format
);
430 // ---- Sudden Termination material ----------------------------------------
432 #if DEPLOYMENT_TARGET_MACOSX
434 CF_EXPORT
void _CFSuddenTerminationDisable(void);
435 CF_EXPORT
void _CFSuddenTerminationEnable(void);
436 CF_EXPORT
void _CFSuddenTerminationExitIfTerminationEnabled(int exitStatus
);
437 CF_EXPORT
void _CFSuddenTerminationExitWhenTerminationEnabled(int exitStatus
);
438 CF_EXPORT
size_t _CFSuddenTerminationDisablingCount(void);
442 // ---- Thread-specific data --------------------------------------------
444 // Get some thread specific data from a pre-assigned slot.
445 CF_EXPORT
void *_CFGetTSD(uint32_t slot
);
447 // 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.
448 CF_EXPORT
void *_CFSetTSD(uint32_t slot
, void *newVal
, void (*destructor
)(void *));
450 #if DEPLOYMENT_TARGET_WINDOWS
451 // ---- Windows-specific material ---------------------------------------
453 // These are replacements for POSIX calls on Windows, ensuring that the UTF8 parameters are converted to UTF16 before being passed to Windows
454 CF_EXPORT
int _NS_stat(const char *name
, struct _stat
*st
);
455 CF_EXPORT
int _NS_mkdir(const char *name
);
456 CF_EXPORT
int _NS_rmdir(const char *name
);
457 CF_EXPORT
int _NS_chmod(const char *name
, int mode
);
458 CF_EXPORT
int _NS_unlink(const char *name
);
459 CF_EXPORT
char *_NS_getcwd(char *dstbuf
, size_t size
); // Warning: this doesn't support dstbuf as null even though 'getcwd' does
460 CF_EXPORT
char *_NS_getenv(const char *name
);
461 CF_EXPORT
int _NS_rename(const char *oldName
, const char *newName
);
462 CF_EXPORT
int _NS_open(const char *name
, int oflag
, int pmode
);
463 CF_EXPORT
int _NS_mkstemp(char *name
, int bufSize
);
466 // ---- Miscellaneous material ----------------------------------------
468 #include <CoreFoundation/CFBag.h>
469 #include <CoreFoundation/CFSet.h>
474 CF_EXPORT CFTypeID
CFTypeGetTypeID(void);
476 CF_EXPORT
void _CFArraySetCapacity(CFMutableArrayRef array
, CFIndex cap
);
477 CF_EXPORT
void _CFBagSetCapacity(CFMutableBagRef bag
, CFIndex cap
);
478 CF_EXPORT
void _CFDictionarySetCapacity(CFMutableDictionaryRef dict
, CFIndex cap
);
479 CF_EXPORT
void _CFSetSetCapacity(CFMutableSetRef set
, CFIndex cap
);
481 CF_EXPORT
void CFCharacterSetCompact(CFMutableCharacterSetRef theSet
);
482 CF_EXPORT
void CFCharacterSetFast(CFMutableCharacterSetRef theSet
);
484 CF_EXPORT
const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array
, CFIndex idx
);
485 CF_EXPORT
void _CFArrayReplaceValues(CFMutableArrayRef array
, CFRange range
, const void **newValues
, CFIndex newCount
);
489 Call CFStartSearchPathEnumeration() once, then call
490 CFGetNextSearchPathEnumeration() one or more times with the returned state.
491 The return value of CFGetNextSearchPathEnumeration() should be used as
492 the state next time around.
493 When CFGetNextSearchPathEnumeration() returns 0, you're done.
495 typedef CFIndex CFSearchPathEnumerationState
;
496 CF_EXPORT CFSearchPathEnumerationState
__CFStartSearchPathEnumeration(CFSearchPathDirectory dir
, CFSearchPathDomainMask domainMask
);
497 CF_EXPORT CFSearchPathEnumerationState
__CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state
, UInt8
*path
, CFIndex pathSize
);
499 /* For use by NSNumber and CFNumber.
500 Hashing algorithm for CFNumber:
501 M = Max CFHashCode (assumed to be unsigned)
502 For positive integral values: (N * HASHFACTOR) mod M
503 For negative integral values: ((-N) * HASHFACTOR) mod M
504 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
505 HASHFACTOR is 2654435761, from Knuth's multiplicative method
507 #define HASHFACTOR 2654435761U
509 CF_INLINE CFHashCode
_CFHashInt(long i
) {
510 return ((i
> 0) ? (CFHashCode
)(i
) : (CFHashCode
)(-i
)) * HASHFACTOR
;
513 CF_INLINE CFHashCode
_CFHashDouble(double d
) {
517 CFHashCode integralHash
= HASHFACTOR
* (CFHashCode
)fmod(dInt
, (double)ULONG_MAX
);
518 return (CFHashCode
)(integralHash
+ (CFHashCode
)((d
- dInt
) * ULONG_MAX
));
522 /* 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.
524 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedDescription(CFErrorRef err
);
525 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedFailureReason(CFErrorRef err
);
526 CF_EXPORT CFStringRef
_CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err
);
527 CF_EXPORT CFStringRef
_CFErrorCreateDebugDescription(CFErrorRef err
);
529 CF_EXPORT
void *__CFURLReservedPtr(CFURLRef url
);
530 CF_EXPORT
void __CFURLSetReservedPtr(CFURLRef url
, void *ptr
);
531 CF_EXPORT CFStringEncoding
_CFURLGetEncoding(CFURLRef url
);
533 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
534 CF_EXPORT Boolean
_CFRunLoopFinished(CFRunLoopRef rl
, CFStringRef mode
);
537 CF_EXPORT CFIndex
_CFStreamInstanceSize(void);
539 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
541 mach_vm_address_t address
;
548 } CFDiscorporateMemory
;
550 extern kern_return_t
_CFDiscorporateMemoryAllocate(CFDiscorporateMemory
*hm
, size_t size
, bool purgeable
);
551 extern kern_return_t
_CFDiscorporateMemoryDeallocate(CFDiscorporateMemory
*hm
);
552 extern kern_return_t
_CFDiscorporateMemoryDematerialize(CFDiscorporateMemory
*hm
);
553 extern kern_return_t
_CFDiscorporateMemoryMaterialize(CFDiscorporateMemory
*hm
);
557 kCFNumberFormatterOrdinalStyle
= 6,
558 kCFNumberFormatterDurationStyle
= 7,
561 // This is for NSNumberFormatter use only!
562 CF_EXPORT
void *_CFNumberFormatterGetFormatter(CFNumberFormatterRef formatter
);
564 CF_EXPORT CFRange
_CFDataFindBytes(CFDataRef data
, CFDataRef dataToFind
, CFRange searchRange
, CFDataSearchFlags compareOptions
);
567 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
568 #if !defined(__CFReadTSR)
569 #include <mach/mach_time.h>
570 #define __CFReadTSR() mach_absolute_time()
572 #elif DEPLOYMENT_TARGET_WINDOWS
574 CF_INLINE UInt64
__CFReadTSR(void) {
576 QueryPerformanceCounter(&freq
);
577 return freq
.QuadPart
;
585 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */