]> git.saurik.com Git - apple/cf.git/blob - ForFoundationOnly.h
CF-476.13.tar.gz
[apple/cf.git] / ForFoundationOnly.h
1 /*
2 * Copyright (c) 2008 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-2007, 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/CFDictionary.h>
39 #include <CoreFoundation/CFPriv.h>
40 #include <CoreFoundation/CFPropertyList.h>
41 #include <CoreFoundation/CFError.h>
42 #include <CoreFoundation/CFStringEncodingExt.h>
43 #include <limits.h>
44
45 // NOTE: miscellaneous declarations are at the end
46
47 // ---- CFRuntime material ----------------------------------------
48
49 CF_EXTERN_C_BEGIN
50
51 #if DEPLOYMENT_TARGET_MACOSX || 0
52 #include <malloc/malloc.h>
53 #endif //__MACH__
54
55 CF_EXTERN_C_END
56
57 // ---- CFBundle material ----------------------------------------
58
59 #include <CoreFoundation/CFBundlePriv.h>
60
61 CF_EXTERN_C_BEGIN
62
63 CF_EXPORT const CFStringRef _kCFBundleExecutablePathKey;
64 CF_EXPORT const CFStringRef _kCFBundleInfoPlistURLKey;
65 CF_EXPORT const CFStringRef _kCFBundleRawInfoPlistURLKey;
66 CF_EXPORT const CFStringRef _kCFBundleNumericVersionKey;
67 CF_EXPORT const CFStringRef _kCFBundleResourcesFileMappedKey;
68 CF_EXPORT const CFStringRef _kCFBundleCFMLoadAsBundleKey;
69 CF_EXPORT const CFStringRef _kCFBundleAllowMixedLocalizationsKey;
70 CF_EXPORT const CFStringRef _kCFBundleInitialPathKey;
71 CF_EXPORT const CFStringRef _kCFBundleResolvedPathKey;
72 CF_EXPORT const CFStringRef _kCFBundlePrincipalClassKey;
73
74 CF_EXPORT CFArrayRef _CFFindBundleResources(CFBundleRef bundle, CFURLRef bundleURL, CFStringRef subDirName, CFArrayRef searchLanguages, CFStringRef resName, CFArrayRef resTypes, CFIndex limit, UInt8 version);
75
76 CF_EXPORT UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
77
78 CF_EXPORT CFArrayRef _CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
79 CF_EXPORT CFArrayRef _CFBundleGetLanguageSearchList(CFBundleRef bundle);
80
81 CF_EXPORT Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
82 CF_EXPORT CFErrorRef _CFBundleCreateError(CFAllocatorRef allocator, CFBundleRef bundle, CFIndex code);
83
84 CF_EXTERN_C_END
85
86
87 #if (DEPLOYMENT_TARGET_MACOSX || 0) || defined (__WIN32__)
88 // ---- CFPreferences material ----------------------------------------
89
90 #define DEBUG_PREFERENCES_MEMORY 0
91
92 #if DEBUG_PREFERENCES_MEMORY
93 #include "../Tests/CFCountingAllocator.h"
94 #endif
95
96 CF_EXTERN_C_BEGIN
97
98 extern void _CFPreferencesPurgeDomainCache(void);
99
100 typedef struct {
101 void * (*createDomain)(CFAllocatorRef allocator, CFTypeRef context);
102 void (*freeDomain)(CFAllocatorRef allocator, CFTypeRef context, void *domain);
103 CFTypeRef (*fetchValue)(CFTypeRef context, void *domain, CFStringRef key); // Caller releases
104 void (*writeValue)(CFTypeRef context, void *domain, CFStringRef key, CFTypeRef value);
105 Boolean (*synchronize)(CFTypeRef context, void *domain);
106 void (*getKeysAndValues)(CFAllocatorRef alloc, CFTypeRef context, void *domain, void **buf[], CFIndex *numKeyValuePairs);
107 CFDictionaryRef (*copyDomainDictionary)(CFTypeRef context, void *domain);
108 /* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
109 void (*setIsWorldReadable)(CFTypeRef context, void *domain, Boolean isWorldReadable);
110 } _CFPreferencesDomainCallBacks;
111
112 CF_EXPORT CFAllocatorRef __CFPreferencesAllocator(void);
113 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks;
114 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks;
115
116 typedef struct __CFPreferencesDomain * CFPreferencesDomainRef;
117
118 CF_EXPORT CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks);
119 CF_EXPORT CFPreferencesDomainRef _CFPreferencesStandardDomain(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
120
121 CF_EXPORT CFTypeRef _CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain, CFStringRef key);
122 CF_EXPORT void _CFPreferencesDomainSet(CFPreferencesDomainRef domain, CFStringRef key, CFTypeRef value);
123 CF_EXPORT Boolean _CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain);
124
125 CF_EXPORT CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName);
126 CF_EXPORT Boolean _CFSynchronizeDomainCache(void);
127
128 CF_EXPORT void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain, CFDictionaryRef dict);
129 CF_EXPORT CFDictionaryRef _CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain);
130 CF_EXPORT Boolean _CFPreferencesDomainExists(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
131
132 /* 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 */
133 CF_EXPORT void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain, Boolean isWorldReadable);
134
135 typedef struct {
136 CFMutableArrayRef _search; // the search list; an array of _CFPreferencesDomains
137 CFMutableDictionaryRef _dictRep; // Mutable; a collapsed view of the search list, expressed as a single dictionary
138 CFStringRef _appName;
139 } _CFApplicationPreferences;
140
141 CF_EXPORT _CFApplicationPreferences *_CFStandardApplicationPreferences(CFStringRef appName);
142 CF_EXPORT _CFApplicationPreferences *_CFApplicationPreferencesCreateWithUser(CFStringRef userName, CFStringRef appName);
143 CF_EXPORT void _CFDeallocateApplicationPreferences(_CFApplicationPreferences *self);
144 CF_EXPORT CFTypeRef _CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences *prefs, CFStringRef key);
145 CF_EXPORT void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef defaultName, CFTypeRef value);
146 CF_EXPORT void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName);
147 CF_EXPORT Boolean _CFApplicationPreferencesSynchronize(_CFApplicationPreferences *self);
148 CF_EXPORT void _CFApplicationPreferencesUpdate(_CFApplicationPreferences *self); // same as updateDictRep
149 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences *self, CFDictionaryRef hint, CFDictionaryRef insertion, CFPreferencesDomainRef afterDomain);
150 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences *self, CFDictionaryRef hint); // same as dictRep
151 CF_EXPORT void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences *appPreferences);
152 CF_EXPORT void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences *appPrefs, CFStringRef appName);
153 CF_EXPORT void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
154 CF_EXPORT void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
155
156 CF_EXPORT void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain, Boolean addAtTop);
157 CF_EXPORT Boolean _CFApplicationPreferencesContainsDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
158 CF_EXPORT void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
159
160 CF_EXPORT CFTypeRef _CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef stopper, CFStringRef key);
161
162
163 CF_EXTERN_C_END
164
165 #endif
166
167 #if DEPLOYMENT_TARGET_MACOSX || 0 || 0
168 // ---- CFNotification material ----------------------------------------
169
170 #include <CoreFoundation/CFNotificationCenter.h>
171
172 CF_EXTERN_C_BEGIN
173
174 enum {
175 kCFXNotificationSuspensionBehaviorDeliverImmediately = 1,
176 kCFXNotificationSuspensionBehaviorDrop = 2,
177 kCFXNotificationSuspensionBehaviorCoalesce = 4,
178 kCFXNotificationSuspensionBehaviorHold = 8,
179 kCFXNotificationSuspensionBehaviorAny = 0x0000FFFF
180 };
181 typedef CFOptionFlags CFXNotificationSuspensionBehavior;
182
183 CF_EXPORT const CFStringRef kCFNotificationAnyName;
184 CF_EXPORT const CFStringRef kCFNotificationAnyObject;
185
186 typedef void (*CFXNotificationCallBack)(CFNotificationCenterRef nc, CFStringRef name, const void *object, CFDictionaryRef userInfo, void *info);
187
188 // operations: 1==retain, 2==release, 3==copyDescription
189 typedef void * (*CFXNotificationInfoCallBack)(int operation, void *info);
190 typedef bool (*CFXNotificationEqualCallBack)(const void *info1, const void *info2);
191
192 // 'object' is treated as an arbitrary unretained pointer for a local notification
193 // center, and as a retained CFStringRef or NULL for a distributed notification center.
194 typedef struct { // version 0
195 CFIndex version;
196 CFXNotificationCallBack callback;
197 CFXNotificationSuspensionBehavior behavior;
198 CFStringRef name;
199 const void * object;
200 void * info;
201 CFXNotificationInfoCallBack info_callback;
202 } CFNotificationRegistrationData;
203
204 typedef struct { // version 0
205 CFIndex version;
206 CFXNotificationCallBack callback;
207 CFXNotificationSuspensionBehavior behaviorFlags;
208 CFStringRef name;
209 const void * object;
210 void * info;
211 CFXNotificationEqualCallBack info_equal;
212 } CFNotificationUnregistrationData;
213
214
215 CF_EXPORT CFNotificationCenterRef _CFXNotificationGetTaskCenter(void);
216 CF_EXPORT CFNotificationCenterRef _CFXNotificationGetHostCenter(void);
217
218 CF_EXPORT CFNotificationCenterRef _CFXNotificationCenterCreate(CFAllocatorRef allocator, bool distributed);
219
220 CF_EXPORT void _CFXNotificationRegister(CFNotificationCenterRef nc, CFNotificationRegistrationData *data);
221 CF_EXPORT void _CFXNotificationUnregister(CFNotificationCenterRef nc, CFNotificationUnregistrationData *data);
222
223 CF_EXPORT void _CFXNotificationPost(CFNotificationCenterRef nc, CFStringRef name, const void *object, CFDictionaryRef userInfo, CFOptionFlags options);
224 CF_EXPORT void _CFXNotificationPostNotification(CFNotificationCenterRef nc, CFStringRef name, const void *object, CFDictionaryRef userInfo, CFOptionFlags options, void *note);
225
226 CF_EXPORT bool _CFXNotificationGetSuspended(CFNotificationCenterRef nc);
227 CF_EXPORT void _CFXNotificationSetSuspended(CFNotificationCenterRef nc, bool suspended);
228
229 CF_EXTERN_C_END
230
231 #endif
232
233
234 // ---- CFString material ----------------------------------------
235
236
237 CF_EXTERN_C_BEGIN
238
239 /* Create a byte stream from a CFString backing. Can convert a string piece at a
240 time into a fixed size buffer. Returns number of characters converted.
241 Characters that cannot be converted to the specified encoding are represented
242 with the char specified by lossByte; if 0, then lossy conversion is not allowed
243 and conversion stops, returning partial results.
244 generatingExternalFile indicates that any extra stuff to allow this data to be
245 persistent (for instance, BOM) should be included.
246 Pass buffer==NULL if you don't care about the converted string (but just the
247 convertability, or number of bytes required, indicated by usedBufLen).
248 Does not zero-terminate. If you want to create Pascal or C string, allow one
249 extra byte at start or end.
250 */
251 CF_EXPORT CFIndex __CFStringEncodeByteStream(CFStringRef string, CFIndex rangeLoc, CFIndex rangeLen, Boolean generatingExternalFile, CFStringEncoding encoding, char lossByte, UInt8 *buffer, CFIndex max, CFIndex *usedBufLen);
252
253 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);
254
255 CF_INLINE Boolean __CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding) {
256 switch (encoding & 0x0000FF00) {
257
258 case 0x100: // Unicode range
259 if (encoding != kCFStringEncodingUTF8) return false;
260 return true;
261
262
263 case 0x600: // National standards range
264 if (encoding != kCFStringEncodingASCII) return false;
265 return true;
266
267 case 0x800: // ISO 2022 range
268 return false; // It's modal encoding
269
270
271 case 0xB00:
272 if (encoding == kCFStringEncodingNonLossyASCII) return false;
273 return true;
274
275 case 0xC00: // EBCDIC
276 return false;
277
278 default:
279 return ((encoding & 0x0000FF00) > 0x0C00 ? false : true);
280 }
281 }
282
283
284 /* Desperately using extern here */
285 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding;
286 CF_EXPORT CFStringEncoding __CFStringComputeEightBitStringEncoding(void);
287
288 CF_INLINE CFStringEncoding __CFStringGetEightBitStringEncoding(void) {
289 if (__CFDefaultEightBitStringEncoding == kCFStringEncodingInvalidId) __CFStringComputeEightBitStringEncoding();
290 return __CFDefaultEightBitStringEncoding;
291 }
292
293 enum {
294 __kCFVarWidthLocalBufferSize = 1008
295 };
296
297 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
298 union {
299 UInt8 *ascii;
300 UniChar *unicode;
301 } chars;
302 Boolean isASCII; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
303 Boolean shouldFreeChars; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
304 Boolean _unused1;
305 Boolean _unused2;
306 CFAllocatorRef allocator; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
307 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 */
308 UInt8 localBuffer[__kCFVarWidthLocalBufferSize]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
309 } CFVarWidthCharBuffer;
310
311
312 /* 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.
313 !!! 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.
314 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
315 */
316 CF_EXPORT Boolean __CFStringDecodeByteStream2(const UInt8 *bytes, UInt32 len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr);
317 CF_EXPORT Boolean __CFStringDecodeByteStream3(const UInt8 *bytes, CFIndex len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr, UInt32 converterFlags);
318
319
320 /* 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.
321 */
322 CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
323 CF_EXPORT void __CFSetCharToUniCharFunc(Boolean (*func)(UInt32 flags, UInt8 ch, UniChar *unicodeChar));
324 CF_EXPORT UniChar __CFCharToUniCharTable[256];
325
326 /* Character class functions UnicodeData-2_1_5.txt
327 */
328 CF_INLINE Boolean __CFIsWhitespace(UniChar theChar) {
329 return ((theChar < 0x21) || (theChar > 0x7E && theChar < 0xA1) || (theChar >= 0x2000 && theChar <= 0x200B) || (theChar == 0x3000)) ? true : false;
330 }
331
332 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
333 */
334 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer *buf, CFIndex idx) {
335 if (buf->directBuffer) {
336 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
337 return buf->directBuffer[idx + buf->rangeToBuffer.location];
338 }
339 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
340 if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0xFFFF;
341 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
342 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
343 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
344 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
345 }
346 return buf->buffer[idx - buf->bufferedRangeStart];
347 }
348
349 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
350 */
351 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer *buf, CFIndex idx) {
352 if (buf->directBuffer) return buf->directBuffer[idx + buf->rangeToBuffer.location];
353 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
354 if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
355 buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
356 if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
357 CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
358 }
359 return buf->buffer[idx - buf->bufferedRangeStart];
360 }
361
362
363 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
364 */
365 CF_EXPORT void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef formatString, va_list args);
366 CF_EXPORT CFStringRef _CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef format, va_list arguments);
367
368 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
369 */
370 enum {_CFStringErrNone = 0, _CFStringErrNotMutable = 1, _CFStringErrNilArg = 2, _CFStringErrBounds = 3};
371 CF_EXPORT int __CFStringCheckAndReplace(CFMutableStringRef str, CFRange range, CFStringRef replacement);
372 CF_EXPORT Boolean __CFStringNoteErrors(void); // Should string errors raise?
373
374 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
375 */
376 CF_EXPORT Boolean __CFStringIsEightBit(CFStringRef str);
377
378 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
379 */
380 CF_EXPORT int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str, CFIndex idx, UniChar *ch);
381 CF_EXPORT int _CFStringCheckAndGetCharacters(CFStringRef str, CFRange range, UniChar *buffer);
382 CF_EXPORT CFIndex _CFStringGetLength2(CFStringRef str);
383 CF_EXPORT CFHashCode __CFStringHash(CFTypeRef cf);
384 CF_EXPORT CFHashCode CFStringHashISOLatin1CString(const uint8_t *bytes, CFIndex len);
385 CF_EXPORT CFHashCode CFStringHashCString(const uint8_t *bytes, CFIndex len);
386 CF_EXPORT CFHashCode CFStringHashCharacters(const UniChar *characters, CFIndex len);
387 CF_EXPORT CFHashCode CFStringHashNSString(CFStringRef str);
388
389 /* Currently for CFString usage, for handling out-of-memory conditions.
390 The callback might not return; if it does, true indicates the error was potentially dealt with; false means no.
391 Typically true means OK to continue executing.
392 */
393 typedef Boolean (*CFBadErrorCallBack)(CFTypeRef obj, CFStringRef domain, CFStringRef msg);
394 CF_EXPORT CFBadErrorCallBack _CFGetOutOfMemoryErrorCallBack(void);
395 CF_EXPORT void _CFSetOutOfMemoryErrorCallBack(CFBadErrorCallBack callback);
396
397
398
399 CF_EXTERN_C_END
400
401
402 // ---- Binary plist material ----------------------------------------
403
404 typedef const struct __CFKeyedArchiverUID * CFKeyedArchiverUIDRef;
405 extern CFTypeID _CFKeyedArchiverUIDGetTypeID(void);
406 extern CFKeyedArchiverUIDRef _CFKeyedArchiverUIDCreate(CFAllocatorRef allocator, uint32_t value);
407 extern uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid);
408
409
410 enum {
411 kCFBinaryPlistMarkerNull = 0x00,
412 kCFBinaryPlistMarkerFalse = 0x08,
413 kCFBinaryPlistMarkerTrue = 0x09,
414 kCFBinaryPlistMarkerFill = 0x0F,
415 kCFBinaryPlistMarkerInt = 0x10,
416 kCFBinaryPlistMarkerReal = 0x20,
417 kCFBinaryPlistMarkerDate = 0x33,
418 kCFBinaryPlistMarkerData = 0x40,
419 kCFBinaryPlistMarkerASCIIString = 0x50,
420 kCFBinaryPlistMarkerUnicode16String = 0x60,
421 kCFBinaryPlistMarkerUID = 0x80,
422 kCFBinaryPlistMarkerArray = 0xA0,
423 kCFBinaryPlistMarkerSet = 0xC0,
424 kCFBinaryPlistMarkerDict = 0xD0
425 };
426
427 typedef struct {
428 uint8_t _magic[6];
429 uint8_t _version[2];
430 } CFBinaryPlistHeader;
431
432 typedef struct {
433 uint8_t _unused[6];
434 uint8_t _offsetIntSize;
435 uint8_t _objectRefSize;
436 uint64_t _numObjects;
437 uint64_t _topObject;
438 uint64_t _offsetTableOffset;
439 } CFBinaryPlistTrailer;
440
441 extern bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes, uint64_t datalen, uint8_t *marker, uint64_t *offset, CFBinaryPlistTrailer *trailer);
442 extern bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFIndex idx, uint64_t *offset, CFMutableDictionaryRef objects);
443 extern bool __CFBinaryPlistGetOffsetForValueFromDictionary2(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFTypeRef key, uint64_t *koffset, uint64_t *voffset, CFMutableDictionaryRef objects);
444 extern bool __CFBinaryPlistCreateObject(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFAllocatorRef allocator, CFOptionFlags mutabilityOption, CFMutableDictionaryRef objects, CFPropertyListRef *plist);
445 extern CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef stream);
446
447
448 // ---- Used by property list parsing in Foundation
449
450 extern CFTypeRef _CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
451
452
453 // ---- Miscellaneous material ----------------------------------------
454
455 #include <CoreFoundation/CFBag.h>
456 #include <CoreFoundation/CFSet.h>
457 #include <math.h>
458
459 CF_EXTERN_C_BEGIN
460
461 CF_EXPORT CFTypeID CFTypeGetTypeID(void);
462
463 CF_EXPORT CFTypeRef _CFRetainGC(CFTypeRef cf);
464 CF_EXPORT void _CFReleaseGC(CFTypeRef cf);
465
466 CF_EXPORT void _CFArraySetCapacity(CFMutableArrayRef array, CFIndex cap);
467 CF_EXPORT void _CFBagSetCapacity(CFMutableBagRef bag, CFIndex cap);
468 CF_EXPORT void _CFDictionarySetCapacity(CFMutableDictionaryRef dict, CFIndex cap);
469 CF_EXPORT void _CFSetSetCapacity(CFMutableSetRef set, CFIndex cap);
470
471 CF_EXPORT void CFCharacterSetCompact(CFMutableCharacterSetRef theSet);
472 CF_EXPORT void CFCharacterSetFast(CFMutableCharacterSetRef theSet);
473
474 CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex idx);
475 CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount);
476
477
478 /* Enumeration
479 Call CFStartSearchPathEnumeration() once, then call
480 CFGetNextSearchPathEnumeration() one or more times with the returned state.
481 The return value of CFGetNextSearchPathEnumeration() should be used as
482 the state next time around.
483 When CFGetNextSearchPathEnumeration() returns 0, you're done.
484 */
485 typedef CFIndex CFSearchPathEnumerationState;
486 CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
487 CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
488
489 /* For use by NSNumber and CFNumber.
490 Hashing algorithm for CFNumber:
491 M = Max CFHashCode (assumed to be unsigned)
492 For positive integral values: (N * HASHFACTOR) mod M
493 For negative integral values: ((-N) * HASHFACTOR) mod M
494 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
495 HASHFACTOR is 2654435761, from Knuth's multiplicative method
496 */
497 #define HASHFACTOR 2654435761U
498
499 CF_INLINE CFHashCode _CFHashInt(long i) {
500 return ((i > 0) ? (CFHashCode)(i) : (CFHashCode)(-i)) * HASHFACTOR;
501 }
502
503 CF_INLINE CFHashCode _CFHashDouble(double d) {
504 double dInt;
505 if (d < 0) d = -d;
506 dInt = rint(d);
507 return (CFHashCode)((HASHFACTOR * (CFHashCode)fmod(dInt, (double)ULONG_MAX)) + ((d - dInt) * ULONG_MAX));
508 }
509
510
511 /* 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.
512 */
513 CF_EXPORT CFStringRef _CFErrorCreateLocalizedDescription(CFErrorRef err);
514 CF_EXPORT CFStringRef _CFErrorCreateLocalizedFailureReason(CFErrorRef err);
515 CF_EXPORT CFStringRef _CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err);
516 CF_EXPORT CFStringRef _CFErrorCreateDebugDescription(CFErrorRef err);
517
518 CF_EXPORT CFURLRef _CFURLAlloc(CFAllocatorRef allocator);
519 CF_EXPORT void _CFURLInitWithString(CFURLRef url, CFStringRef string, CFURLRef baseURL);
520 CF_EXPORT void _CFURLInitFSPath(CFURLRef url, CFStringRef path);
521 CF_EXPORT Boolean _CFStringIsLegalURLString(CFStringRef string);
522 CF_EXPORT void *__CFURLReservedPtr(CFURLRef url);
523 CF_EXPORT void __CFURLSetReservedPtr(CFURLRef url, void *ptr);
524 CF_EXPORT CFStringEncoding _CFURLGetEncoding(CFURLRef url);
525
526 CF_EXPORT Boolean _CFRunLoopFinished(CFRunLoopRef rl, CFStringRef mode);
527
528 CF_EXPORT CFIndex _CFStreamInstanceSize(void);
529
530 #if (DEPLOYMENT_TARGET_MACOSX || 0)
531 #if !defined(__CFReadTSR)
532 #include <mach/mach_time.h>
533 #define __CFReadTSR() mach_absolute_time()
534 #endif
535 #elif defined(__WIN32__)
536 CF_INLINE UInt64 __CFReadTSR(void) {
537 LARGE_INTEGER freq;
538 QueryPerformanceCounter(&freq);
539 return freq.QuadPart;
540 }
541 #endif
542
543 #define CF_HAS_NSOBJECT 1
544 #define CF_HAS_NSARRAY 1
545 #define CF_HAS_NSMUTABLEARRAY 1
546 #define CF_HAS_NSDICTIONARY 1
547 #define CF_HAS_NSMUTABLEDICTIONARY 1
548 #define CF_HAS_NSSET 1
549 #define CF_HAS_NSMUTABLESET 1
550 #define CF_HAS_NSBATCH2 1
551
552 CF_EXTERN_C_END
553
554 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */
555