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