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