]> git.saurik.com Git - apple/cf.git/blob - ForFoundationOnly.h
CF-744.12.tar.gz
[apple/cf.git] / ForFoundationOnly.h
1 /*
2 * Copyright (c) 2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* ForFoundationOnly.h
25 Copyright (c) 1998-2012, Apple Inc. All rights reserved.
26 */
27
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.
31 #endif
32
33 #if !defined(__COREFOUNDATION_FORFOUNDATIONONLY__)
34 #define __COREFOUNDATION_FORFOUNDATIONONLY__ 1
35
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 <limits.h>
47
48 // NOTE: miscellaneous declarations are at the end
49
50 // ---- CFRuntime material ----------------------------------------
51
52 CF_EXTERN_C_BEGIN
53
54 #if DEPLOYMENT_TARGET_LINUX
55 #include <malloc.h>
56 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
57 #include <malloc/malloc.h>
58 #endif
59
60 CF_EXTERN_C_END
61
62 // ---- CFBundle material ----------------------------------------
63
64 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
65 #include <CoreFoundation/CFBundlePriv.h>
66
67 CF_EXTERN_C_BEGIN
68
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;
78
79 #if __BLOCKS__
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));
83 #endif
84
85 CF_EXPORT UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
86
87 CF_EXPORT CFArrayRef _CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
88 CF_EXPORT CFArrayRef _CFBundleGetLanguageSearchList(CFBundleRef bundle);
89
90 CF_EXPORT Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
91 CF_EXPORT CFErrorRef _CFBundleCreateError(CFAllocatorRef allocator, CFBundleRef bundle, CFIndex code);
92
93 CF_EXTERN_C_END
94
95 #endif
96
97 // ---- CFPreferences material ----------------------------------------
98
99 #define DEBUG_PREFERENCES_MEMORY 0
100
101 #if DEBUG_PREFERENCES_MEMORY
102 #include "../Tests/CFCountingAllocator.h"
103 #endif
104
105 CF_EXTERN_C_BEGIN
106
107 extern void _CFPreferencesPurgeDomainCache(void);
108
109 typedef struct {
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;
120
121 CF_EXPORT CFAllocatorRef __CFPreferencesAllocator(void);
122 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks;
123 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks;
124
125 typedef struct __CFPreferencesDomain * CFPreferencesDomainRef;
126
127 CF_EXPORT CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks);
128 CF_EXPORT CFPreferencesDomainRef _CFPreferencesStandardDomain(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
129
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);
133
134 CF_EXPORT CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName);
135 CF_EXPORT Boolean _CFSynchronizeDomainCache(void);
136
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);
140
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);
143
144 typedef struct {
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;
149
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);
164
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);
168
169 CF_EXPORT CFTypeRef _CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef stopper, CFStringRef key);
170
171
172 CF_EXTERN_C_END
173
174
175
176 // ---- CFString material ----------------------------------------
177
178 #include <CoreFoundation/CFStringEncodingExt.h>
179
180 CF_EXTERN_C_BEGIN
181
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.
193 */
194 CF_EXPORT CFIndex __CFStringEncodeByteStream(CFStringRef string, CFIndex rangeLoc, CFIndex rangeLen, Boolean generatingExternalFile, CFStringEncoding encoding, char lossByte, UInt8 *buffer, CFIndex max, CFIndex *usedBufLen);
195
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);
197
198 CF_EXPORT void __CFStringAppendBytes(CFMutableStringRef str, const char *cStr, CFIndex appendedLength, CFStringEncoding encoding);
199
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;
205 return true;
206
207 case 0x100: // Unicode range
208 if (encoding != kCFStringEncodingUTF8) return false;
209 return true;
210
211 case 0x200: // ISO range
212 if (encoding == kCFStringEncodingISOLatinArabic) return false;
213 return true;
214
215 case 0x600: // National standards range
216 if (encoding != kCFStringEncodingASCII) return false;
217 return true;
218
219 case 0x800: // ISO 2022 range
220 return false; // It's modal encoding
221
222 case 0xA00: // Misc standard range
223 if ((encoding == kCFStringEncodingShiftJIS) || (encoding == kCFStringEncodingHZ_GB_2312) || (encoding == kCFStringEncodingUTF7_IMAP)) return false;
224 return true;
225
226 case 0xB00:
227 if (encoding == kCFStringEncodingNonLossyASCII) return false;
228 return true;
229
230 case 0xC00: // EBCDIC
231 return false;
232
233 default:
234 return ((encoding & 0x0000FF00) > 0x0C00 ? false : true);
235 }
236 }
237
238
239 /* Desperately using extern here */
240 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding;
241 CF_EXPORT CFStringEncoding __CFStringComputeEightBitStringEncoding(void);
242
243 CF_INLINE CFStringEncoding __CFStringGetEightBitStringEncoding(void) {
244 if (__CFDefaultEightBitStringEncoding == kCFStringEncodingInvalidId) __CFStringComputeEightBitStringEncoding();
245 return __CFDefaultEightBitStringEncoding;
246 }
247
248 enum {
249 __kCFVarWidthLocalBufferSize = 1008
250 };
251
252 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
253 union {
254 UInt8 *ascii;
255 UniChar *unicode;
256 } chars;
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 */
259 Boolean _unused1;
260 Boolean _unused2;
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;
265
266
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.
270 */
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);
273
274
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.
276 */
277 CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
278
279 /* Character class functions UnicodeData-2_1_5.txt
280 */
281 CF_INLINE Boolean __CFIsWhitespace(UniChar theChar) {
282 return ((theChar < 0x21) || (theChar > 0x7E && theChar < 0xA1) || (theChar >= 0x2000 && theChar <= 0x200B) || (theChar == 0x3000)) ? true : false;
283 }
284
285 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
286 */
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];
291 }
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);
298 }
299 return buf->buffer[idx - buf->bufferedRangeStart];
300 }
301
302 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
303 */
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);
311 }
312 return buf->buffer[idx - buf->bufferedRangeStart];
313 }
314
315
316 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
317 */
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);
320
321 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
322 */
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?
326
327 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
328 */
329 CF_EXPORT Boolean __CFStringIsEightBit(CFStringRef str);
330
331 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
332 */
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);
341
342
343 CF_EXTERN_C_END
344
345
346 // ---- Binary plist material ----------------------------------------
347
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);
352
353
354 enum {
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
369 };
370
371 typedef struct {
372 uint8_t _magic[6];
373 uint8_t _version[2];
374 } CFBinaryPlistHeader;
375
376 typedef struct {
377 uint8_t _unused[5];
378 uint8_t _sortVersion;
379 uint8_t _offsetIntSize;
380 uint8_t _objectRefSize;
381 uint64_t _numObjects;
382 uint64_t _topObject;
383 uint64_t _offsetTableOffset;
384 } CFBinaryPlistTrailer;
385
386
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);
395
396 // ---- Used by property list parsing in Foundation
397
398 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
399
400 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLString(CFAllocatorRef allocator, CFStringRef xmlString, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
401
402 // ---- Sudden Termination material ----------------------------------------
403
404 #if DEPLOYMENT_TARGET_MACOSX
405
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);
411
412 #endif
413
414 // ---- Thread-specific data --------------------------------------------
415
416 // Get some thread specific data from a pre-assigned slot.
417 CF_EXPORT void *_CFGetTSD(uint32_t slot);
418
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 *));
421
422 #if DEPLOYMENT_TARGET_WINDOWS
423 // ---- Windows-specific material ---------------------------------------
424
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);
436 #endif
437
438 // ---- Miscellaneous material ----------------------------------------
439
440 #include <CoreFoundation/CFBag.h>
441 #include <CoreFoundation/CFSet.h>
442 #include <math.h>
443
444 CF_EXTERN_C_BEGIN
445
446 CF_EXPORT CFTypeID CFTypeGetTypeID(void);
447
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);
452
453 CF_EXPORT void CFCharacterSetCompact(CFMutableCharacterSetRef theSet);
454 CF_EXPORT void CFCharacterSetFast(CFMutableCharacterSetRef theSet);
455
456 CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex idx);
457 CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount);
458
459
460 /* Enumeration
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.
466 */
467 typedef CFIndex CFSearchPathEnumerationState;
468 CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
469 CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
470
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
478 */
479 #define HASHFACTOR 2654435761U
480
481 CF_INLINE CFHashCode _CFHashInt(long i) {
482 return ((i > 0) ? (CFHashCode)(i) : (CFHashCode)(-i)) * HASHFACTOR;
483 }
484
485 CF_INLINE CFHashCode _CFHashDouble(double d) {
486 double dInt;
487 if (d < 0) d = -d;
488 dInt = floor(d+0.5);
489 CFHashCode integralHash = HASHFACTOR * (CFHashCode)fmod(dInt, (double)ULONG_MAX);
490 return (CFHashCode)(integralHash + (CFHashCode)((d - dInt) * ULONG_MAX));
491 }
492
493
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.
495 */
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);
500
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);
508
509 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
510 CF_EXPORT Boolean _CFRunLoopFinished(CFRunLoopRef rl, CFStringRef mode);
511 #endif
512
513 CF_EXPORT CFIndex _CFStreamInstanceSize(void);
514
515 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
516 typedef struct {
517 mach_vm_address_t address;
518 mach_vm_size_t size;
519 mach_port_t port;
520 bool purgeable;
521 bool corporeal;
522 bool volatyle;
523 uintptr_t reserved;
524 } CFDiscorporateMemory;
525
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);
530 #endif
531
532 enum {
533 kCFNumberFormatterOrdinalStyle = 6,
534 kCFNumberFormatterDurationStyle = 7,
535 };
536
537 CF_EXPORT CFRange _CFDataFindBytes(CFDataRef data, CFDataRef dataToFind, CFRange searchRange, CFDataSearchFlags compareOptions);
538
539
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()
544 #endif
545 #elif DEPLOYMENT_TARGET_WINDOWS
546 #if 0
547 CF_INLINE UInt64 __CFReadTSR(void) {
548 LARGE_INTEGER freq;
549 QueryPerformanceCounter(&freq);
550 return freq.QuadPart;
551 }
552 #endif
553 #endif
554
555
556 CF_EXTERN_C_END
557
558 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */
559