]> git.saurik.com Git - apple/cf.git/blob - ForFoundationOnly.h
CF-635.tar.gz
[apple/cf.git] / ForFoundationOnly.h
1 /*
2 * Copyright (c) 2011 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-2011, 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
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_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 #endif
82
83 CF_EXPORT UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
84
85 CF_EXPORT CFArrayRef _CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
86 CF_EXPORT CFArrayRef _CFBundleGetLanguageSearchList(CFBundleRef bundle);
87
88 CF_EXPORT Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
89 CF_EXPORT CFErrorRef _CFBundleCreateError(CFAllocatorRef allocator, CFBundleRef bundle, CFIndex code);
90
91 CF_EXTERN_C_END
92
93 #endif
94
95 // ---- CFPreferences material ----------------------------------------
96
97 #define DEBUG_PREFERENCES_MEMORY 0
98
99 #if DEBUG_PREFERENCES_MEMORY
100 #include "../Tests/CFCountingAllocator.h"
101 #endif
102
103 CF_EXTERN_C_BEGIN
104
105 extern void _CFPreferencesPurgeDomainCache(void);
106
107 typedef struct {
108 void * (*createDomain)(CFAllocatorRef allocator, CFTypeRef context);
109 void (*freeDomain)(CFAllocatorRef allocator, CFTypeRef context, void *domain);
110 CFTypeRef (*fetchValue)(CFTypeRef context, void *domain, CFStringRef key); // Caller releases
111 void (*writeValue)(CFTypeRef context, void *domain, CFStringRef key, CFTypeRef value);
112 Boolean (*synchronize)(CFTypeRef context, void *domain);
113 void (*getKeysAndValues)(CFAllocatorRef alloc, CFTypeRef context, void *domain, void **buf[], CFIndex *numKeyValuePairs);
114 CFDictionaryRef (*copyDomainDictionary)(CFTypeRef context, void *domain);
115 /* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
116 void (*setIsWorldReadable)(CFTypeRef context, void *domain, Boolean isWorldReadable);
117 } _CFPreferencesDomainCallBacks;
118
119 CF_EXPORT CFAllocatorRef __CFPreferencesAllocator(void);
120 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks;
121 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks;
122
123 typedef struct __CFPreferencesDomain * CFPreferencesDomainRef;
124
125 CF_EXPORT CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks);
126 CF_EXPORT CFPreferencesDomainRef _CFPreferencesStandardDomain(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
127
128 CF_EXPORT CFTypeRef _CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain, CFStringRef key);
129 CF_EXPORT void _CFPreferencesDomainSet(CFPreferencesDomainRef domain, CFStringRef key, CFTypeRef value);
130 CF_EXPORT Boolean _CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain);
131
132 CF_EXPORT CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName);
133 CF_EXPORT Boolean _CFSynchronizeDomainCache(void);
134
135 CF_EXPORT void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain, CFDictionaryRef dict);
136 CF_EXPORT CFDictionaryRef _CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain);
137 CF_EXPORT Boolean _CFPreferencesDomainExists(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
138
139 /* 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 */
140 CF_EXPORT void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain, Boolean isWorldReadable);
141
142 typedef struct {
143 CFMutableArrayRef _search; // the search list; an array of _CFPreferencesDomains
144 CFMutableDictionaryRef _dictRep; // Mutable; a collapsed view of the search list, expressed as a single dictionary
145 CFStringRef _appName;
146 } _CFApplicationPreferences;
147
148 CF_EXPORT _CFApplicationPreferences *_CFStandardApplicationPreferences(CFStringRef appName);
149 CF_EXPORT _CFApplicationPreferences *_CFApplicationPreferencesCreateWithUser(CFStringRef userName, CFStringRef appName);
150 CF_EXPORT void _CFDeallocateApplicationPreferences(_CFApplicationPreferences *self);
151 CF_EXPORT CFTypeRef _CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences *prefs, CFStringRef key);
152 CF_EXPORT void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef defaultName, CFTypeRef value);
153 CF_EXPORT void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName);
154 CF_EXPORT Boolean _CFApplicationPreferencesSynchronize(_CFApplicationPreferences *self);
155 CF_EXPORT void _CFApplicationPreferencesUpdate(_CFApplicationPreferences *self); // same as updateDictRep
156 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences *self, CFDictionaryRef hint, CFDictionaryRef insertion, CFPreferencesDomainRef afterDomain);
157 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences *self, CFDictionaryRef hint); // same as dictRep
158 CF_EXPORT void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences *appPreferences);
159 CF_EXPORT void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences *appPrefs, CFStringRef appName);
160 CF_EXPORT void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
161 CF_EXPORT void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
162
163 CF_EXPORT void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain, Boolean addAtTop);
164 CF_EXPORT Boolean _CFApplicationPreferencesContainsDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
165 CF_EXPORT void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
166
167 CF_EXPORT CFTypeRef _CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef stopper, CFStringRef key);
168
169
170 CF_EXTERN_C_END
171
172
173
174 // ---- CFString material ----------------------------------------
175
176 #include <CoreFoundation/CFStringEncodingExt.h>
177
178 CF_EXTERN_C_BEGIN
179
180 /* Create a byte stream from a CFString backing. Can convert a string piece at a
181 time into a fixed size buffer. Returns number of characters converted.
182 Characters that cannot be converted to the specified encoding are represented
183 with the char specified by lossByte; if 0, then lossy conversion is not allowed
184 and conversion stops, returning partial results.
185 generatingExternalFile indicates that any extra stuff to allow this data to be
186 persistent (for instance, BOM) should be included.
187 Pass buffer==NULL if you don't care about the converted string (but just the
188 convertability, or number of bytes required, indicated by usedBufLen).
189 Does not zero-terminate. If you want to create Pascal or C string, allow one
190 extra byte at start or end.
191 */
192 CF_EXPORT CFIndex __CFStringEncodeByteStream(CFStringRef string, CFIndex rangeLoc, CFIndex rangeLen, Boolean generatingExternalFile, CFStringEncoding encoding, char lossByte, UInt8 *buffer, CFIndex max, CFIndex *usedBufLen);
193
194 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);
195
196 CF_EXPORT void __CFStringAppendBytes(CFMutableStringRef str, const char *cStr, CFIndex appendedLength, CFStringEncoding encoding);
197
198 CF_INLINE Boolean __CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding) {
199 switch (encoding & 0x0000FF00) {
200 case 0x0: // MacOS Script range
201 // Symbol & bidi encodings are not ASCII superset
202 if (encoding == kCFStringEncodingMacJapanese || encoding == kCFStringEncodingMacArabic || encoding == kCFStringEncodingMacHebrew || encoding == kCFStringEncodingMacUkrainian || encoding == kCFStringEncodingMacSymbol || encoding == kCFStringEncodingMacDingbats) return false;
203 return true;
204
205 case 0x100: // Unicode range
206 if (encoding != kCFStringEncodingUTF8) return false;
207 return true;
208
209 case 0x200: // ISO range
210 if (encoding == kCFStringEncodingISOLatinArabic) return false;
211 return true;
212
213 case 0x600: // National standards range
214 if (encoding != kCFStringEncodingASCII) return false;
215 return true;
216
217 case 0x800: // ISO 2022 range
218 return false; // It's modal encoding
219
220 case 0xA00: // Misc standard range
221 if ((encoding == kCFStringEncodingShiftJIS) || (encoding == kCFStringEncodingHZ_GB_2312) || (encoding == kCFStringEncodingUTF7_IMAP)) return false;
222 return true;
223
224 case 0xB00:
225 if (encoding == kCFStringEncodingNonLossyASCII) return false;
226 return true;
227
228 case 0xC00: // EBCDIC
229 return false;
230
231 default:
232 return ((encoding & 0x0000FF00) > 0x0C00 ? false : true);
233 }
234 }
235
236
237 /* Desperately using extern here */
238 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding;
239 CF_EXPORT CFStringEncoding __CFStringComputeEightBitStringEncoding(void);
240
241 CF_INLINE CFStringEncoding __CFStringGetEightBitStringEncoding(void) {
242 if (__CFDefaultEightBitStringEncoding == kCFStringEncodingInvalidId) __CFStringComputeEightBitStringEncoding();
243 return __CFDefaultEightBitStringEncoding;
244 }
245
246 enum {
247 __kCFVarWidthLocalBufferSize = 1008
248 };
249
250 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
251 union {
252 UInt8 *ascii;
253 UniChar *unicode;
254 } chars;
255 Boolean isASCII; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
256 Boolean shouldFreeChars; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
257 Boolean _unused1;
258 Boolean _unused2;
259 CFAllocatorRef allocator; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
260 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 */
261 UInt8 localBuffer[__kCFVarWidthLocalBufferSize]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
262 } CFVarWidthCharBuffer;
263
264
265 /* 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.
266 !!! 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.
267 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
268 */
269 CF_EXPORT Boolean __CFStringDecodeByteStream2(const UInt8 *bytes, UInt32 len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr);
270 CF_EXPORT Boolean __CFStringDecodeByteStream3(const UInt8 *bytes, CFIndex len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr, UInt32 converterFlags);
271
272
273 /* 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.
274 */
275 CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
276
277 /* Character class functions UnicodeData-2_1_5.txt
278 */
279 CF_INLINE Boolean __CFIsWhitespace(UniChar theChar) {
280 return ((theChar < 0x21) || (theChar > 0x7E && theChar < 0xA1) || (theChar >= 0x2000 && theChar <= 0x200B) || (theChar == 0x3000)) ? true : false;
281 }
282
283 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
284 */
285 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer *buf, CFIndex idx) {
286 if (buf->directBuffer) {
287 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
288 return buf->directBuffer[idx + buf->rangeToBuffer.location];
289 }
290 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
291 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
292 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
293 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
294 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
295 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
296 }
297 return buf->buffer[idx - buf->bufferedRangeStart];
298 }
299
300 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
301 */
302 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer *buf, CFIndex idx) {
303 if (buf->directBuffer) return buf->directBuffer[idx + buf->rangeToBuffer.location];
304 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
305 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
306 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
307 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
308 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
309 }
310 return buf->buffer[idx - buf->bufferedRangeStart];
311 }
312
313
314 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
315 */
316 CF_EXPORT void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef formatString, va_list args);
317 CF_EXPORT CFStringRef _CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef format, va_list arguments);
318
319 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
320 */
321 enum {_CFStringErrNone = 0, _CFStringErrNotMutable = 1, _CFStringErrNilArg = 2, _CFStringErrBounds = 3};
322 CF_EXPORT int __CFStringCheckAndReplace(CFMutableStringRef str, CFRange range, CFStringRef replacement);
323 CF_EXPORT Boolean __CFStringNoteErrors(void); // Should string errors raise?
324
325 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
326 */
327 CF_EXPORT Boolean __CFStringIsEightBit(CFStringRef str);
328
329 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
330 */
331 CF_EXPORT int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str, CFIndex idx, UniChar *ch);
332 CF_EXPORT int _CFStringCheckAndGetCharacters(CFStringRef str, CFRange range, UniChar *buffer);
333 CF_EXPORT CFIndex _CFStringGetLength2(CFStringRef str);
334 CF_EXPORT CFHashCode __CFStringHash(CFTypeRef cf);
335 CF_EXPORT CFHashCode CFStringHashISOLatin1CString(const uint8_t *bytes, CFIndex len);
336 CF_EXPORT CFHashCode CFStringHashCString(const uint8_t *bytes, CFIndex len);
337 CF_EXPORT CFHashCode CFStringHashCharacters(const UniChar *characters, CFIndex len);
338 CF_EXPORT CFHashCode CFStringHashNSString(CFStringRef str);
339
340
341 CF_EXTERN_C_END
342
343
344 // ---- Binary plist material ----------------------------------------
345
346 typedef const struct __CFKeyedArchiverUID * CFKeyedArchiverUIDRef;
347 CF_EXPORT CFTypeID _CFKeyedArchiverUIDGetTypeID(void);
348 CF_EXPORT CFKeyedArchiverUIDRef _CFKeyedArchiverUIDCreate(CFAllocatorRef allocator, uint32_t value);
349 CF_EXPORT uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid);
350
351
352 enum {
353 kCFBinaryPlistMarkerNull = 0x00,
354 kCFBinaryPlistMarkerFalse = 0x08,
355 kCFBinaryPlistMarkerTrue = 0x09,
356 kCFBinaryPlistMarkerFill = 0x0F,
357 kCFBinaryPlistMarkerInt = 0x10,
358 kCFBinaryPlistMarkerReal = 0x20,
359 kCFBinaryPlistMarkerDate = 0x33,
360 kCFBinaryPlistMarkerData = 0x40,
361 kCFBinaryPlistMarkerASCIIString = 0x50,
362 kCFBinaryPlistMarkerUnicode16String = 0x60,
363 kCFBinaryPlistMarkerUID = 0x80,
364 kCFBinaryPlistMarkerArray = 0xA0,
365 kCFBinaryPlistMarkerSet = 0xC0,
366 kCFBinaryPlistMarkerDict = 0xD0
367 };
368
369 typedef struct {
370 uint8_t _magic[6];
371 uint8_t _version[2];
372 } CFBinaryPlistHeader;
373
374 typedef struct {
375 uint8_t _unused[5];
376 uint8_t _sortVersion;
377 uint8_t _offsetIntSize;
378 uint8_t _objectRefSize;
379 uint64_t _numObjects;
380 uint64_t _topObject;
381 uint64_t _offsetTableOffset;
382 } CFBinaryPlistTrailer;
383
384
385 CF_EXPORT bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes, uint64_t datalen, uint8_t *marker, uint64_t *offset, CFBinaryPlistTrailer *trailer);
386 CF_EXPORT bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFIndex idx, uint64_t *offset, CFMutableDictionaryRef objects);
387 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);
388 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);
389 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);
390 CF_EXPORT CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef stream);
391 CF_EXPORT CFIndex __CFBinaryPlistWriteToStreamWithEstimate(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate); // will be removed soon
392 CF_EXPORT CFIndex __CFBinaryPlistWriteToStreamWithOptions(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate, CFOptionFlags options); // will be removed soon
393 CF_EXPORT CFIndex __CFBinaryPlistWrite(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate, CFOptionFlags options, CFErrorRef *error);
394
395 // ---- Used by property list parsing in Foundation
396
397 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
398
399 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLString(CFAllocatorRef allocator, CFStringRef xmlString, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
400
401 // ---- Sudden Termination material ----------------------------------------
402
403 #if DEPLOYMENT_TARGET_MACOSX
404
405 CF_EXPORT void _CFSuddenTerminationDisable(void);
406 CF_EXPORT void _CFSuddenTerminationEnable(void);
407 CF_EXPORT void _CFSuddenTerminationExitIfTerminationEnabled(int exitStatus);
408 CF_EXPORT void _CFSuddenTerminationExitWhenTerminationEnabled(int exitStatus);
409 CF_EXPORT size_t _CFSuddenTerminationDisablingCount(void);
410
411 #endif
412
413 // ---- Thread-specific data --------------------------------------------
414
415 // Get some thread specific data from a pre-assigned slot.
416 CF_EXPORT void *_CFGetTSD(uint32_t slot);
417
418 // 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.
419 CF_EXPORT void *_CFSetTSD(uint32_t slot, void *newVal, void (*destructor)(void *));
420
421 #if DEPLOYMENT_TARGET_WINDOWS
422 // ---- Windows-specific material ---------------------------------------
423
424 // These are replacements for POSIX calls on Windows, ensuring that the UTF8 parameters are converted to UTF16 before being passed to Windows
425 CF_EXPORT int _NS_stat(const char *name, struct _stat *st);
426 CF_EXPORT int _NS_mkdir(const char *name);
427 CF_EXPORT int _NS_rmdir(const char *name);
428 CF_EXPORT int _NS_chmod(const char *name, int mode);
429 CF_EXPORT int _NS_unlink(const char *name);
430 CF_EXPORT char *_NS_getcwd(char *dstbuf, size_t size); // Warning: this doesn't support dstbuf as null even though 'getcwd' does
431 CF_EXPORT char *_NS_getenv(const char *name);
432 CF_EXPORT int _NS_rename(const char *oldName, const char *newName);
433 CF_EXPORT int _NS_open(const char *name, int oflag, int pmode);
434 CF_EXPORT int _NS_mkstemp(char *name, int bufSize);
435 #endif
436
437 // ---- Miscellaneous material ----------------------------------------
438
439 #include <CoreFoundation/CFBag.h>
440 #include <CoreFoundation/CFSet.h>
441 #include <math.h>
442
443 CF_EXTERN_C_BEGIN
444
445 CF_EXPORT CFTypeID CFTypeGetTypeID(void);
446
447 CF_EXPORT void _CFArraySetCapacity(CFMutableArrayRef array, CFIndex cap);
448 CF_EXPORT void _CFBagSetCapacity(CFMutableBagRef bag, CFIndex cap);
449 CF_EXPORT void _CFDictionarySetCapacity(CFMutableDictionaryRef dict, CFIndex cap);
450 CF_EXPORT void _CFSetSetCapacity(CFMutableSetRef set, CFIndex cap);
451
452 CF_EXPORT void CFCharacterSetCompact(CFMutableCharacterSetRef theSet);
453 CF_EXPORT void CFCharacterSetFast(CFMutableCharacterSetRef theSet);
454
455 CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex idx);
456 CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount);
457
458
459 /* Enumeration
460 Call CFStartSearchPathEnumeration() once, then call
461 CFGetNextSearchPathEnumeration() one or more times with the returned state.
462 The return value of CFGetNextSearchPathEnumeration() should be used as
463 the state next time around.
464 When CFGetNextSearchPathEnumeration() returns 0, you're done.
465 */
466 typedef CFIndex CFSearchPathEnumerationState;
467 CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
468 CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
469
470 /* For use by NSNumber and CFNumber.
471 Hashing algorithm for CFNumber:
472 M = Max CFHashCode (assumed to be unsigned)
473 For positive integral values: (N * HASHFACTOR) mod M
474 For negative integral values: ((-N) * HASHFACTOR) mod M
475 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
476 HASHFACTOR is 2654435761, from Knuth's multiplicative method
477 */
478 #define HASHFACTOR 2654435761U
479
480 CF_INLINE CFHashCode _CFHashInt(long i) {
481 return ((i > 0) ? (CFHashCode)(i) : (CFHashCode)(-i)) * HASHFACTOR;
482 }
483
484 CF_INLINE CFHashCode _CFHashDouble(double d) {
485 double dInt;
486 if (d < 0) d = -d;
487 dInt = floor(d+0.5);
488 CFHashCode integralHash = HASHFACTOR * (CFHashCode)fmod(dInt, (double)ULONG_MAX);
489 return (CFHashCode)(integralHash + (CFHashCode)((d - dInt) * ULONG_MAX));
490 }
491
492
493 /* 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.
494 */
495 CF_EXPORT CFStringRef _CFErrorCreateLocalizedDescription(CFErrorRef err);
496 CF_EXPORT CFStringRef _CFErrorCreateLocalizedFailureReason(CFErrorRef err);
497 CF_EXPORT CFStringRef _CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err);
498 CF_EXPORT CFStringRef _CFErrorCreateDebugDescription(CFErrorRef err);
499
500 CF_EXPORT CFURLRef _CFURLAlloc(CFAllocatorRef allocator);
501 CF_EXPORT void _CFURLInitWithString(CFURLRef url, CFStringRef string, CFURLRef baseURL);
502 CF_EXPORT void _CFURLInitFSPath(CFURLRef url, CFStringRef path);
503 CF_EXPORT Boolean _CFStringIsLegalURLString(CFStringRef string);
504 CF_EXPORT void *__CFURLReservedPtr(CFURLRef url);
505 CF_EXPORT void __CFURLSetReservedPtr(CFURLRef url, void *ptr);
506 CF_EXPORT CFStringEncoding _CFURLGetEncoding(CFURLRef url);
507
508 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
509 CF_EXPORT Boolean _CFRunLoopFinished(CFRunLoopRef rl, CFStringRef mode);
510 #endif
511
512 CF_EXPORT CFIndex _CFStreamInstanceSize(void);
513
514 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
515 typedef struct {
516 mach_vm_address_t address;
517 mach_vm_size_t size;
518 mach_port_t port;
519 bool purgeable;
520 bool corporeal;
521 bool volatyle;
522 uintptr_t reserved;
523 } CFDiscorporateMemory;
524
525 extern kern_return_t _CFDiscorporateMemoryAllocate(CFDiscorporateMemory *hm, size_t size, bool purgeable);
526 extern kern_return_t _CFDiscorporateMemoryDeallocate(CFDiscorporateMemory *hm);
527 extern kern_return_t _CFDiscorporateMemoryDematerialize(CFDiscorporateMemory *hm);
528 extern kern_return_t _CFDiscorporateMemoryMaterialize(CFDiscorporateMemory *hm);
529 #endif
530
531 enum {
532 kCFNumberFormatterOrdinalStyle = 6,
533 kCFNumberFormatterDurationStyle = 7,
534 };
535
536 CF_EXPORT CFRange _CFDataFindBytes(CFDataRef data, CFDataRef dataToFind, CFRange searchRange, CFDataSearchFlags compareOptions);
537
538
539 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
540 #if !defined(__CFReadTSR)
541 #include <mach/mach_time.h>
542 #define __CFReadTSR() mach_absolute_time()
543 #endif
544 #elif DEPLOYMENT_TARGET_WINDOWS
545 #if 0
546 CF_INLINE UInt64 __CFReadTSR(void) {
547 LARGE_INTEGER freq;
548 QueryPerformanceCounter(&freq);
549 return freq.QuadPart;
550 }
551 #endif
552 #endif
553
554
555 CF_EXTERN_C_END
556
557 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */
558