2 * Copyright (c) 2010 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
29 NOT TO BE USED OUTSIDE CF!
33 #error The header file CFInternal.h is for the exclusive use of CoreFoundation. No other project should include it.
36 #if !defined(__COREFOUNDATION_CFINTERNAL__)
37 #define __COREFOUNDATION_CFINTERNAL__ 1
41 #include <CoreFoundation/CFBase.h>
42 #include <CoreFoundation/CFURL.h>
43 #include <CoreFoundation/CFString.h>
44 #include <CoreFoundation/CFDate.h>
45 #include <CoreFoundation/CFArray.h>
46 #include <CoreFoundation/CFRunLoop.h>
47 #include <CoreFoundation/CFStorage.h>
48 #include <CoreFoundation/CFLogUtilities.h>
49 #include <CoreFoundation/CFRuntime.h>
51 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
53 #include <libkern/OSAtomic.h>
54 #include <mach/mach_time.h>
55 #include <mach/mach.h>
58 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
63 #if DEPLOYMENT_TARGET_WINDOWS
68 #if defined(__BIG_ENDIAN__)
69 #define __CF_BIG_ENDIAN__ 1
70 #define __CF_LITTLE_ENDIAN__ 0
73 #if defined(__LITTLE_ENDIAN__)
74 #define __CF_LITTLE_ENDIAN__ 1
75 #define __CF_BIG_ENDIAN__ 0
79 #include <CoreFoundation/ForFoundationOnly.h>
81 CF_EXPORT
const char *_CFProcessName(void);
82 CF_EXPORT CFStringRef
_CFProcessNameString(void);
84 CF_EXPORT Boolean
_CFIsCFM(void);
86 CF_EXPORT Boolean
_CFGetCurrentDirectory(char *path
, int maxlen
);
88 CF_EXPORT CFStringRef
_CFGetUserName(void);
90 CF_EXPORT CFArrayRef
_CFGetWindowsBinaryDirectories(void);
92 CF_EXPORT CFStringRef
_CFStringCreateHostName(void);
94 CF_EXPORT
void _CFMachPortInstallNotifyPort(CFRunLoopRef rl
, CFStringRef mode
);
97 #define HALT do {asm __volatile__("trap"); kill(getpid(), 9); } while (0)
98 #elif defined(__i386__) || defined(__x86_64__)
100 #define HALT do {asm __volatile__("int3"); kill(getpid(), 9); } while (0)
101 #elif defined(_MSC_VER)
102 #define HALT do { DebugBreak(); abort(); } while (0)
104 #error Compiler not supported
108 #define HALT do {asm __volatile__("bkpt 0xCF"); kill(getpid(), 9); } while (0)
112 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
115 CFLog(prio, CFSTR(desc), a1, a2, a3, a4, a5); \
120 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
124 #define CFAssert(condition, priority, description) \
125 __CFAssert((condition), (priority), description, 0, 0, 0, 0, 0)
126 #define CFAssert1(condition, priority, description, a1) \
127 __CFAssert((condition), (priority), description, (a1), 0, 0, 0, 0)
128 #define CFAssert2(condition, priority, description, a1, a2) \
129 __CFAssert((condition), (priority), description, (a1), (a2), 0, 0, 0)
130 #define CFAssert3(condition, priority, description, a1, a2, a3) \
131 __CFAssert((condition), (priority), description, (a1), (a2), (a3), 0, 0)
132 #define CFAssert4(condition, priority, description, a1, a2, a3, a4) \
133 __CFAssert((condition), (priority), description, (a1), (a2), (a3), (a4), 0)
135 #define __kCFLogAssertion 3
138 extern void __CFGenericValidateType_(CFTypeRef cf
, CFTypeID type
, const char *func
);
139 #define __CFGenericValidateType(cf, type) __CFGenericValidateType_(cf, type, __PRETTY_FUNCTION__)
141 #define __CFGenericValidateType(cf, type) ((void)0)
144 #define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3)
145 #define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3)
147 /* Bit manipulation macros */
148 /* Bits are numbered from 31 on left to 0 on right */
149 /* May or may not work if you use them on bitfields in types other than UInt32, bitfields the full width of a UInt32, or anything else for which they were not designed. */
150 /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */
151 #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1))
152 #define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2))
153 #define __CFBitfieldSetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfieldMask(N1, N2)) | (((X) << (N2)) & __CFBitfieldMask(N1, N2)))
154 #define __CFBitfieldMaxValue(N1, N2) __CFBitfieldGetValue(0xFFFFFFFFUL, (N1), (N2))
156 #define __CFBitIsSet(V, N) (((V) & (1UL << (N))) != 0)
157 #define __CFBitSet(V, N) ((V) |= (1UL << (N)))
158 #define __CFBitClear(V, N) ((V) &= ~(1UL << (N)))
161 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
162 // The fixed range 50 - 59 of pthread_specific keys is reserved
163 // for CoreFoundation; see <System/pthread_machdep.h>.
164 // 60 - 69 are reserved for Foundation; Foundation uses 64 - 69
165 // and reserves 60-63 for CoreFoundation.
166 // Foundation knows about the value of __CFTSDKeyAutoreleaseData1
168 __CFTSDKeyUnused50
= 50,
169 __CFTSDKeyAllocator
= 51,
170 __CFTSDKeyExceptionData
= 52,
171 __CFTSDKeyRunLoopCntr
= 53,
172 __CFTSDKeyRunLoop
= 54,
173 __CFTSDKeyICUConverter
= 55,
174 __CFTSDKeyCollatorLocale
= 56,
175 __CFTSDKeyCollatorUCollator
= 57,
176 __CFTSDKeyIsInNSCache
= 58,
177 __CFTSDKeyIsInCFLog
= 59,
178 __CFTSDKeyIsInGCDMainQ
= 60,
179 __CFTSDKeyUnused61
= 61,
180 __CFTSDKeyAutoreleaseData1
= 62,
181 __CFTSDKeyAutoreleaseData2
= 63, // autorelease pool stuff must be higher than run loop constants
184 extern int pthread_key_init_np(int, void (*)(void *));
187 #if DEPLOYMENT_TARGET_WINDOWS
188 typedef struct ___CFThreadSpecificData
{
194 void *_icuThreadData
;
196 // If you add things to this struct, add cleanup to __CFFinalizeThreadData()
197 } __CFThreadSpecificData
;
199 extern __CFThreadSpecificData
*__CFGetThreadSpecificData(void);
200 __private_extern__
void __CFFinalizeThreadData(void *arg
);
201 extern DWORD __CFTSDKey
;
203 // implemented in windowsSyncHelper.c
204 __private_extern__ __CFThreadSpecificData
*__CFGetThreadSpecificData_inline(void);
208 #define __kCFAllocatorTypeID_CONST 2
210 CF_INLINE CFAllocatorRef
__CFGetDefaultAllocator(void) {
211 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
212 CFAllocatorRef allocator
= pthread_getspecific(__CFTSDKeyAllocator
);
214 CFAllocatorRef allocator
= (CFAllocatorRef
)__CFGetThreadSpecificData_inline()->_allocator
;
216 if (NULL
== allocator
) {
217 allocator
= kCFAllocatorSystemDefault
;
222 extern CFTypeID
__CFGenericTypeID(const void *cf
);
224 // This should only be used in CF types, not toll-free bridged objects!
225 // It should not be used with CFAllocator arguments!
226 // Use CFGetAllocator() in the general case, and this inline function in a few limited (but often called) situations.
227 CF_INLINE CFAllocatorRef
__CFGetAllocator(CFTypeRef cf
) { // !!! Use with CF types only, and NOT WITH CFAllocator!
228 CFAssert1(__kCFAllocatorTypeID_CONST
!= __CFGenericTypeID(cf
), __kCFLogAssertion
, "__CFGetAllocator(): CFAllocator argument", cf
);
229 if (__builtin_expect(__CFBitfieldGetValue(((const CFRuntimeBase
*)cf
)->_cfinfo
[CF_INFO_BITS
], 7, 7), 1)) {
230 return kCFAllocatorSystemDefault
;
232 return *(CFAllocatorRef
*)((char *)cf
- sizeof(CFAllocatorRef
));
235 // Don't define a __CFGetCurrentRunLoop(), because even internal clients should go through the real one
238 #if !defined(LLONG_MAX)
239 #if defined(_I64_MAX)
240 #define LLONG_MAX _I64_MAX
242 #warning Arbitrarily defining LLONG_MAX
243 #define LLONG_MAX (int64_t)9223372036854775807
245 #endif /* !defined(LLONG_MAX) */
247 #if !defined(LLONG_MIN)
248 #if defined(_I64_MIN)
249 #define LLONG_MIN _I64_MIN
251 #warning Arbitrarily defining LLONG_MIN
252 #define LLONG_MIN (-LLONG_MAX - (int64_t)1)
254 #endif /* !defined(LLONG_MIN) */
256 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
257 #define __CFMin(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
258 #define __CFMax(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
260 #define __CFMin(A,B) ((A) < (B) ? (A) : (B))
261 #define __CFMax(A,B) ((A) > (B) ? (A) : (B))
262 #endif /* __GNUC__ */
264 /* Secret CFAllocator hint bits */
265 #define __kCFAllocatorTempMemory 0x2
266 #define __kCFAllocatorNoPointers 0x10
267 #define __kCFAllocatorDoNotRecordEvent 0x100
268 #define __kCFAllocatorGCScannedMemory 0x200 /* GC: memory should be scanned. */
269 #define __kCFAllocatorGCObjectMemory 0x400 /* GC: memory needs to be finalized. */
271 CF_INLINE auto_memory_type_t
CF_GET_GC_MEMORY_TYPE(CFOptionFlags flags
) {
272 auto_memory_type_t type
= (flags
& __kCFAllocatorGCScannedMemory
? 0 : AUTO_UNSCANNED
) | (flags
& __kCFAllocatorGCObjectMemory
? AUTO_OBJECT
: 0);
276 CF_INLINE
void __CFAssignWithWriteBarrier(void **location
, void *value
) {
277 if (kCFUseCollectableAllocator
) {
278 objc_assign_strongCast((id
)value
, (id
*)location
);
284 // Zero-retain count CFAllocator functions, i.e. memory that will be collected, no dealloc necessary
285 CF_EXPORT
void *_CFAllocatorAllocateGC(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
286 CF_EXPORT
void *_CFAllocatorReallocateGC(CFAllocatorRef allocator
, void *ptr
, CFIndex newsize
, CFOptionFlags hint
);
287 CF_EXPORT
void _CFAllocatorDeallocateGC(CFAllocatorRef allocator
, void *ptr
);
289 CF_EXPORT CFAllocatorRef
_CFTemporaryMemoryAllocator(void);
291 extern SInt64
__CFTimeIntervalToTSR(CFTimeInterval ti
);
292 extern CFTimeInterval
__CFTSRToTimeInterval(SInt64 tsr
);
294 extern CFStringRef
__CFCopyFormattingDescription(CFTypeRef cf
, CFDictionaryRef formatOptions
);
296 /* result is long long or int, depending on doLonglong
298 extern Boolean
__CFStringScanInteger(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, Boolean doLonglong
, void *result
);
299 extern Boolean
__CFStringScanDouble(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, double *resultPtr
);
300 extern Boolean
__CFStringScanHex(CFStringInlineBuffer
*buf
, SInt32
*indexPtr
, unsigned *result
);
302 extern const char *__CFgetenv(const char *n
);
304 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
305 #define STACK_BUFFER_DECL(T, N, C) T N[C]
306 #elif DEPLOYMENT_TARGET_WINDOWS
307 #define STACK_BUFFER_DECL(T, N, C) T *N = (T *)_alloca((C) * sizeof(T))
309 #error Unknown or unspecified DEPLOYMENT_TARGET
313 #ifdef __CONSTANT_CFSTRINGS__
314 #define CONST_STRING_DECL(S, V) const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
315 #define PE_CONST_STRING_DECL(S, V) __private_extern__ const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
318 struct CF_CONST_STRING
{
324 CF_EXPORT
int __CFConstantStringClassReference
[];
326 /* CFNetwork also has a copy of the CONST_STRING_DECL macro (for use on platforms without constant string support in cc); please warn cfnetwork-core@group.apple.com of any necessary changes to this macro. -- REW, 1/28/2002 */
328 #if __CF_BIG_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
329 #define CONST_STRING_DECL(S, V) \
330 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
331 const CFStringRef S = (CFStringRef) & __ ## S ## __;
332 #define PE_CONST_STRING_DECL(S, V) \
333 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
334 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
335 #elif __CF_LITTLE_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
336 #define CONST_STRING_DECL(S, V) \
337 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
338 const CFStringRef S = (CFStringRef) & __ ## S ## __;
339 #define PE_CONST_STRING_DECL(S, V) \
340 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
341 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
342 #elif DEPLOYMENT_TARGET_WINDOWS
343 #define CONST_STRING_DECL(S, V) \
344 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
345 const CFStringRef S = (CFStringRef) & __ ## S ## __;
346 #define PE_CONST_STRING_DECL(S, V) \
347 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
348 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
350 #endif // __BIG_ENDIAN__
353 /* Buffer size for file pathname */
354 #if DEPLOYMENT_TARGET_WINDOWS
355 #define CFMaxPathSize ((CFIndex)262)
356 #define CFMaxPathLength ((CFIndex)260)
358 #define CFMaxPathSize ((CFIndex)1026)
359 #define CFMaxPathLength ((CFIndex)1024)
362 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
363 extern bool __CFOASafe
;
364 extern void __CFSetLastAllocationEventName(void *ptr
, const char *classname
);
367 #define __CFSetLastAllocationEventName(a, b) ((void) 0)
372 /* Comparators are passed the address of the values; this is somewhat different than CFComparatorFunction is used in public API usually. */
373 CF_EXPORT CFIndex
CFBSearch(const void *element
, CFIndex elementSize
, const void *list
, CFIndex count
, CFComparatorFunction comparator
, void *context
);
375 CF_EXPORT CFHashCode
CFHashBytes(UInt8
*bytes
, CFIndex length
);
377 CF_EXPORT CFStringEncoding
CFStringFileSystemEncoding(void);
379 __private_extern__ CFStringRef
__CFStringCreateImmutableFunnel3(CFAllocatorRef alloc
, const void *bytes
, CFIndex numBytes
, CFStringEncoding encoding
, Boolean possiblyExternalFormat
, Boolean tryToReduceUnicode
, Boolean hasLengthByte
, Boolean hasNullByte
, Boolean noCopy
, CFAllocatorRef contentsDeallocator
, UInt32 converterFlags
);
381 extern const void *__CFStringCollectionCopy(CFAllocatorRef allocator
, const void *ptr
);
382 extern const void *__CFTypeCollectionRetain(CFAllocatorRef allocator
, const void *ptr
);
383 extern void __CFTypeCollectionRelease(CFAllocatorRef allocator
, const void *ptr
);
385 extern CFTypeRef
CFMakeUncollectable(CFTypeRef cf
);
387 __private_extern__
void _CFRaiseMemoryException(CFStringRef reason
);
389 __private_extern__ Boolean __CFProphylacticAutofsAccess
;
392 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
394 typedef OSSpinLock CFSpinLock_t
;
396 #define CFSpinLockInit OS_SPINLOCK_INIT
397 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
399 #define __CFSpinLock(LP) ({ \
400 OSSpinLock *__lockp__ = (LP); \
401 OSSpinLock __lockv__ = *__lockp__; \
402 if (0 != __lockv__ && ~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
403 CFLog(3, CFSTR("In '%s', file %s, line %d, during lock, spin lock %p has value 0x%x, which is neither locked nor unlocked. The memory has been smashed."), __PRETTY_FUNCTION__, __FILE__, __LINE__, __lockp__, __lockv__); \
406 OSSpinLockLock(__lockp__); })
408 #define __CFSpinUnlock(LP) ({ \
409 OSSpinLock *__lockp__ = (LP); \
410 OSSpinLock __lockv__ = *__lockp__; \
411 if (~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
412 CFLog(3, CFSTR("In '%s', file %s, line %d, during unlock, spin lock %p has value 0x%x, which is not locked. The memory has been smashed or the lock is being unlocked when not locked."), __PRETTY_FUNCTION__, __FILE__, __LINE__, __lockp__, __lockv__); \
415 OSSpinLockUnlock(__lockp__); })
417 #elif DEPLOYMENT_TARGET_WINDOWS
419 typedef int32_t CFSpinLock_t
;
420 #define CFSpinLockInit 0
421 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
423 CF_INLINE
void __CFSpinLock(volatile CFSpinLock_t
*lock
) {
424 while (InterlockedCompareExchange((LONG
volatile *)lock
, ~0, 0) != 0) {
429 CF_INLINE
void __CFSpinUnlock(volatile CFSpinLock_t
*lock
) {
437 #warning CF spin locks not defined for this platform -- CF is not thread-safe
438 #define __CFSpinLock(A) do {} while (0)
439 #define __CFSpinUnlock(A) do {} while (0)
444 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
445 extern uint8_t __CF120293
;
446 extern uint8_t __CF120290
;
447 extern void __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__(void);
448 #define CHECK_FOR_FORK() do { __CF120290 = true; if (__CF120293) __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__(); } while (0)
449 #define CHECK_FOR_FORK_RET(...) do { CHECK_FOR_FORK(); if (__CF120293) return __VA_ARGS__; } while (0)
450 #define HAS_FORKED() (__CF120293)
453 #if !defined(CHECK_FOR_FORK)
454 #define CHECK_FOR_FORK() do { } while (0)
457 #if !defined(CHECK_FOR_FORK_RET)
458 #define CHECK_FOR_FORK_RET(...) do { } while (0)
461 #if !defined(HAS_FORKED)
462 #define HAS_FORKED() 0
465 #if DEPLOYMENT_TARGET_WINDOWS
467 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
468 #include <sys/errno.h>
471 #define thread_errno() errno
472 #define thread_set_errno(V) do {errno = (V);} while (0)
474 extern void *__CFStartSimpleThread(void *func
, void *arg
);
476 /* ==================== Simple file access ==================== */
477 /* For dealing with abstract types. MF:!!! These ought to be somewhere else and public. */
479 CF_EXPORT CFStringRef
_CFCopyExtensionForAbstractType(CFStringRef abstractType
);
481 /* ==================== Simple file access ==================== */
482 /* These functions all act on a c-strings which must be in the file system encoding. */
484 CF_EXPORT Boolean
_CFCreateDirectory(const char *path
);
485 #if DEPLOYMENT_TARGET_WINDOWS
486 CF_EXPORT Boolean
_CFCreateDirectoryWide(const wchar_t *path
);
488 CF_EXPORT Boolean
_CFRemoveDirectory(const char *path
);
489 CF_EXPORT Boolean
_CFDeleteFile(const char *path
);
491 CF_EXPORT Boolean
_CFReadBytesFromFile(CFAllocatorRef alloc
, CFURLRef url
, void **bytes
, CFIndex
*length
, CFIndex maxLength
);
492 /* resulting bytes are allocated from alloc which MUST be non-NULL. */
493 /* maxLength of zero means the whole file. Otherwise it sets a limit on the number of bytes read. */
495 CF_EXPORT Boolean
_CFWriteBytesToFile(CFURLRef url
, const void *bytes
, CFIndex length
);
496 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
497 CF_EXPORT Boolean
_CFWriteBytesToFileWithAtomicity(CFURLRef url
, const void *bytes
, unsigned int length
, SInt32 mode
, Boolean atomic
);
500 CF_EXPORT CFMutableArrayRef
_CFContentsOfDirectory(CFAllocatorRef alloc
, char *dirPath
, void *dirSpec
, CFURLRef dirURL
, CFStringRef matchingAbstractType
);
501 /* On Mac OS 8/9, one of dirSpec, dirPath and dirURL must be non-NULL */
502 /* On all other platforms, one of path and dirURL must be non-NULL */
503 /* If both are present, they are assumed to be in-synch; that is, they both refer to the same directory. */
504 /* alloc may be NULL */
505 /* return value is CFArray of CFURLs */
507 CF_EXPORT SInt32
_CFGetFileProperties(CFAllocatorRef alloc
, CFURLRef pathURL
, Boolean
*exists
, SInt32
*posixMode
, SInt64
*size
, CFDateRef
*modTime
, SInt32
*ownerID
, CFArrayRef
*dirContents
);
508 /* alloc may be NULL */
509 /* any of exists, posixMode, size, modTime, and dirContents can be NULL. Usually it is not a good idea to pass NULL for exists, since interpretting the other values sometimes requires that you know whether the file existed or not. Except for dirContents, it is pretty cheap to compute any of these things as loing as one of them must be computed. */
512 /* ==================== Simple path manipulation ==================== */
513 /* These functions all act on a UniChar buffers. */
515 CF_EXPORT Boolean
_CFIsAbsolutePath(UniChar
*unichars
, CFIndex length
);
516 CF_EXPORT Boolean
_CFStripTrailingPathSlashes(UniChar
*unichars
, CFIndex
*length
);
517 CF_EXPORT Boolean
_CFAppendPathComponent(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*component
, CFIndex componentLength
);
518 CF_EXPORT Boolean
_CFAppendPathExtension(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*extension
, CFIndex extensionLength
);
519 CF_EXPORT Boolean
_CFTransmutePathSlashes(UniChar
*unichars
, CFIndex
*length
, UniChar replSlash
);
520 CF_EXPORT CFIndex
_CFStartOfLastPathComponent(UniChar
*unichars
, CFIndex length
);
521 CF_EXPORT CFIndex
_CFLengthAfterDeletingLastPathComponent(UniChar
*unichars
, CFIndex length
);
522 CF_EXPORT CFIndex
_CFStartOfPathExtension(UniChar
*unichars
, CFIndex length
);
523 CF_EXPORT CFIndex
_CFLengthAfterDeletingPathExtension(UniChar
*unichars
, CFIndex length
);
525 #define __CFMaxRuntimeTypes 65535
527 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS_SYNC
529 #include <objc/runtime.h>
531 extern int32_t __CFRuntimeClassTableSize
;
533 extern uintptr_t *__CFRuntimeObjCClassTable
;
534 CF_INLINE
uintptr_t __CFISAForTypeID(CFTypeID typeID
) {
535 return (typeID
< __CFRuntimeClassTableSize
) ? __CFRuntimeObjCClassTable
[typeID
] : 0;
538 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
539 extern id
objc_msgSend(id
, SEL
, ...);
540 #elif DEPLOYMENT_TARGET_WINDOWS && defined(__cplusplus)
541 extern "C" __declspec(dllimport
) id
objc_msgSend(id
, SEL
, ...);
542 #elif DEPLOYMENT_TARGET_WINDOWS
543 extern __declspec(dllimport
) id
objc_msgSend(id
, SEL
, ...);
546 extern void * (*__CFSendObjCMsg
)(const void *, SEL
, ...);
548 CF_INLINE Boolean
CF_IS_OBJC(CFTypeID typeID
, const void *obj
) {
549 return (typeID
>= __CFRuntimeClassTableSize
) || (((CFRuntimeBase
*)obj
)->_cfisa
!= __CFISAForTypeID(typeID
) && ((CFRuntimeBase
*)obj
)->_cfisa
> (uintptr_t)0xFFF);
552 // Invoke an ObjC method that returns void.
553 // Assumes CF_IS_OBJC has already been checked.
554 #define CF_OBJC_VOIDCALL0(obj, sel) \
555 {void (*func)(const void *, SEL) = (void (*)(const void *, SEL))objc_msgSend; \
556 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
557 func((const void *)obj, s);}
558 #define CF_OBJC_VOIDCALL1(obj, sel, a1) \
559 {void (*func)(const void *, SEL, ...) = (void (*)(const void *, SEL, ...))objc_msgSend; \
560 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
561 func((const void *)obj, s, (a1));}
562 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2) \
563 {void (*func)(const void *, SEL, ...) = (void (*)(const void *, SEL, ...))objc_msgSend; \
564 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
565 func((const void *)obj, s, (a1), (a2));}
568 // Invoke an ObjC method, leaving the result in "retvar".
569 // Assumes CF_IS_OBJC has already been checked.
570 #define CF_OBJC_CALL0(rettype, retvar, obj, sel) \
571 {rettype (*func)(const void *, SEL) = (rettype (*)(const void *, SEL))objc_msgSend; \
572 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
573 retvar = func((const void *)obj, s);}
574 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1) \
575 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL, ...))objc_msgSend; \
576 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
577 retvar = func((const void *)obj, s, (a1));}
578 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2) \
579 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL, ...))objc_msgSend; \
580 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
581 retvar = func((const void *)obj, s, (a1), (a2));}
583 // Invoke an ObjC method, return the result
584 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel) \
585 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
586 {rettype (*func)(const void *, SEL) = (rettype (*)(const void *, SEL))objc_msgSend; \
587 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
588 return func((const void *)obj, s);}
589 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1) \
590 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
591 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL,...))objc_msgSend; \
592 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
593 return func((const void *)obj, s, (a1));}
594 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2) \
595 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
596 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL,...))objc_msgSend; \
597 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
598 return func((const void *)obj, s, (a1), (a2));}
599 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3) \
600 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
601 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL,...))objc_msgSend; \
602 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
603 return func((const void *)obj, s, (a1), (a2), (a3));}
604 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4) \
605 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
606 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL,...))objc_msgSend; \
607 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
608 return func((const void *)obj, s, (a1), (a2), (a3), (a4));}
609 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5) \
610 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
611 {rettype (*func)(const void *, SEL, ...) = (rettype (*)(const void *, SEL,...))objc_msgSend; \
612 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
613 return func((const void *)obj, s, (a1), (a2), (a3), (a4), (a5));}
617 /* See comments in CFBase.c
619 #if DEPLOYMENT_TARGET_MACOSX && defined(__ppc__)
620 extern void __CF_FAULT_CALLBACK(void **ptr
);
621 extern void *__CF_INVOKE_CALLBACK(void *, ...);
622 #define FAULT_CALLBACK(V) __CF_FAULT_CALLBACK(V)
623 #define INVOKE_CALLBACK1(P, A) (__CF_INVOKE_CALLBACK(P, A))
624 #define INVOKE_CALLBACK2(P, A, B) (__CF_INVOKE_CALLBACK(P, A, B))
625 #define INVOKE_CALLBACK3(P, A, B, C) (__CF_INVOKE_CALLBACK(P, A, B, C))
626 #define INVOKE_CALLBACK4(P, A, B, C, D) (__CF_INVOKE_CALLBACK(P, A, B, C, D))
627 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (__CF_INVOKE_CALLBACK(P, A, B, C, D, E))
628 #define UNFAULT_CALLBACK(V) do { V = (void *)((uintptr_t)V & ~0x3); } while (0)
630 #define FAULT_CALLBACK(V)
631 #define INVOKE_CALLBACK1(P, A) (P)(A)
632 #define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
633 #define INVOKE_CALLBACK3(P, A, B, C) (P)(A, B, C)
634 #define INVOKE_CALLBACK4(P, A, B, C, D) (P)(A, B, C, D)
635 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (P)(A, B, C, D, E)
636 #define UNFAULT_CALLBACK(V) do { } while (0)
639 /* For the support of functionality which needs CarbonCore or other frameworks */
640 // These macros define an upcall or weak "symbol-lookup" wrapper function.
641 // The parameters are:
642 // R : the return type of the function
643 // N : the name of the function (in the other library)
644 // P : the parenthesized parameter list of the function
645 // A : the parenthesized actual argument list to be passed
646 // opt: a fifth optional argument can be passed in which is the
647 // return value of the wrapper when the function cannot be
648 // found; should be of type R, & can be a function call
649 // The name of the resulting wrapper function is:
650 // __CFCarbonCore_N (where N is the second parameter)
651 // __CFNetwork_N (where N is the second parameter)
654 // DEFINE_WEAK_CARBONCORE_FUNC(void, DisposeHandle, (Handle h), (h))
657 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
659 extern void *__CFLookupCFNetworkFunction(const char *name
);
661 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...) \
662 static R __CFNetwork_ ## N P { \
663 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
664 if ((void *)(~(uintptr_t)0) == dyfunc) { \
665 dyfunc = __CFLookupCFNetworkFunction(#N); } \
666 if (dyfunc) { return dyfunc A ; } \
667 return __VA_ARGS__ ; \
670 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, FAILACTION, ...) \
671 static R __CFNetwork_ ## N P { \
672 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
673 if ((void *)(~(uintptr_t)0) == dyfunc) { \
674 dyfunc = __CFLookupCFNetworkFunction(#N); } \
675 if (dyfunc) { return dyfunc A ; } \
677 return __VA_ARGS__ ; \
682 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...)
683 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, ...)
688 #if !defined(DEFINE_WEAK_CARBONCORE_FUNC)
689 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...)
692 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
693 __private_extern__ CFComparisonResult
_CFCompareStringsWithLocale(CFStringInlineBuffer
*str1
, CFRange str1Range
, CFStringInlineBuffer
*str2
, CFRange str2Range
, CFOptionFlags options
, const void *compareLocale
);
697 __private_extern__ CFArrayRef
_CFBundleCopyUserLanguages(Boolean useBackstops
);
700 #if DEPLOYMENT_TARGET_WINDOWS
701 __private_extern__
const wchar_t *_CFDLLPath(void);
702 __private_extern__
void __CFStringCleanup(void);
703 __private_extern__
void __CFSocketCleanup(void);
704 __private_extern__
void __CFUniCharCleanup(void);
705 __private_extern__
void __CFStreamCleanup(void);
708 /* !!! Avoid #importing objc.h; e.g. converting this to a .m file */
709 struct __objcFastEnumerationStateEquivalent
{
711 unsigned long *itemsPtr
;
712 unsigned long *mutationsPtr
;
713 unsigned long extra
[5];
716 unsigned long _CFStorageFastEnumeration(CFStorageRef storage
, struct __objcFastEnumerationStateEquivalent
*state
, void *stackbuffer
, unsigned long count
);
720 #endif /* ! __COREFOUNDATION_CFINTERNAL__ */