]> git.saurik.com Git - apple/cf.git/blob - ForFoundationOnly.h
CF-1153.18.tar.gz
[apple/cf.git] / ForFoundationOnly.h
1 /*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* ForFoundationOnly.h
25 Copyright (c) 1998-2014, Apple Inc. All rights reserved.
26 */
27
28 #if !CF_BUILDING_CF && !NSBUILDINGFOUNDATION
29 #error The header file ForFoundationOnly.h is for the exclusive use of the
30 #error CoreFoundation and Foundation projects. No other project should include it.
31 #endif
32
33 #if !defined(__COREFOUNDATION_FORFOUNDATIONONLY__)
34 #define __COREFOUNDATION_FORFOUNDATIONONLY__ 1
35
36 #include <CoreFoundation/CFBase.h>
37 #include <CoreFoundation/CFString.h>
38 #include <CoreFoundation/CFArray.h>
39 #include <CoreFoundation/CFData.h>
40 #include <CoreFoundation/CFDictionary.h>
41 #include <CoreFoundation/CFSet.h>
42 #include <CoreFoundation/CFPriv.h>
43 #include <CoreFoundation/CFPropertyList.h>
44 #include <CoreFoundation/CFError.h>
45 #include <CoreFoundation/CFStringEncodingExt.h>
46 #include <CoreFoundation/CFNumberFormatter.h>
47 #include <limits.h>
48
49 // NOTE: miscellaneous declarations are at the end
50
51 // ---- CFRuntime material ----------------------------------------
52
53 CF_EXTERN_C_BEGIN
54
55 #if DEPLOYMENT_TARGET_LINUX
56 #include <malloc.h>
57 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
58 #include <malloc/malloc.h>
59 #endif
60
61 CF_EXTERN_C_END
62
63 // ---- CFBundle material ----------------------------------------
64
65 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
66 #include <CoreFoundation/CFBundlePriv.h>
67
68 CF_EXTERN_C_BEGIN
69
70 CF_EXPORT const CFStringRef _kCFBundleExecutablePathKey;
71 CF_EXPORT const CFStringRef _kCFBundleInfoPlistURLKey;
72 CF_EXPORT const CFStringRef _kCFBundleRawInfoPlistURLKey;
73 CF_EXPORT const CFStringRef _kCFBundleNumericVersionKey;
74 CF_EXPORT const CFStringRef _kCFBundleResourcesFileMappedKey;
75 CF_EXPORT const CFStringRef _kCFBundleAllowMixedLocalizationsKey;
76 CF_EXPORT const CFStringRef _kCFBundleInitialPathKey;
77 CF_EXPORT const CFStringRef _kCFBundleResolvedPathKey;
78 CF_EXPORT const CFStringRef _kCFBundlePrincipalClassKey;
79
80 #if __BLOCKS__
81 CF_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));
82 #endif
83
84 CF_EXPORT Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
85 CF_EXPORT CFErrorRef _CFBundleCreateError(CFAllocatorRef allocator, CFBundleRef bundle, CFIndex code);
86
87 CF_EXTERN_C_END
88
89 #endif
90
91 // ---- CFPreferences material ----------------------------------------
92
93 #define DEBUG_PREFERENCES_MEMORY 0
94
95 #if DEBUG_PREFERENCES_MEMORY
96 #include "../Tests/CFCountingAllocator.h"
97 #endif
98
99 CF_EXTERN_C_BEGIN
100
101 extern void _CFPreferencesPurgeDomainCache(void);
102
103 typedef 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
115 CF_EXPORT CFAllocatorRef __CFPreferencesAllocator(void);
116 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFVolatileDomainCallBacks;
117 CF_EXPORT const _CFPreferencesDomainCallBacks __kCFXMLPropertyListDomainCallBacks;
118
119 typedef struct __CFPreferencesDomain * CFPreferencesDomainRef;
120
121 CF_EXPORT CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks);
122 CF_EXPORT CFPreferencesDomainRef _CFPreferencesStandardDomain(CFStringRef domainName, CFStringRef userName, CFStringRef hostName);
123
124 CF_EXPORT CFTypeRef _CFPreferencesDomainCreateValueForKey(CFPreferencesDomainRef domain, CFStringRef key);
125 CF_EXPORT void _CFPreferencesDomainSet(CFPreferencesDomainRef domain, CFStringRef key, CFTypeRef value);
126 CF_EXPORT Boolean _CFPreferencesDomainSynchronize(CFPreferencesDomainRef domain);
127
128 CF_EXPORT CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName);
129 CF_EXPORT Boolean _CFSynchronizeDomainCache(void);
130
131 CF_EXPORT void _CFPreferencesDomainSetDictionary(CFPreferencesDomainRef domain, CFDictionaryRef dict);
132 CF_EXPORT CFDictionaryRef _CFPreferencesDomainDeepCopyDictionary(CFPreferencesDomainRef domain);
133 CF_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 */
136 CF_EXPORT void _CFPreferencesDomainSetIsWorldReadable(CFPreferencesDomainRef domain, Boolean isWorldReadable);
137
138 typedef 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
144 CF_EXPORT _CFApplicationPreferences *_CFStandardApplicationPreferences(CFStringRef appName);
145 CF_EXPORT _CFApplicationPreferences *_CFApplicationPreferencesCreateWithUser(CFStringRef userName, CFStringRef appName);
146 CF_EXPORT void _CFDeallocateApplicationPreferences(_CFApplicationPreferences *self);
147 CF_EXPORT CFTypeRef _CFApplicationPreferencesCreateValueForKey(_CFApplicationPreferences *prefs, CFStringRef key);
148 CF_EXPORT void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef defaultName, CFTypeRef value);
149 CF_EXPORT void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName);
150 CF_EXPORT Boolean _CFApplicationPreferencesSynchronize(_CFApplicationPreferences *self);
151 CF_EXPORT void _CFApplicationPreferencesUpdate(_CFApplicationPreferences *self); // same as updateDictRep
152 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentation3(_CFApplicationPreferences *self, CFDictionaryRef hint, CFDictionaryRef insertion, CFPreferencesDomainRef afterDomain);
153 CF_EXPORT CFDictionaryRef _CFApplicationPreferencesCopyRepresentationWithHint(_CFApplicationPreferences *self, CFDictionaryRef hint); // same as dictRep
154 CF_EXPORT void _CFApplicationPreferencesSetStandardSearchList(_CFApplicationPreferences *appPreferences);
155 CF_EXPORT void _CFApplicationPreferencesSetCacheForApp(_CFApplicationPreferences *appPrefs, CFStringRef appName);
156 CF_EXPORT void _CFApplicationPreferencesAddSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
157 CF_EXPORT void _CFApplicationPreferencesRemoveSuitePreferences(_CFApplicationPreferences *appPrefs, CFStringRef suiteName);
158
159 CF_EXPORT void _CFApplicationPreferencesAddDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain, Boolean addAtTop);
160 CF_EXPORT Boolean _CFApplicationPreferencesContainsDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
161 CF_EXPORT void _CFApplicationPreferencesRemoveDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain);
162
163 CF_EXPORT CFTypeRef _CFApplicationPreferencesSearchDownToDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef stopper, CFStringRef key);
164
165
166 CF_EXTERN_C_END
167
168
169
170 // ---- CFString material ----------------------------------------
171
172 #include <CoreFoundation/CFStringEncodingExt.h>
173
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
183 // This can be made into an exception for post-10.10 apps
184 #define NSSTRING_POSSIBLE_RANGEERROR(range, len) \
185 if (__CFStringNoteErrors()) { \
186 static bool warnonce = false; \
187 if (!warnonce) { \
188 warnonce = true; \
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); \
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
206 CF_EXTERN_C_BEGIN
207
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 */
220 CF_EXPORT CFIndex __CFStringEncodeByteStream(CFStringRef string, CFIndex rangeLoc, CFIndex rangeLen, Boolean generatingExternalFile, CFStringEncoding encoding, char lossByte, UInt8 *buffer, CFIndex max, CFIndex *usedBufLen);
221
222 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);
223
224 CF_EXPORT void __CFStringAppendBytes(CFMutableStringRef str, const char *cStr, CFIndex appendedLength, CFStringEncoding encoding);
225
226 CF_INLINE Boolean __CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding) {
227 switch (encoding & 0x0000FF00) {
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;
232
233 case 0x100: // Unicode range
234 if (encoding != kCFStringEncodingUTF8) return false;
235 return true;
236
237 case 0x200: // ISO range
238 if (encoding == kCFStringEncodingISOLatinArabic) return false;
239 return true;
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
248 case 0xA00: // Misc standard range
249 if ((encoding == kCFStringEncodingShiftJIS) || (encoding == kCFStringEncodingHZ_GB_2312) || (encoding == kCFStringEncodingUTF7_IMAP)) return false;
250 return true;
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
264
265 /* Desperately using extern here */
266 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding;
267 CF_EXPORT CFStringEncoding __CFStringComputeEightBitStringEncoding(void);
268
269 CF_INLINE CFStringEncoding __CFStringGetEightBitStringEncoding(void) {
270 if (__CFDefaultEightBitStringEncoding == kCFStringEncodingInvalidId) __CFStringComputeEightBitStringEncoding();
271 return __CFDefaultEightBitStringEncoding;
272 }
273
274 enum {
275 __kCFVarWidthLocalBufferSize = 1008
276 };
277
278 typedef 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 */
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 */
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 */
297 CF_EXPORT Boolean __CFStringDecodeByteStream2(const UInt8 *bytes, UInt32 len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr);
298 CF_EXPORT Boolean __CFStringDecodeByteStream3(const UInt8 *bytes, CFIndex len, CFStringEncoding encoding, Boolean alwaysUnicode, CFVarWidthCharBuffer *buffer, Boolean *useClientsMemoryPtr, UInt32 converterFlags);
299
300
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.
302 */
303 CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
304
305 /* Character class functions UnicodeData-2_1_5.txt
306 */
307 CF_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 */
313 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer *buf, CFIndex idx) {
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]);
317 if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
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 */
328 CF_INLINE UniChar __CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer *buf, CFIndex idx) {
329 if (buf->directUniCharBuffer) return buf->directUniCharBuffer[idx + buf->rangeToBuffer.location];
330 if (buf->directCStringBuffer) return (UniChar)(buf->directCStringBuffer[idx + buf->rangeToBuffer.location]);
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 */
343 CF_EXPORT void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef formatString, va_list args);
344 CF_EXPORT CFStringRef _CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc, CFStringRef (*copyDescFunc)(void *, const void *loc), CFDictionaryRef formatOptions, CFStringRef format, va_list arguments);
345
346 CF_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);
347 CF_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
349 /* For NSString (and NSAttributedString) usage, mutate with isMutable check
350 */
351 enum {_CFStringErrNone = 0, _CFStringErrNotMutable = 1, _CFStringErrNilArg = 2, _CFStringErrBounds = 3};
352 CF_EXPORT int __CFStringCheckAndReplace(CFMutableStringRef str, CFRange range, CFStringRef replacement);
353 CF_EXPORT Boolean __CFStringNoteErrors(void); // Should string errors raise?
354
355 /* For NSString usage, guarantees that the contents can be extracted as 8-bit bytes in the __CFStringGetEightBitStringEncoding().
356 */
357 CF_EXPORT Boolean __CFStringIsEightBit(CFStringRef str);
358
359 /* For NSCFString usage, these do range check (where applicable) but don't check for ObjC dispatch
360 */
361 CF_EXPORT int _CFStringCheckAndGetCharacterAtIndex(CFStringRef str, CFIndex idx, UniChar *ch);
362 CF_EXPORT int _CFStringCheckAndGetCharacters(CFStringRef str, CFRange range, UniChar *buffer);
363 CF_EXPORT CFIndex _CFStringGetLength2(CFStringRef str);
364 CF_EXPORT CFHashCode __CFStringHash(CFTypeRef cf);
365 CF_EXPORT CFHashCode CFStringHashISOLatin1CString(const uint8_t *bytes, CFIndex len);
366 CF_EXPORT CFHashCode CFStringHashCString(const uint8_t *bytes, CFIndex len);
367 CF_EXPORT CFHashCode CFStringHashCharacters(const UniChar *characters, CFIndex len);
368 CF_EXPORT CFHashCode CFStringHashNSString(CFStringRef str);
369
370
371 CF_EXTERN_C_END
372
373
374 // ---- Binary plist material ----------------------------------------
375
376 typedef const struct __CFKeyedArchiverUID * CFKeyedArchiverUIDRef;
377 CF_EXPORT CFTypeID _CFKeyedArchiverUIDGetTypeID(void);
378 CF_EXPORT CFKeyedArchiverUIDRef _CFKeyedArchiverUIDCreate(CFAllocatorRef allocator, uint32_t value);
379 CF_EXPORT uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid);
380
381
382 enum {
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,
395 kCFBinaryPlistMarkerSet = 0xC0,
396 kCFBinaryPlistMarkerDict = 0xD0
397 };
398
399 typedef struct {
400 uint8_t _magic[6];
401 uint8_t _version[2];
402 } CFBinaryPlistHeader;
403
404 typedef struct {
405 uint8_t _unused[5];
406 uint8_t _sortVersion;
407 uint8_t _offsetIntSize;
408 uint8_t _objectRefSize;
409 uint64_t _numObjects;
410 uint64_t _topObject;
411 uint64_t _offsetTableOffset;
412 } CFBinaryPlistTrailer;
413
414
415 CF_EXPORT bool __CFBinaryPlistGetTopLevelInfo(const uint8_t *databytes, uint64_t datalen, uint8_t *marker, uint64_t *offset, CFBinaryPlistTrailer *trailer);
416 CF_EXPORT bool __CFBinaryPlistGetOffsetForValueFromArray2(const uint8_t *databytes, uint64_t datalen, uint64_t startOffset, const CFBinaryPlistTrailer *trailer, CFIndex idx, uint64_t *offset, CFMutableDictionaryRef objects);
417 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);
418 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);
419 CF_EXPORT CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef stream);
420 CF_EXPORT CFIndex __CFBinaryPlistWriteToStreamWithEstimate(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate); // will be removed soon
421 CF_EXPORT CFIndex __CFBinaryPlistWriteToStreamWithOptions(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate, CFOptionFlags options); // will be removed soon
422 CF_EXPORT CFIndex __CFBinaryPlistWrite(CFPropertyListRef plist, CFTypeRef stream, uint64_t estimate, CFOptionFlags options, CFErrorRef *error);
423
424 // ---- Used by property list parsing in Foundation
425
426 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
427
428 CF_EXPORT CFTypeRef _CFPropertyListCreateFromXMLString(CFAllocatorRef allocator, CFStringRef xmlString, CFOptionFlags option, CFStringRef *errorString, Boolean allowNewTypes, CFPropertyListFormat *format);
429
430 // ---- Sudden Termination material ----------------------------------------
431
432 #if DEPLOYMENT_TARGET_MACOSX
433
434 CF_EXPORT void _CFSuddenTerminationDisable(void);
435 CF_EXPORT void _CFSuddenTerminationEnable(void);
436 CF_EXPORT void _CFSuddenTerminationExitIfTerminationEnabled(int exitStatus);
437 CF_EXPORT void _CFSuddenTerminationExitWhenTerminationEnabled(int exitStatus);
438 CF_EXPORT size_t _CFSuddenTerminationDisablingCount(void);
439
440 #endif
441
442 // ---- Thread-specific data --------------------------------------------
443
444 // Get some thread specific data from a pre-assigned slot.
445 CF_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.
448 CF_EXPORT void *_CFSetTSD(uint32_t slot, void *newVal, void (*destructor)(void *));
449
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
454 CF_EXPORT int _NS_stat(const char *name, struct _stat *st);
455 CF_EXPORT int _NS_mkdir(const char *name);
456 CF_EXPORT int _NS_rmdir(const char *name);
457 CF_EXPORT int _NS_chmod(const char *name, int mode);
458 CF_EXPORT int _NS_unlink(const char *name);
459 CF_EXPORT char *_NS_getcwd(char *dstbuf, size_t size); // Warning: this doesn't support dstbuf as null even though 'getcwd' does
460 CF_EXPORT char *_NS_getenv(const char *name);
461 CF_EXPORT int _NS_rename(const char *oldName, const char *newName);
462 CF_EXPORT int _NS_open(const char *name, int oflag, int pmode);
463 CF_EXPORT int _NS_mkstemp(char *name, int bufSize);
464 #endif
465
466 // ---- Miscellaneous material ----------------------------------------
467
468 #include <CoreFoundation/CFBag.h>
469 #include <CoreFoundation/CFSet.h>
470 #include <math.h>
471
472 CF_EXTERN_C_BEGIN
473
474 CF_EXPORT CFTypeID CFTypeGetTypeID(void);
475
476 CF_EXPORT void _CFArraySetCapacity(CFMutableArrayRef array, CFIndex cap);
477 CF_EXPORT void _CFBagSetCapacity(CFMutableBagRef bag, CFIndex cap);
478 CF_EXPORT void _CFDictionarySetCapacity(CFMutableDictionaryRef dict, CFIndex cap);
479 CF_EXPORT void _CFSetSetCapacity(CFMutableSetRef set, CFIndex cap);
480
481 CF_EXPORT void CFCharacterSetCompact(CFMutableCharacterSetRef theSet);
482 CF_EXPORT void CFCharacterSetFast(CFMutableCharacterSetRef theSet);
483
484 CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex idx);
485 CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount);
486
487
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 */
495 typedef CFIndex CFSearchPathEnumerationState;
496 CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
497 CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
498
499 /* For use by NSNumber and CFNumber.
500 Hashing algorithm for CFNumber:
501 M = Max CFHashCode (assumed to be unsigned)
502 For positive integral values: (N * HASHFACTOR) mod M
503 For negative integral values: ((-N) * HASHFACTOR) mod M
504 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
505 HASHFACTOR is 2654435761, from Knuth's multiplicative method
506 */
507 #define HASHFACTOR 2654435761U
508
509 CF_INLINE CFHashCode _CFHashInt(long i) {
510 return ((i > 0) ? (CFHashCode)(i) : (CFHashCode)(-i)) * HASHFACTOR;
511 }
512
513 CF_INLINE CFHashCode _CFHashDouble(double d) {
514 double dInt;
515 if (d < 0) d = -d;
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));
519 }
520
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 */
524 CF_EXPORT CFStringRef _CFErrorCreateLocalizedDescription(CFErrorRef err);
525 CF_EXPORT CFStringRef _CFErrorCreateLocalizedFailureReason(CFErrorRef err);
526 CF_EXPORT CFStringRef _CFErrorCreateLocalizedRecoverySuggestion(CFErrorRef err);
527 CF_EXPORT CFStringRef _CFErrorCreateDebugDescription(CFErrorRef err);
528
529 CF_EXPORT void *__CFURLReservedPtr(CFURLRef url);
530 CF_EXPORT void __CFURLSetReservedPtr(CFURLRef url, void *ptr);
531 CF_EXPORT CFStringEncoding _CFURLGetEncoding(CFURLRef url);
532
533 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
534 CF_EXPORT Boolean _CFRunLoopFinished(CFRunLoopRef rl, CFStringRef mode);
535 #endif
536
537 CF_EXPORT CFIndex _CFStreamInstanceSize(void);
538
539 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
540 typedef 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
550 extern kern_return_t _CFDiscorporateMemoryAllocate(CFDiscorporateMemory *hm, size_t size, bool purgeable);
551 extern kern_return_t _CFDiscorporateMemoryDeallocate(CFDiscorporateMemory *hm);
552 extern kern_return_t _CFDiscorporateMemoryDematerialize(CFDiscorporateMemory *hm);
553 extern kern_return_t _CFDiscorporateMemoryMaterialize(CFDiscorporateMemory *hm);
554 #endif
555
556 enum {
557 kCFNumberFormatterOrdinalStyle = 6,
558 kCFNumberFormatterDurationStyle = 7,
559 };
560
561 // This is for NSNumberFormatter use only!
562 CF_EXPORT void *_CFNumberFormatterGetFormatter(CFNumberFormatterRef formatter);
563
564 CF_EXPORT CFRange _CFDataFindBytes(CFDataRef data, CFDataRef dataToFind, CFRange searchRange, CFDataSearchFlags compareOptions);
565
566
567 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
568 #if !defined(__CFReadTSR)
569 #include <mach/mach_time.h>
570 #define __CFReadTSR() mach_absolute_time()
571 #endif
572 #elif DEPLOYMENT_TARGET_WINDOWS
573 #if 0
574 CF_INLINE UInt64 __CFReadTSR(void) {
575 LARGE_INTEGER freq;
576 QueryPerformanceCounter(&freq);
577 return freq.QuadPart;
578 }
579 #endif
580 #endif
581
582
583 CF_EXTERN_C_END
584
585 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */
586