2 * Copyright (c) 2009 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
78 #include <CoreFoundation/ForFoundationOnly.h>
80 CF_EXPORT
const char *_CFProcessName(void);
81 CF_EXPORT CFStringRef
_CFProcessNameString(void);
83 CF_EXPORT Boolean
_CFIsCFM(void);
85 CF_EXPORT Boolean
_CFGetCurrentDirectory(char *path
, int maxlen
);
87 CF_EXPORT CFStringRef
_CFGetUserName(void);
89 CF_EXPORT CFArrayRef
_CFGetWindowsBinaryDirectories(void);
91 CF_EXPORT CFStringRef
_CFStringCreateHostName(void);
93 CF_EXPORT
void _CFMachPortInstallNotifyPort(CFRunLoopRef rl
, CFStringRef mode
);
96 #define HALT do {asm __volatile__("trap"); kill(getpid(), 9); } while (0)
97 #elif defined(__i386__) || defined(__x86_64__)
99 #define HALT do {asm __volatile__("int3"); kill(getpid(), 9); } while (0)
100 #elif defined(_MSC_VER)
101 #define HALT do { DebugBreak(); abort(); } while (0)
103 #error Compiler not supported
107 #define HALT do {asm __volatile__("bkpt 0xCF"); kill(getpid(), 9); } while (0)
111 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
114 CFLog(prio, CFSTR(desc), a1, a2, a3, a4, a5); \
119 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
123 #define CFAssert(condition, priority, description) \
124 __CFAssert((condition), (priority), description, 0, 0, 0, 0, 0)
125 #define CFAssert1(condition, priority, description, a1) \
126 __CFAssert((condition), (priority), description, (a1), 0, 0, 0, 0)
127 #define CFAssert2(condition, priority, description, a1, a2) \
128 __CFAssert((condition), (priority), description, (a1), (a2), 0, 0, 0)
129 #define CFAssert3(condition, priority, description, a1, a2, a3) \
130 __CFAssert((condition), (priority), description, (a1), (a2), (a3), 0, 0)
131 #define CFAssert4(condition, priority, description, a1, a2, a3, a4) \
132 __CFAssert((condition), (priority), description, (a1), (a2), (a3), (a4), 0)
134 #define __kCFLogAssertion 3
137 extern void __CFGenericValidateType_(CFTypeRef cf
, CFTypeID type
, const char *func
);
138 #define __CFGenericValidateType(cf, type) __CFGenericValidateType_(cf, type, __PRETTY_FUNCTION__)
140 #define __CFGenericValidateType(cf, type) ((void)0)
143 #define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3)
144 #define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3)
146 /* Bit manipulation macros */
147 /* Bits are numbered from 31 on left to 0 on right */
148 /* 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. */
149 /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */
150 #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1))
151 #define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2))
152 #define __CFBitfieldSetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfieldMask(N1, N2)) | (((X) << (N2)) & __CFBitfieldMask(N1, N2)))
153 #define __CFBitfieldMaxValue(N1, N2) __CFBitfieldGetValue(0xFFFFFFFFUL, (N1), (N2))
155 #define __CFBitIsSet(V, N) (((V) & (1UL << (N))) != 0)
156 #define __CFBitSet(V, N) ((V) |= (1UL << (N)))
157 #define __CFBitClear(V, N) ((V) &= ~(1UL << (N)))
160 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
161 // The fixed range 50 - 59 of pthread_specific keys is reserved
162 // for CoreFoundation; see <System/pthread_machdep.h>.
163 // 60 - 69 are reserved for Foundation; Foundation uses 64 - 69
164 // and reserves 60-63 for CoreFoundation.
165 // Foundation knows about the value of __CFTSDKeyAutoreleaseData1
167 __CFTSDKeyUnused50
= 50,
168 __CFTSDKeyAllocator
= 51,
169 __CFTSDKeyExceptionData
= 52,
170 __CFTSDKeyRunLoopCntr
= 53,
171 __CFTSDKeyRunLoop
= 54,
172 __CFTSDKeyICUConverter
= 55,
173 __CFTSDKeyCollatorLocale
= 56,
174 __CFTSDKeyCollatorUCollator
= 57,
175 __CFTSDKeyIsInNSCache
= 58,
176 __CFTSDKeyIsInCFLog
= 59,
177 __CFTSDKeyIsInGCDMainQ
= 60,
178 __CFTSDKeyUnused61
= 61,
179 __CFTSDKeyAutoreleaseData1
= 62,
180 __CFTSDKeyAutoreleaseData2
= 63, // autorelease pool stuff must be higher than run loop constants
183 extern int pthread_key_init_np(int, void (*)(void *));
186 #if DEPLOYMENT_TARGET_WINDOWS
187 typedef struct ___CFThreadSpecificData
{
193 void *_icuThreadData
;
195 // If you add things to this struct, add cleanup to __CFFinalizeThreadData()
196 } __CFThreadSpecificData
;
198 extern __CFThreadSpecificData
*__CFGetThreadSpecificData(void);
199 __private_extern__
void __CFFinalizeThreadData(void *arg
);
200 extern DWORD __CFTSDKey
;
202 // implemented in windowsSyncHelper.c
203 __private_extern__ __CFThreadSpecificData
*__CFGetThreadSpecificData_inline(void);
207 #define __kCFAllocatorTypeID_CONST 2
209 CF_INLINE CFAllocatorRef
__CFGetDefaultAllocator(void) {
210 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
211 CFAllocatorRef allocator
= pthread_getspecific(__CFTSDKeyAllocator
);
213 CFAllocatorRef allocator
= (CFAllocatorRef
)__CFGetThreadSpecificData_inline()->_allocator
;
215 if (NULL
== allocator
) {
216 allocator
= kCFAllocatorSystemDefault
;
221 extern CFTypeID
__CFGenericTypeID(const void *cf
);
223 // This should only be used in CF types, not toll-free bridged objects!
224 // It should not be used with CFAllocator arguments!
225 // Use CFGetAllocator() in the general case, and this inline function in a few limited (but often called) situations.
226 CF_INLINE CFAllocatorRef
__CFGetAllocator(CFTypeRef cf
) { // !!! Use with CF types only, and NOT WITH CFAllocator!
227 CFAssert1(__kCFAllocatorTypeID_CONST
!= __CFGenericTypeID(cf
), __kCFLogAssertion
, "__CFGetAllocator(): CFAllocator argument", cf
);
228 if (__builtin_expect(__CFBitfieldGetValue(((const CFRuntimeBase
*)cf
)->_cfinfo
[CF_INFO_BITS
], 7, 7), 1)) {
229 return kCFAllocatorSystemDefault
;
231 return *(CFAllocatorRef
*)((char *)cf
- sizeof(CFAllocatorRef
));
234 // Don't define a __CFGetCurrentRunLoop(), because even internal clients should go through the real one
237 #if !defined(LLONG_MAX)
238 #if defined(_I64_MAX)
239 #define LLONG_MAX _I64_MAX
241 #warning Arbitrarily defining LLONG_MAX
242 #define LLONG_MAX (int64_t)9223372036854775807
244 #endif /* !defined(LLONG_MAX) */
246 #if !defined(LLONG_MIN)
247 #if defined(_I64_MIN)
248 #define LLONG_MIN _I64_MIN
250 #warning Arbitrarily defining LLONG_MIN
251 #define LLONG_MIN (-LLONG_MAX - (int64_t)1)
253 #endif /* !defined(LLONG_MIN) */
255 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
256 #define __CFMin(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
257 #define __CFMax(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
259 #define __CFMin(A,B) ((A) < (B) ? (A) : (B))
260 #define __CFMax(A,B) ((A) > (B) ? (A) : (B))
261 #endif /* __GNUC__ */
263 /* Secret CFAllocator hint bits */
264 #define __kCFAllocatorTempMemory 0x2
265 #define __kCFAllocatorNoPointers 0x10
266 #define __kCFAllocatorDoNotRecordEvent 0x100
267 #define __kCFAllocatorGCScannedMemory 0x200 /* GC: memory should be scanned. */
268 #define __kCFAllocatorGCObjectMemory 0x400 /* GC: memory needs to be finalized. */
270 CF_INLINE auto_memory_type_t
CF_GET_GC_MEMORY_TYPE(CFOptionFlags flags
) {
271 auto_memory_type_t type
= (flags
& __kCFAllocatorGCScannedMemory
? 0 : AUTO_UNSCANNED
) | (flags
& __kCFAllocatorGCObjectMemory
? AUTO_OBJECT
: 0);
275 CF_INLINE
void __CFAssignWithWriteBarrier(void **location
, void *value
) {
276 if (kCFUseCollectableAllocator
) {
277 objc_assign_strongCast((id
)value
, (id
*)location
);
283 // Zero-retain count CFAllocator functions, i.e. memory that will be collected, no dealloc necessary
284 CF_EXPORT
void *_CFAllocatorAllocateGC(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
285 CF_EXPORT
void *_CFAllocatorReallocateGC(CFAllocatorRef allocator
, void *ptr
, CFIndex newsize
, CFOptionFlags hint
);
286 CF_EXPORT
void _CFAllocatorDeallocateGC(CFAllocatorRef allocator
, void *ptr
);
288 CF_EXPORT CFAllocatorRef
_CFTemporaryMemoryAllocator(void);
290 extern SInt64
__CFTimeIntervalToTSR(CFTimeInterval ti
);
291 extern CFTimeInterval
__CFTSRToTimeInterval(SInt64 tsr
);
293 extern CFStringRef
__CFCopyFormattingDescription(CFTypeRef cf
, CFDictionaryRef formatOptions
);
295 /* result is long long or int, depending on doLonglong
297 extern Boolean
__CFStringScanInteger(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, Boolean doLonglong
, void *result
);
298 extern Boolean
__CFStringScanDouble(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, double *resultPtr
);
299 extern Boolean
__CFStringScanHex(CFStringInlineBuffer
*buf
, SInt32
*indexPtr
, unsigned *result
);
301 extern const char *__CFgetenv(const char *n
);
303 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
304 #define STACK_BUFFER_DECL(T, N, C) T N[C]
305 #elif DEPLOYMENT_TARGET_WINDOWS
306 #define STACK_BUFFER_DECL(T, N, C) T *N = (T *)_alloca((C) * sizeof(T))
308 #error Unknown or unspecified DEPLOYMENT_TARGET
312 #ifdef __CONSTANT_CFSTRINGS__
313 #define CONST_STRING_DECL(S, V) const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
314 #define PE_CONST_STRING_DECL(S, V) __private_extern__ const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
317 struct CF_CONST_STRING
{
323 CF_EXPORT
int __CFConstantStringClassReference
[];
325 /* 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 */
327 #if __CF_BIG_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
328 #define CONST_STRING_DECL(S, V) \
329 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
330 const CFStringRef S = (CFStringRef) & __ ## S ## __;
331 #define PE_CONST_STRING_DECL(S, V) \
332 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
333 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
334 #elif __CF_LITTLE_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
335 #define CONST_STRING_DECL(S, V) \
336 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
337 const CFStringRef S = (CFStringRef) & __ ## S ## __;
338 #define PE_CONST_STRING_DECL(S, V) \
339 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
340 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
341 #elif DEPLOYMENT_TARGET_WINDOWS
342 #define CONST_STRING_DECL(S, V) \
343 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
344 const CFStringRef S = (CFStringRef) & __ ## S ## __;
345 #define PE_CONST_STRING_DECL(S, V) \
346 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
347 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
349 #endif // __BIG_ENDIAN__
352 /* Buffer size for file pathname */
353 #if DEPLOYMENT_TARGET_WINDOWS
354 #define CFMaxPathSize ((CFIndex)262)
355 #define CFMaxPathLength ((CFIndex)260)
357 #define CFMaxPathSize ((CFIndex)1026)
358 #define CFMaxPathLength ((CFIndex)1024)
361 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
362 extern bool __CFOASafe
;
363 extern void __CFSetLastAllocationEventName(void *ptr
, const char *classname
);
366 #define __CFSetLastAllocationEventName(a, b) ((void) 0)
371 /* Comparators are passed the address of the values; this is somewhat different than CFComparatorFunction is used in public API usually. */
372 CF_EXPORT CFIndex
CFBSearch(const void *element
, CFIndex elementSize
, const void *list
, CFIndex count
, CFComparatorFunction comparator
, void *context
);
374 CF_EXPORT CFHashCode
CFHashBytes(UInt8
*bytes
, CFIndex length
);
376 CF_EXPORT CFStringEncoding
CFStringFileSystemEncoding(void);
378 __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
);
380 extern const void *__CFStringCollectionCopy(CFAllocatorRef allocator
, const void *ptr
);
381 extern const void *__CFTypeCollectionRetain(CFAllocatorRef allocator
, const void *ptr
);
382 extern void __CFTypeCollectionRelease(CFAllocatorRef allocator
, const void *ptr
);
384 extern CFTypeRef
CFMakeUncollectable(CFTypeRef cf
);
386 __private_extern__
void _CFRaiseMemoryException(CFStringRef reason
);
388 __private_extern__ Boolean __CFProphylacticAutofsAccess
;
391 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
393 typedef OSSpinLock CFSpinLock_t
;
395 #define CFSpinLockInit OS_SPINLOCK_INIT
396 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
398 #define __CFSpinLock(LP) ({ \
399 OSSpinLock *__lockp__ = (LP); \
400 OSSpinLock __lockv__ = *__lockp__; \
401 if (0 != __lockv__ && ~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
402 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__); \
405 OSSpinLockLock(__lockp__); })
407 #define __CFSpinUnlock(LP) ({ \
408 OSSpinLock *__lockp__ = (LP); \
409 OSSpinLock __lockv__ = *__lockp__; \
410 if (~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
411 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__); \
414 OSSpinLockUnlock(__lockp__); })
416 #elif DEPLOYMENT_TARGET_WINDOWS
418 typedef int32_t CFSpinLock_t
;
419 #define CFSpinLockInit 0
420 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
422 CF_INLINE
void __CFSpinLock(volatile CFSpinLock_t
*lock
) {
423 while (InterlockedCompareExchange((LONG
volatile *)lock
, ~0, 0) != 0) {
428 CF_INLINE
void __CFSpinUnlock(volatile CFSpinLock_t
*lock
) {
436 #warning CF spin locks not defined for this platform -- CF is not thread-safe
437 #define __CFSpinLock(A) do {} while (0)
438 #define __CFSpinUnlock(A) do {} while (0)
443 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
444 extern uint8_t __CF120293
;
445 extern uint8_t __CF120290
;
446 extern void __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__(void);
447 #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)
448 #define CHECK_FOR_FORK_RET(...) do { CHECK_FOR_FORK(); if (__CF120293) return __VA_ARGS__; } while (0)
449 #define HAS_FORKED() (__CF120293)
452 #if !defined(CHECK_FOR_FORK)
453 #define CHECK_FOR_FORK() do { } while (0)
456 #if !defined(CHECK_FOR_FORK_RET)
457 #define CHECK_FOR_FORK_RET(...) do { } while (0)
460 #if !defined(HAS_FORKED)
461 #define HAS_FORKED() 0
464 #if DEPLOYMENT_TARGET_WINDOWS
466 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
467 #include <sys/errno.h>
470 #define thread_errno() errno
471 #define thread_set_errno(V) do {errno = (V);} while (0)
473 extern void *__CFStartSimpleThread(void *func
, void *arg
);
475 /* ==================== Simple file access ==================== */
476 /* For dealing with abstract types. MF:!!! These ought to be somewhere else and public. */
478 CF_EXPORT CFStringRef
_CFCopyExtensionForAbstractType(CFStringRef abstractType
);
480 /* ==================== Simple file access ==================== */
481 /* These functions all act on a c-strings which must be in the file system encoding. */
483 CF_EXPORT Boolean
_CFCreateDirectory(const char *path
);
484 #if DEPLOYMENT_TARGET_WINDOWS
485 CF_EXPORT Boolean
_CFCreateDirectoryWide(const wchar_t *path
);
487 CF_EXPORT Boolean
_CFRemoveDirectory(const char *path
);
488 CF_EXPORT Boolean
_CFDeleteFile(const char *path
);
490 CF_EXPORT Boolean
_CFReadBytesFromFile(CFAllocatorRef alloc
, CFURLRef url
, void **bytes
, CFIndex
*length
, CFIndex maxLength
);
491 /* resulting bytes are allocated from alloc which MUST be non-NULL. */
492 /* maxLength of zero means the whole file. Otherwise it sets a limit on the number of bytes read. */
494 CF_EXPORT Boolean
_CFWriteBytesToFile(CFURLRef url
, const void *bytes
, CFIndex length
);
495 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
496 CF_EXPORT Boolean
_CFWriteBytesToFileWithAtomicity(CFURLRef url
, const void *bytes
, unsigned int length
, SInt32 mode
, Boolean atomic
);
499 CF_EXPORT CFMutableArrayRef
_CFContentsOfDirectory(CFAllocatorRef alloc
, char *dirPath
, void *dirSpec
, CFURLRef dirURL
, CFStringRef matchingAbstractType
);
500 /* On Mac OS 8/9, one of dirSpec, dirPath and dirURL must be non-NULL */
501 /* On all other platforms, one of path and dirURL must be non-NULL */
502 /* If both are present, they are assumed to be in-synch; that is, they both refer to the same directory. */
503 /* alloc may be NULL */
504 /* return value is CFArray of CFURLs */
506 CF_EXPORT SInt32
_CFGetFileProperties(CFAllocatorRef alloc
, CFURLRef pathURL
, Boolean
*exists
, SInt32
*posixMode
, SInt64
*size
, CFDateRef
*modTime
, SInt32
*ownerID
, CFArrayRef
*dirContents
);
507 /* alloc may be NULL */
508 /* 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. */
511 /* ==================== Simple path manipulation ==================== */
512 /* These functions all act on a UniChar buffers. */
514 CF_EXPORT Boolean
_CFIsAbsolutePath(UniChar
*unichars
, CFIndex length
);
515 CF_EXPORT Boolean
_CFStripTrailingPathSlashes(UniChar
*unichars
, CFIndex
*length
);
516 CF_EXPORT Boolean
_CFAppendPathComponent(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*component
, CFIndex componentLength
);
517 CF_EXPORT Boolean
_CFAppendPathExtension(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*extension
, CFIndex extensionLength
);
518 CF_EXPORT Boolean
_CFTransmutePathSlashes(UniChar
*unichars
, CFIndex
*length
, UniChar replSlash
);
519 CF_EXPORT CFIndex
_CFStartOfLastPathComponent(UniChar
*unichars
, CFIndex length
);
520 CF_EXPORT CFIndex
_CFLengthAfterDeletingLastPathComponent(UniChar
*unichars
, CFIndex length
);
521 CF_EXPORT CFIndex
_CFStartOfPathExtension(UniChar
*unichars
, CFIndex length
);
522 CF_EXPORT CFIndex
_CFLengthAfterDeletingPathExtension(UniChar
*unichars
, CFIndex length
);
524 #define __CFMaxRuntimeTypes 65535
526 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS_SYNC
528 #include <objc/runtime.h>
530 extern int32_t __CFRuntimeClassTableSize
;
532 extern uintptr_t *__CFRuntimeObjCClassTable
;
533 CF_INLINE
uintptr_t __CFISAForTypeID(CFTypeID typeID
) {
534 return (typeID
< __CFRuntimeClassTableSize
) ? __CFRuntimeObjCClassTable
[typeID
] : 0;
537 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
538 extern id
objc_msgSend(id
, SEL
, ...);
539 #elif DEPLOYMENT_TARGET_WINDOWS && defined(__cplusplus)
540 extern "C" __declspec(dllimport
) id
objc_msgSend(id
, SEL
, ...);
541 #elif DEPLOYMENT_TARGET_WINDOWS
542 extern __declspec(dllimport
) id
objc_msgSend(id
, SEL
, ...);
545 extern void * (*__CFSendObjCMsg
)(const void *, SEL
, ...);
547 CF_INLINE Boolean
CF_IS_OBJC(CFTypeID typeID
, const void *obj
) {
548 return (typeID
>= __CFRuntimeClassTableSize
) || (((CFRuntimeBase
*)obj
)->_cfisa
!= __CFISAForTypeID(typeID
) && ((CFRuntimeBase
*)obj
)->_cfisa
> (uintptr_t)0xFFF);
552 #define CF_IS_OBJC(typeID, obj) (false)
554 #define CF_OBJC_VOIDCALL0(obj, sel)
555 #define CF_OBJC_VOIDCALL1(obj, sel, a1)
556 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2)
558 #define CF_OBJC_CALL0(rettype, retvar, obj, sel)
559 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1)
560 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2)
562 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel)
563 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1)
564 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2)
565 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3)
566 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4)
567 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5)
571 /* See comments in CFBase.c
573 #if DEPLOYMENT_TARGET_MACOSX && defined(__ppc__)
574 extern void __CF_FAULT_CALLBACK(void **ptr
);
575 extern void *__CF_INVOKE_CALLBACK(void *, ...);
576 #define FAULT_CALLBACK(V) __CF_FAULT_CALLBACK(V)
577 #define INVOKE_CALLBACK1(P, A) (__CF_INVOKE_CALLBACK(P, A))
578 #define INVOKE_CALLBACK2(P, A, B) (__CF_INVOKE_CALLBACK(P, A, B))
579 #define INVOKE_CALLBACK3(P, A, B, C) (__CF_INVOKE_CALLBACK(P, A, B, C))
580 #define INVOKE_CALLBACK4(P, A, B, C, D) (__CF_INVOKE_CALLBACK(P, A, B, C, D))
581 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (__CF_INVOKE_CALLBACK(P, A, B, C, D, E))
582 #define UNFAULT_CALLBACK(V) do { V = (void *)((uintptr_t)V & ~0x3); } while (0)
584 #define FAULT_CALLBACK(V)
585 #define INVOKE_CALLBACK1(P, A) (P)(A)
586 #define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
587 #define INVOKE_CALLBACK3(P, A, B, C) (P)(A, B, C)
588 #define INVOKE_CALLBACK4(P, A, B, C, D) (P)(A, B, C, D)
589 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (P)(A, B, C, D, E)
590 #define UNFAULT_CALLBACK(V) do { } while (0)
593 /* For the support of functionality which needs CarbonCore or other frameworks */
594 // These macros define an upcall or weak "symbol-lookup" wrapper function.
595 // The parameters are:
596 // R : the return type of the function
597 // N : the name of the function (in the other library)
598 // P : the parenthesized parameter list of the function
599 // A : the parenthesized actual argument list to be passed
600 // opt: a fifth optional argument can be passed in which is the
601 // return value of the wrapper when the function cannot be
602 // found; should be of type R, & can be a function call
603 // The name of the resulting wrapper function is:
604 // __CFCarbonCore_N (where N is the second parameter)
605 // __CFNetwork_N (where N is the second parameter)
608 // DEFINE_WEAK_CARBONCORE_FUNC(void, DisposeHandle, (Handle h), (h))
611 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
613 extern void *__CFLookupCFNetworkFunction(const char *name
);
615 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...) \
616 static R __CFNetwork_ ## N P { \
617 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
618 if ((void *)(~(uintptr_t)0) == dyfunc) { \
619 dyfunc = __CFLookupCFNetworkFunction(#N); } \
620 if (dyfunc) { return dyfunc A ; } \
621 return __VA_ARGS__ ; \
624 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, FAILACTION, ...) \
625 static R __CFNetwork_ ## N P { \
626 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
627 if ((void *)(~(uintptr_t)0) == dyfunc) { \
628 dyfunc = __CFLookupCFNetworkFunction(#N); } \
629 if (dyfunc) { return dyfunc A ; } \
631 return __VA_ARGS__ ; \
636 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...)
637 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, ...)
642 #if !defined(DEFINE_WEAK_CARBONCORE_FUNC)
643 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...)
646 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
647 __private_extern__ CFComparisonResult
_CFCompareStringsWithLocale(CFStringInlineBuffer
*str1
, CFRange str1Range
, CFStringInlineBuffer
*str2
, CFRange str2Range
, CFOptionFlags options
, const void *compareLocale
);
651 __private_extern__ CFArrayRef
_CFBundleCopyUserLanguages(Boolean useBackstops
);
654 #if DEPLOYMENT_TARGET_WINDOWS
655 __private_extern__
const wchar_t *_CFDLLPath(void);
656 __private_extern__
void __CFStringCleanup(void);
657 __private_extern__
void __CFSocketCleanup(void);
658 __private_extern__
void __CFUniCharCleanup(void);
659 __private_extern__
void __CFStreamCleanup(void);
662 /* !!! Avoid #importing objc.h; e.g. converting this to a .m file */
663 struct __objcFastEnumerationStateEquivalent
{
665 unsigned long *itemsPtr
;
666 unsigned long *mutationsPtr
;
667 unsigned long extra
[5];
670 unsigned long _CFStorageFastEnumeration(CFStorageRef storage
, struct __objcFastEnumerationStateEquivalent
*state
, void *stackbuffer
, unsigned long count
);
674 #endif /* ! __COREFOUNDATION_CFINTERNAL__ */