]> git.saurik.com Git - apple/cf.git/blame - Base.subproj/ForFoundationOnly.h
CF-368.11.tar.gz
[apple/cf.git] / Base.subproj / ForFoundationOnly.h
CommitLineData
9ce05555 1/*
d8925383 2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
9ce05555
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
9ce05555
A
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
d8925383 24 Copyright (c) 1998-2005, Apple, Inc. All rights reserved.
9ce05555
A
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/CFDictionary.h>
39#include <CoreFoundation/CFPriv.h>
d8925383 40#include <CoreFoundation/CFPropertyList.h>
9ce05555
A
41
42// NOTE: miscellaneous declarations are at the end
43
d8925383
A
44// ---- CFRuntime material ----------------------------------------
45
46#if defined(__cplusplus)
47extern "C" {
48#endif
49
50#include <malloc/malloc.h>
51
52CF_EXPORT
53void __CFSetupFoundationBridging(void *, void *, void *, void *);
54
55#if defined(__cplusplus)
56}
57#endif
9ce05555
A
58
59// ---- CFBundle material ----------------------------------------
60
d8925383 61#include <CoreFoundation/CFBundlePriv.h>
9ce05555
A
62
63#if defined(__cplusplus)
64extern "C" {
65#endif
66
67CF_EXPORT const CFStringRef _kCFBundleExecutablePathKey;
68CF_EXPORT const CFStringRef _kCFBundleInfoPlistURLKey;
69CF_EXPORT const CFStringRef _kCFBundleNumericVersionKey;
70CF_EXPORT const CFStringRef _kCFBundleResourcesFileMappedKey;
71CF_EXPORT const CFStringRef _kCFBundleCFMLoadAsBundleKey;
72CF_EXPORT const CFStringRef _kCFBundleAllowMixedLocalizationsKey;
73
d8925383
A
74CF_EXPORT CFArrayRef _CFFindBundleResources(CFBundleRef bundle, CFURLRef bundleURL, CFStringRef subDirName, CFArrayRef searchLanguages, CFStringRef resName, CFArrayRef resTypes, CFIndex limit, UInt8 version);
75
76CF_EXPORT UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
9ce05555
A
77
78CF_EXPORT CFArrayRef _CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
79CF_EXPORT CFArrayRef _CFBundleGetLanguageSearchList(CFBundleRef bundle);
80
81#if defined(__cplusplus)
82}
83#endif
84
85
d8925383
A
86#if defined(__MACH__)
87// ---- CFPreferences material ----------------------------------------
88
89#define DEBUG_PREFERENCES_MEMORY 0
90
91#if DEBUG_PREFERENCES_MEMORY
92#include "../Tests/CFCountingAllocator.h"
93#endif
94
95#if defined(__cplusplus)
96extern "C" {
97#endif
98
99extern void _CFPreferencesPurgeDomainCache(void);
100
101typedef 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
113CF_EXPORT CFAllocatorRef __CFPreferencesAllocator(void);
114CF_EXPORT const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks;
115
116#if defined(__WIN32__)
117CF_EXPORT const _CFPreferencesDomainCallBacks __kCFWindowsRegistryDomainCallBacks;
118#else
119CF_EXPORT const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks;
120#endif
121
122typedef struct __CFPreferencesDomain * CFPreferencesDomainRef;
123
124CF_EXPORT CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks);
125CF_EXPORT CFPreferencesDomainRef _CFPreferencesStandardDomain(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
126
127CF_EXPORT CFTypeRef _CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain, CFStringRef key);
128CF_EXPORT void _CFPreferencesDomainSet(CFPreferencesDomainRef domain, CFStringRef key, CFTypeRef value);
129CF_EXPORT Boolean _CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain);
130
131/* If buf is NULL, no allocation occurs. *numKeyValuePairs should be set to the current size of buf; alloc should be allocator to allocate/reallocate buf, or kCFAllocatorNull if buf is not to be (re)allocated. No matter what happens, *numKeyValuePairs is always set to the number of pairs in the domain */
132CF_EXPORT void _CFPreferencesDomainGetKeysAndValues(CFAllocatorRef alloc, CFPreferencesDomainRef domain, void **buf[], CFIndex *numKeyValuePairs);
133
134CF_EXPORT CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName);
135CF_EXPORT Boolean _CFSynchronizeDomainCache(void);
136
137CF_EXPORT void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain, CFDictionaryRef dict);
138CF_EXPORT CFDictionaryRef _CFPreferencesDomainCopyDictionary(CFPreferencesDomainRef domain);
139CF_EXPORT CFDictionaryRef _CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain);
140CF_EXPORT Boolean _CFPreferencesDomainExists(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
141
142/* 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 */
143CF_EXPORT void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain, Boolean isWorldReadable);
144
145typedef struct {
146 CFMutableArrayRef _search; // the search list; an array of _CFPreferencesDomains
147 CFMutableDictionaryRef _dictRep; // Mutable; a collapsed view of the search list, expressed as a single dictionary
148 CFStringRef _appName;
149} _CFApplicationPreferences;
150
151CF_EXPORT _CFApplicationPreferences *_CFStandardApplicationPreferences(CFStringRef appName);
152CF_EXPORT _CFApplicationPreferences *_CFApplicationPreferencesCreateWithUser(CFStringRef userName, CFStringRef appName);
153CF_EXPORT void _CFDeallocateApplicationPreferences(_CFApplicationPreferences *self);
154CF_EXPORT CFTypeRef _CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences *prefs, CFStringRef key);
155CF_EXPORT void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef defaultName, CFTypeRef value);
156CF_EXPORT void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName);
157CF_EXPORT Boolean _CFApplicationPreferencesSynchronize(_CFApplicationPreferences *self);
158CF_EXPORT void _CFApplicationPreferencesUpdate(_CFApplicationPreferences *self); // same as updateDictRep
159CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences *self, CFDictionaryRef hint, CFDictionaryRef insertion, CFPreferencesDomainRef afterDomain);
160CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences *self, CFDictionaryRef hint); // same as dictRep
161CF_EXPORT void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences *appPreferences);
162CF_EXPORT void _CFApplicationPreferencesSetSearchList(_CFApplicationPreferences *self, CFArrayRef newSearchList);
163CF_EXPORT void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences *appPrefs, CFStringRef appName);
164CF_EXPORT void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
165CF_EXPORT void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
166
167CF_EXPORT void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain, Boolean addAtTop);
168CF_EXPORT Boolean _CFApplicationPreferencesContainsDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
169CF_EXPORT void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
170
171CF_EXPORT CFTypeRef _CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef stopper, CFStringRef key);
172
173
174#if defined(__cplusplus)
175}
176#endif
177
178#endif // __MACH__
179
180
181
9ce05555
A
182// ---- CFString material ----------------------------------------
183
d8925383 184
9ce05555
A
185#if defined(__cplusplus)
186extern "C" {
187#endif
188
189/* Create a byte stream from a CFString backing. Can convert a string piece at a
190 time into a fixed size buffer. Returns number of characters converted.
191 Characters that cannot be converted to the specified encoding are represented
192 with the char specified by lossByte; if 0, then lossy conversion is not allowed
193 and conversion stops, returning partial results.
194 generatingExternalFile indicates that any extra stuff to allow this data to be
195 persistent (for instance, BOM) should be included.
196 Pass buffer==NULL if you don't care about the converted string (but just the
197 convertability, or number of bytes required, indicated by usedBufLen).
198 Does not zero-terminate. If you want to create Pascal or C string, allow one
199 extra byte at start or end.
200*/
201CF_EXPORT CFIndex __CFStringEncodeByteStream(CFStringRef string, CFIndex rangeLoc, CFIndex rangeLen, Boolean generatingExternalFile, CFStringEncoding encoding, char lossByte, UInt8 *buffer, CFIndex max, CFIndex *usedBufLen);
202
d8925383
A
203CF_EXPORT CFStringRef __CFStringCreateImmutableFunnel2(CFAllocatorRef alloc, const void *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean possiblyExternalFormat, Boolean tryToReduceUnicode, Boolean hasLengthByte, Boolean hasNullByte, Boolean noCopy, CFAllocatorRef contentsDeallocator);
204
9ce05555
A
205CF_INLINE Boolean __CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding) {
206 switch (encoding & 0x0000FF00) {
9ce05555
A
207
208 case 0x100: // Unicode range
d8925383 209 if (encoding != kCFStringEncodingUTF8) return false;
9ce05555
A
210 return true;
211
9ce05555
A
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
9ce05555
A
220
221 case 0xB00:
222 if (encoding == kCFStringEncodingNonLossyASCII) return false;
223 return true;
224
225 case 0xC00: // EBCDIC
226 return false;
227
228 default:
229 return ((encoding & 0x0000FF00) > 0x0C00 ? false : true);
230 }
231}
232
d8925383 233
9ce05555
A
234/* Desperately using extern here */
235CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding;
236CF_EXPORT CFStringEncoding __CFStringComputeEightBitStringEncoding(void);
237
238CF_INLINE CFStringEncoding __CFStringGetEightBitStringEncoding(void) {
239 if (__CFDefaultEightBitStringEncoding == kCFStringEncodingInvalidId) __CFStringComputeEightBitStringEncoding();
240 return __CFDefaultEightBitStringEncoding;
241}
242
243enum {
244 __kCFVarWidthLocalBufferSize = 1008
245};
246
247typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
248 union {
249 UInt8 *ascii;
250 UniChar *unicode;
251 } chars;
252 Boolean isASCII; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
253 Boolean shouldFreeChars; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
254 Boolean _unused1;
255 Boolean _unused2;
256 CFAllocatorRef allocator; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
257 UInt32 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 */
258 UInt8 localBuffer[__kCFVarWidthLocalBufferSize]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
259} CFVarWidthCharBuffer;
260
261
262/* 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.
263!!! 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.
264!!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
265*/
266CF_EXPORT Boolean __CFStringDecodeByteStream2(const UInt8 *bytes, UInt32 len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr);
267CF_EXPORT Boolean __CFStringDecodeByteStream3(const UInt8 *bytes, UInt32 len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr, UInt32 converterFlags);
268
269
270/* 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. The table is always safe to use; calling __CFSetCharToUniCharFunc() updates it.
271*/
272CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
273CF_EXPORT void __CFSetCharToUniCharFunc(Boolean (*func)(UInt32 flags, UInt8 ch, UniChar *unicodeChar));
274CF_EXPORT UniChar __CFCharToUniCharTable[256];
275
276/* Character class functions UnicodeData-2_1_5.txt
277*/
278CF_INLINE Boolean __CFIsWhitespace(UniChar theChar) {
279 return ((theChar < 0x21) || (theChar > 0x7E && theChar < 0xA1) || (theChar >= 0x2000 && theChar <= 0x200B) || (theChar == 0x3000)) ? true : false;
280}
281
282/* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
283*/
284CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer *buf, CFIndex idx) {
285 if (buf->directBuffer) {
286 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
287 return buf->directBuffer[idx + buf->rangeToBuffer.location];
288 }
289 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
290 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
291 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
292 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
293 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
294 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
295 }
296 return buf->buffer[idx - buf->bufferedRangeStart];
297}
298
299/* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
300*/
301CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer *buf, CFIndex idx) {
302 if (buf->directBuffer) return buf->directBuffer[idx + buf->rangeToBuffer.location];
303 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
304 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
305 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
306 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
307 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
308 }
309 return buf->buffer[idx - buf->bufferedRangeStart];
310}
311
312
313/* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
314*/
315CF_EXPORT void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString, CFStringRef (*copyDescFunc)(void *, CFDictionaryRef), CFDictionaryRef formatOptions, CFStringRef formatString, va_list args);
316CF_EXPORT CFStringRef _CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc, CFStringRef (*copyDescFunc)(void *, CFDictionaryRef), CFDictionaryRef formatOptions, CFStringRef format, va_list arguments);
317
d8925383
A
318/* For NSString (and NSAttributedString) usage, mutate with isMutable check
319*/
9ce05555 320enum {_CFStringErrNone = 0, _CFStringErrNotMutable = 1, _CFStringErrNilArg = 2, _CFStringErrBounds = 3};
d8925383 321CF_EXPORT int __CFStringCheckAndReplace(CFMutableStringRef str, CFRange range, CFStringRef replacement);
9ce05555
A
322CF_EXPORT Boolean __CFStringNoteErrors(void); // Should string errors raise?
323
d8925383
A
324/* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
325*/
326CF_EXPORT Boolean __CFStringIsEightBit(CFStringRef str);
327
328/* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
329*/
330CF_EXPORT int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str, CFIndex idx, UniChar *ch);
331CF_EXPORT int _CFStringCheckAndGetCharacters(CFStringRef str, CFRange range, UniChar *buffer);
332CF_EXPORT CFIndex _CFStringGetLength2(CFStringRef str);
333CF_EXPORT CFHashCode __CFStringHash(CFTypeRef cf);
334CF_EXPORT CFHashCode CFStringHashISOLatin1CString(const uint8_t *bytes, CFIndex len);
335CF_EXPORT CFHashCode CFStringHashCString(const uint8_t *bytes, CFIndex len);
336CF_EXPORT CFHashCode CFStringHashCharacters(const UniChar *characters, CFIndex len);
337CF_EXPORT CFHashCode CFStringHashNSString(CFStringRef str);
338
339
9ce05555
A
340#if defined(__cplusplus)
341}
342#endif
343
344
345// ---- Binary plist material ----------------------------------------
346
347typedef const struct __CFKeyedArchiverUID * CFKeyedArchiverUIDRef;
348extern CFTypeID _CFKeyedArchiverUIDGetTypeID(void);
349extern CFKeyedArchiverUIDRef _CFKeyedArchiverUIDCreate(CFAllocatorRef allocator, uint32_t value);
350extern uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid);
351
352
353enum {
354 kCFBinaryPlistMarkerNull = 0x00,
355 kCFBinaryPlistMarkerFalse = 0x08,
356 kCFBinaryPlistMarkerTrue = 0x09,
357 kCFBinaryPlistMarkerFill = 0x0F,
358 kCFBinaryPlistMarkerInt = 0x10,
359 kCFBinaryPlistMarkerReal = 0x20,
360 kCFBinaryPlistMarkerDate = 0x33,
361 kCFBinaryPlistMarkerData = 0x40,
362 kCFBinaryPlistMarkerASCIIString = 0x50,
363 kCFBinaryPlistMarkerUnicode16String = 0x60,
364 kCFBinaryPlistMarkerUID = 0x80,
365 kCFBinaryPlistMarkerArray = 0xA0,
366 kCFBinaryPlistMarkerDict = 0xD0
367};
368
369typedef struct {
370 uint8_t _magic[6];
371 uint8_t _version[2];
372} CFBinaryPlistHeader;
373
374typedef struct {
375 uint8_t _unused[6];
376 uint8_t _offsetIntSize;
377 uint8_t _objectRefSize;
378 uint64_t _numObjects;
379 uint64_t _topObject;
380 uint64_t _offsetTableOffset;
381} CFBinaryPlistTrailer;
382
d8925383
A
383extern bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes, uint64_t datalen, uint8_t *marker, uint64_t *offset, CFBinaryPlistTrailer *trailer);
384extern bool __CFBinaryPlistGetOffsetForValueFromArray(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFIndex idx, uint64_t *offset);
385extern bool __CFBinaryPlistGetOffsetForValueFromDictionary(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFTypeRef key, uint64_t *koffset, uint64_t *voffset);
386extern bool __CFBinaryPlistCreateObject(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFAllocatorRef allocator, CFOptionFlags mutabilityOption, CFMutableDictionaryRef objects, CFPropertyListRef *plist);
387extern CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef stream);
388
389
390// ---- Used by property list parsing in Foundation
391
392extern CFTypeRef _CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
393
9ce05555
A
394
395// ---- Miscellaneous material ----------------------------------------
396
397#include <CoreFoundation/CFBag.h>
398#include <CoreFoundation/CFSet.h>
399#include <math.h>
400
401#if defined(__cplusplus)
402extern "C" {
403#endif
404
405CF_EXPORT CFTypeID CFTypeGetTypeID(void);
406
d8925383
A
407CF_EXPORT CFTypeRef _CFRetainGC(CFTypeRef cf);
408CF_EXPORT void _CFReleaseGC(CFTypeRef cf);
409
9ce05555
A
410CF_EXPORT void _CFArraySetCapacity(CFMutableArrayRef array, CFIndex cap);
411CF_EXPORT void _CFBagSetCapacity(CFMutableBagRef bag, CFIndex cap);
412CF_EXPORT void _CFDictionarySetCapacity(CFMutableDictionaryRef dict, CFIndex cap);
413CF_EXPORT void _CFSetSetCapacity(CFMutableSetRef set, CFIndex cap);
414
d8925383
A
415CF_EXPORT void CFCharacterSetCompact(CFMutableCharacterSetRef theSet);
416CF_EXPORT void CFCharacterSetFast(CFMutableCharacterSetRef theSet);
417
418CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex idx);
9ce05555
A
419CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount);
420
421
d8925383
A
422/* Enumeration
423 Call CFStartSearchPathEnumeration() once, then call
424 CFGetNextSearchPathEnumeration() one or more times with the returned state.
425 The return value of CFGetNextSearchPathEnumeration() should be used as
426 the state next time around.
427 When CFGetNextSearchPathEnumeration() returns 0, you're done.
428*/
429typedef CFIndex CFSearchPathEnumerationState;
430CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
431CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
432
9ce05555
A
433/* For use by NSNumber and CFNumber.
434 Hashing algorithm for CFNumber:
435 M = Max CFHashCode (assumed to be unsigned)
436 For positive integral values: N mod M
437 For negative integral values: (-N) mod M
438 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
439*/
440CF_INLINE CFHashCode _CFHashInt(int i) {
441 return (i > 0) ? (CFHashCode)(i) : (CFHashCode)(-i);
442}
443
444CF_INLINE CFHashCode _CFHashDouble(double d) {
445 double dInt;
446 if (d < 0) d = -d;
447 dInt = rint(d);
448 return (CFHashCode)(fmod(dInt, (double)0xFFFFFFFF) + ((d - dInt) * 0xFFFFFFFF));
449}
450
d8925383
A
451CF_EXPORT CFURLRef _CFURLAlloc(CFAllocatorRef allocator);
452CF_EXPORT void _CFURLInitWithString(CFURLRef url, CFStringRef string, CFURLRef baseURL);
453CF_EXPORT void _CFURLInitFSPath(CFURLRef url, CFStringRef path);
454CF_EXPORT Boolean _CFStringIsLegalURLString(CFStringRef string);
455CF_EXPORT void *__CFURLReservedPtr(CFURLRef url);
456CF_EXPORT void __CFURLSetReservedPtr(CFURLRef url, void *ptr);
9ce05555
A
457
458typedef void (*CFRunLoopPerformCallBack)(void *info);
d8925383
A
459CF_EXPORT void _CFRunLoopPerformEnqueue(CFRunLoopRef rl, CFStringRef mode, CFRunLoopPerformCallBack callout, void *info);
460CF_EXPORT Boolean _CFRunLoopFinished(CFRunLoopRef rl, CFStringRef mode);
9ce05555
A
461
462#if defined(__MACH__)
d8925383
A
463 #if !defined(__CFReadTSR)
464 #include <mach/mach_time.h>
465 #define __CFReadTSR() mach_absolute_time()
466 #endif
467#elif defined(__WIN32__)
9ce05555 468CF_INLINE UInt64 __CFReadTSR(void) {
d8925383
A
469 LARGE_INTEGER freq;
470 QueryPerformanceCounter(&freq);
471 return freq.QuadPart;
9ce05555
A
472}
473#else
474CF_INLINE UInt64 __CFReadTSR(void) {
475 union {
476 UInt64 time64;
477 UInt32 word[2];
478 } now;
479#if defined(__i386__)
480 /* Read from Pentium and Pentium Pro 64-bit timestamp counter. */
481 /* The counter is set to 0 at processor reset and increments on */
482 /* every clock cycle. */
483 __asm__ volatile("rdtsc" : : : "eax", "edx");
484 __asm__ volatile("movl %%eax,%0" : "=m" (now.word[0]) : : "eax");
485 __asm__ volatile("movl %%edx,%0" : "=m" (now.word[1]) : : "edx");
d8925383 486#elif defined(__ppc__) || defined(__ppc64__)
9ce05555
A
487 /* Read from PowerPC 64-bit time base register. The increment */
488 /* rate of the time base is implementation-dependent, but is */
489 /* 1/4th the bus clock cycle on 603/604/750 processors. */
490 UInt32 t3;
491 do {
492 __asm__ volatile("mftbu %0" : "=r" (now.word[0]));
493 __asm__ volatile("mftb %0" : "=r" (now.word[1]));
494 __asm__ volatile("mftbu %0" : "=r" (t3));
495 } while (now.word[0] != t3);
496#else
d8925383 497#error Do not know how to read a time stamp register on this architecture
9ce05555
A
498 now.time64 = (uint64_t)0;
499#endif
500 return now.time64;
501}
502#endif
503
504#if defined(__cplusplus)
505}
506#endif
507
508#endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */
509