]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/CommonServices.h
mDNSResponder-1096.100.3.tar.gz
[apple/mdnsresponder.git] / mDNSShared / CommonServices.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 //---------------------------------------------------------------------------------------------------------------------------
19 /*! @header CommonServices
20
21 Common Services for Mac OS X, Linux, Palm, Windows, and Windows CE.
22 */
23
24 #ifndef __COMMON_SERVICES__
25 #define __COMMON_SERVICES__
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #if 0
32 #pragma mark == Target ==
33 #endif
34
35 //===========================================================================================================================
36 // Target
37 //===========================================================================================================================
38
39 // Macintosh
40
41 #if ( !defined( TARGET_OS_MAC ) )
42 #if ( ( macintosh || __MACH__ ) && !KERNEL )
43 // ConditionalMacros.h in CoreServices will define this TARGET_* flag.
44 #else
45 #define TARGET_OS_MAC 0
46 #endif
47 #endif
48
49 #if ( !defined( TARGET_API_MAC_OSX_KERNEL ) )
50 #if ( __MACH__ && KERNEL )
51 #define TARGET_API_MAC_OSX_KERNEL 1
52 #else
53 #define TARGET_API_MAC_OSX_KERNEL 0
54 #endif
55 #endif
56
57 // FreeBSD
58
59 #if ( !defined( TARGET_OS_FREEBSD ) )
60 #if ( defined( __FreeBSD__ ) )
61 #define TARGET_OS_FREEBSD 1
62 #else
63 #define TARGET_OS_FREEBSD 0
64 #endif
65 #endif
66
67 // Linux
68
69 #if ( !defined( TARGET_OS_LINUX ) )
70 #if ( defined( __linux__ ) )
71 #define TARGET_OS_LINUX 1
72 #else
73 #define TARGET_OS_LINUX 0
74 #endif
75 #endif
76
77 // Solaris
78
79 #if ( !defined( TARGET_OS_SOLARIS ) )
80 #if ( defined(solaris) || (defined(__SVR4) && defined(sun)) )
81 #define TARGET_OS_SOLARIS 1
82 #else
83 #define TARGET_OS_SOLARIS 0
84 #endif
85 #endif
86
87 // Palm
88
89 #if ( !defined( TARGET_OS_PALM ) )
90 #if ( defined( __PALMOS_TRAPS__ ) || defined( __PALMOS_ARMLET__ ) )
91 #define TARGET_OS_PALM 1
92 #else
93 #define TARGET_OS_PALM 0
94 #endif
95 #endif
96
97 // Windows
98
99 #if ( !defined( TARGET_OS_WIN32 ) )
100 #if ( macintosh || __MACH__ )
101 // ConditionalMacros.h in CoreServices will define this TARGET_* flag.
102 #else
103 #if ( defined( _WIN32 ) )
104 #define TARGET_OS_WIN32 1
105 #else
106 #define TARGET_OS_WIN32 0
107 #endif
108 #endif
109 #endif
110
111 // Windows CE
112
113 #if ( !defined( TARGET_OS_WINDOWS_CE ) )
114 #if ( defined( _WIN32_WCE ) )
115 #define TARGET_OS_WINDOWS_CE 1
116 #else
117 #define TARGET_OS_WINDOWS_CE 0
118 #endif
119 #endif
120
121 #if 0
122 #pragma mark == Includes ==
123 #endif
124
125 //===========================================================================================================================
126 // Includes
127 //===========================================================================================================================
128
129 #if ( !KERNEL )
130 #if defined(WIN32) && !defined(_WSPIAPI_COUNTOF)
131 #define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
132 #endif
133 #include <stddef.h>
134 #endif
135
136 #if ( ( macintosh || __MACH__ ) && !KERNEL )
137
138 #if ( defined( __MWERKS__ ) )
139 #if ( __option( c9x ) )
140 #include <stdbool.h>
141 #endif
142 #else
143 #include <stdbool.h>
144 #endif
145
146 #include <stdint.h>
147
148 #if ( __MACH__ )
149
150 // Mac OS X
151
152 #include <sys/types.h>
153 #include <netinet/in.h>
154 #include <arpa/inet.h>
155 #include <fcntl.h>
156 #include <pthread.h>
157 #include <sys/ioctl.h>
158 #include <sys/socket.h>
159 #include <unistd.h>
160
161 #else
162
163 // Classic Mac OS
164
165 #include <ConditionalMacros.h>
166 #include <MacTypes.h>
167
168 #endif
169
170 #elif ( KERNEL )
171
172 // Mac OS X Kernel
173
174 #include <stdint.h>
175
176 #include <libkern/OSTypes.h>
177 #include <sys/types.h>
178
179 #elif ( TARGET_OS_FREEBSD )
180
181 // FreeBSD
182 #include <stdint.h>
183 #include <pthread.h>
184 #include <netinet/in.h>
185 #include <arpa/inet.h>
186 #include <sys/socket.h>
187
188 #elif ( TARGET_OS_LINUX )
189
190 // Linux
191
192 #include <stdint.h>
193 #include <arpa/inet.h>
194
195 #elif ( TARGET_OS_SOLARIS )
196
197 // Solaris
198
199 #include <stdint.h>
200
201 #include <arpa/inet.h>
202 #include <arpa/nameser.h>
203
204 #if ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) )
205 #define TARGET_RT_LITTLE_ENDIAN 1
206 #endif
207 #if ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) )
208 #define TARGET_RT_BIG_ENDIAN 1
209 #endif
210
211 #elif ( TARGET_OS_PALM )
212
213 // Palm (no special includes yet).
214
215 #elif ( TARGET_OS_WIN32 )
216
217 // Windows
218
219 #if ( !defined( WIN32_WINDOWS ) )
220 #define WIN32_WINDOWS 0x0401
221 #endif
222
223 #if ( !defined( _WIN32_WINDOWS ) )
224 #define _WIN32_WINDOWS 0x0401
225 #endif
226
227 #if ( !defined( WIN32_LEAN_AND_MEAN ) )
228 #define WIN32_LEAN_AND_MEAN // Needed to avoid redefinitions by Windows interfaces.
229 #endif
230
231 #if ( defined( __MWERKS__ ) )
232
233 #if ( __option( c9x ) )
234 #include <stdbool.h>
235 #endif
236
237 #include <stdint.h>
238
239 #elif ( defined( _MSC_VER ) )
240
241 #pragma warning( disable:4127 ) // Disable "conditional expression is constant" warning for debug macros.
242 #pragma warning( disable:4706 ) // Disable "assignment within conditional expression" for Microsoft headers.
243
244 #endif
245
246 #include <windows.h>
247 #include <winsock2.h>
248 #include <Ws2tcpip.h>
249
250 #if ( defined( _MSC_VER ) )
251 #pragma warning( default:4706 )
252 #endif
253
254 #else
255 #error unknown OS - update this file to support your OS
256 #endif
257
258 #if ( !defined( TARGET_BUILD_MAIN ) )
259 #define TARGET_BUILD_MAIN 1
260 #endif
261
262 #if 0
263 #pragma mark == CPU ==
264 #endif
265
266 //===========================================================================================================================
267 // CPU
268 //===========================================================================================================================
269
270 // PowerPC
271
272 #if ( !defined( TARGET_CPU_PPC ) )
273 #if ( defined( __ppc__ ) || defined( __PPC__ ) || defined( powerpc ) || defined( ppc ) || defined( _M_MPPC ) )
274 #define TARGET_CPU_PPC 1
275 #else
276 #define TARGET_CPU_PPC 0
277 #endif
278 #endif
279
280 // x86
281
282 #if ( !defined( TARGET_CPU_X86 ) )
283 #if ( __INTEL__ || defined( __i386__ ) || defined( i386 ) || defined( intel ) || defined( _M_IX86 ) )
284 #define TARGET_CPU_X86 1
285 #else
286 #define TARGET_CPU_X86 0
287 #endif
288 #endif
289
290 // MIPS
291
292 #if ( !defined( TARGET_CPU_MIPS ) )
293 #if ( __MIPS__ || defined( MIPS32 ) || defined( R3000 ) || defined( R4000 ) || defined( R4650 ) || defined( _M_MRX000 ) )
294 #define TARGET_CPU_MIPS 1
295 #else
296 #define TARGET_CPU_MIPS 0
297 #endif
298 #endif
299
300 #if ( !defined( TARGET_CPU_PPC ) && !defined( TARGET_CPU_X86 ) && !defined( TARGET_CPU_MIPS ) )
301 #error unknown CPU - update this file to support your CPU
302 #endif
303
304 #if 0
305 #pragma mark == Byte Order ==
306 #endif
307
308 //===========================================================================================================================
309 // Byte Order
310 //===========================================================================================================================
311
312 // TARGET_RT_LITTLE_ENDIAN
313
314 #if ( !defined( TARGET_RT_LITTLE_ENDIAN ) )
315 #if ( MIPSEL || IL_LITTLE_ENDIAN || defined( __LITTLE_ENDIAN__ ) || \
316 ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) ) || \
317 ( defined( _BYTE_ORDER ) && defined( _LITTLE_ENDIAN ) && ( _BYTE_ORDER == _LITTLE_ENDIAN ) ) || \
318 ( defined( __BYTE_ORDER ) && defined( __LITTLE_ENDIAN ) && ( __BYTE_ORDER == __LITTLE_ENDIAN ) ) || \
319 TARGET_CPU_X86 || ( defined( TARGET_RT_BIG_ENDIAN ) && !TARGET_RT_BIG_ENDIAN ) )
320 #define TARGET_RT_LITTLE_ENDIAN 1
321 #else
322 #define TARGET_RT_LITTLE_ENDIAN 0
323 #endif
324 #endif
325
326 // TARGET_RT_BIG_ENDIAN
327
328 #if ( !defined( TARGET_RT_BIG_ENDIAN ) )
329 #if ( MIPSEB || IL_BIG_ENDIAN || defined( __BIG_ENDIAN__ ) || \
330 ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) ) || \
331 ( defined( _BYTE_ORDER ) && defined( _BIG_ENDIAN ) && ( _BYTE_ORDER == _BIG_ENDIAN ) ) || \
332 ( defined( __BYTE_ORDER ) && defined( __BIG_ENDIAN ) && ( __BYTE_ORDER == __BIG_ENDIAN ) ) || \
333 ( defined( TARGET_RT_LITTLE_ENDIAN ) && !TARGET_RT_LITTLE_ENDIAN ) )
334 #define TARGET_RT_BIG_ENDIAN 1
335 #else
336 #define TARGET_RT_BIG_ENDIAN 0
337 #endif
338 #endif
339
340 #if ( defined( TARGET_RT_LITTLE_ENDIAN ) && !defined( TARGET_RT_BIG_ENDIAN ) )
341 #if ( TARGET_RT_LITTLE_ENDIAN )
342 #define TARGET_RT_BIG_ENDIAN 0
343 #else
344 #define TARGET_RT_BIG_ENDIAN 1
345 #endif
346 #endif
347
348 #if ( defined( TARGET_RT_BIG_ENDIAN ) && !defined( TARGET_RT_LITTLE_ENDIAN ) )
349 #if ( TARGET_RT_BIG_ENDIAN )
350 #define TARGET_RT_LITTLE_ENDIAN 0
351 #else
352 #define TARGET_RT_LITTLE_ENDIAN 1
353 #endif
354 #endif
355
356 #if ( !defined( TARGET_RT_LITTLE_ENDIAN ) || !defined( TARGET_RT_BIG_ENDIAN ) )
357 #error unknown byte order - update this file to support your byte order
358 #endif
359
360 // TARGET_RT_BYTE_ORDER
361
362 #if ( !defined( TARGET_RT_BYTE_ORDER_BIG_ENDIAN ) )
363 #define TARGET_RT_BYTE_ORDER_BIG_ENDIAN 1234
364 #endif
365
366 #if ( !defined( TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN ) )
367 #define TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN 4321
368 #endif
369
370 #if ( !defined( TARGET_RT_BYTE_ORDER ) )
371 #if ( TARGET_RT_LITTLE_ENDIAN )
372 #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN
373 #else
374 #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_BIG_ENDIAN
375 #endif
376 #endif
377
378 #if 0
379 #pragma mark == Constants ==
380 #endif
381
382 //===========================================================================================================================
383 // Constants
384 //===========================================================================================================================
385
386 #if ( !TARGET_OS_MAC )
387 #define CR '\r'
388 #endif
389
390 #define LF '\n'
391 #define CRSTR "\r"
392 #define LFSTR "\n"
393 #define CRLF "\r\n"
394 #define CRCR "\r\r"
395
396 #if 0
397 #pragma mark == Compatibility ==
398 #endif
399
400 //===========================================================================================================================
401 // Compatibility
402 //===========================================================================================================================
403
404 // Macros to allow the same code to work on Windows and other sockets API-compatible platforms.
405
406 #if ( TARGET_OS_WIN32 )
407 #define close_compat( X ) closesocket( X )
408 #define errno_compat() (int) GetLastError()
409 #define set_errno_compat( X ) SetLastError( X )
410 #define EWOULDBLOCK_compat WSAEWOULDBLOCK
411 #define ETIMEDOUT_compat WSAETIMEDOUT
412 #define ENOTCONN_compat WSAENOTCONN
413 #define IsValidSocket( X ) ( ( X ) != INVALID_SOCKET )
414 #define kInvalidSocketRef INVALID_SOCKET
415 typedef SOCKET SocketRef;
416 #else
417 #define close_compat( X ) close( X )
418 #define errno_compat() errno
419 #define set_errno_compat( X ) do { errno = ( X ); } while( 0 )
420 #define EWOULDBLOCK_compat EWOULDBLOCK
421 #define ETIMEDOUT_compat ETIMEDOUT
422 #define ENOTCONN_compat ENOTCONN
423 #define IsValidSocket( X ) ( ( X ) >= 0 )
424 #define kInvalidSocketRef -1
425 typedef int SocketRef;
426 #endif
427
428 // socklen_t is not defined on the following platforms so emulate it if not defined:
429 //
430 // - Pre-Panther Mac OS X. Panther defines SO_NOADDRERR so trigger off that.
431 // - Windows SDK prior to 2003. 2003+ SDK's define EAI_AGAIN so trigger off that.
432
433 #if ( ( TARGET_OS_MAC && !defined( SO_NOADDRERR ) ) || ( TARGET_OS_WIN32 && !defined( EAI_AGAIN ) ) )
434 typedef int socklen_t;
435 #endif
436
437 // ssize_t is not defined on the following platforms so emulate it if not defined:
438 //
439 // - Mac OS X when not building with BSD headers
440 // - Windows
441
442 #if ( !defined(_SSIZE_T) && ( TARGET_OS_WIN32 || !defined( _BSD_SSIZE_T_DEFINED_ ) ) && !TARGET_OS_FREEBSD && !TARGET_OS_LINUX && !TARGET_OS_MAC)
443 typedef int ssize_t;
444 #endif
445
446 // sockaddr_storage is not supported on non-IPv6 machines so alias it to an IPv4-compatible structure.
447
448 #if ( !defined( AF_INET6 ) )
449 #define sockaddr_storage sockaddr_in
450 #define ss_family sin_family
451 #endif
452
453 //---------------------------------------------------------------------------------------------------------------------------
454 /*! @defined SOCKADDR_IS_IP_LOOPBACK
455
456 @abstract Determines if a sockaddr is an IPv4 or IPv6 loopback address (if IPv6 is supported).
457 */
458
459 #if ( defined( AF_INET6 ) )
460 #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
461 ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
462 ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
463 : ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET6 ) \
464 ? IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) \
465 : 0
466 #else
467 #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
468 ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
469 ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
470 : 0
471 #endif
472
473 //---------------------------------------------------------------------------------------------------------------------------
474 /*! @defined SOCKADDR_IS_IP_LINK_LOCAL
475
476 @abstract Determines if a sockaddr is an IPv4 or IPv6 link-local address (if IPv6 is supported).
477 */
478
479 #if ( defined( AF_INET6 ) )
480 #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
481 ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
482 ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
483 ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
484 : IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) )
485 #else
486 #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
487 ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
488 ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
489 ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
490 : 0 )
491 #endif
492
493 // _beginthreadex and _endthreadex are not supported on Windows CE 2.1 or later (the C runtime issues with leaking
494 // resources have apparently been resolved and they seem to have just ripped out support for the API) so map it to
495 // CreateThread on Windows CE.
496
497 #if ( TARGET_OS_WINDOWS_CE )
498 #define _beginthreadex_compat( SECURITY_PTR, STACK_SIZE, START_ADDRESS, ARG_LIST, FLAGS, THREAD_ID_PTR ) \
499 (uintptr_t) CreateThread( SECURITY_PTR, STACK_SIZE, (LPTHREAD_START_ROUTINE) START_ADDRESS, ARG_LIST, FLAGS, \
500 (LPDWORD) THREAD_ID_PTR )
501
502 #define _endthreadex_compat( RESULT ) ExitThread( (DWORD) RESULT )
503 #elif ( TARGET_OS_WIN32 )
504 #define _beginthreadex_compat _beginthreadex
505 #define _endthreadex_compat _endthreadex
506 #endif
507
508 // The C99 "inline" keyword is not supported by Microsoft compilers, but they do support __inline so map it when needed.
509
510 #if ( defined( _MSC_VER ) )
511 #define inline_compat __inline
512 #else
513 #define inline_compat inline
514 #endif
515
516 // Calling conventions
517
518 #if ( !defined( CALLBACK_COMPAT ) )
519 #if ( TARGET_OS_WIN32 || TARGET_OS_WINDOWS_CE )
520 #define CALLBACK_COMPAT CALLBACK
521 #else
522 #define CALLBACK_COMPAT
523 #endif
524 #endif
525
526 #if 0
527 #pragma mark == Macros ==
528 #endif
529
530 //---------------------------------------------------------------------------------------------------------------------------
531 /*! @defined kSizeCString
532
533 @abstract A meta-value to pass to supported routines to indicate the size should be calculated with strlen.
534 */
535
536 #define kSizeCString ( (size_t) -1 )
537
538 //---------------------------------------------------------------------------------------------------------------------------
539 /*! @defined sizeof_array
540
541 @abstract Determines the number of elements in an array.
542 */
543
544 #define sizeof_array( X ) ( sizeof( X ) / sizeof( X[ 0 ] ) )
545
546 //---------------------------------------------------------------------------------------------------------------------------
547 /*! @defined sizeof_element
548
549 @abstract Determines the size of an array element.
550 */
551
552 #define sizeof_element( X ) sizeof( X[ 0 ] )
553
554 //---------------------------------------------------------------------------------------------------------------------------
555 /*! @defined sizeof_string
556
557 @abstract Determines the size of a constant C string, excluding the null terminator.
558 */
559
560 #define sizeof_string( X ) ( sizeof( ( X ) ) - 1 )
561
562 //---------------------------------------------------------------------------------------------------------------------------
563 /*! @defined sizeof_field
564
565 @abstract Determines the size of a field of a type.
566 */
567
568 #define sizeof_field( TYPE, FIELD ) sizeof( ( ( (TYPE *) 0 )->FIELD ) )
569
570 //---------------------------------------------------------------------------------------------------------------------------
571 /*! @function RoundUp
572
573 @abstract Rounds X up to a multiple of Y.
574 */
575
576 #define RoundUp( X, Y ) ( ( X ) + ( ( Y ) -( ( X ) % ( Y ) ) ) )
577
578 //---------------------------------------------------------------------------------------------------------------------------
579 /*! @function IsAligned
580
581 @abstract Returns non-zero if X is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
582 */
583
584 #define IsAligned( X, Y ) ( ( ( X ) &( ( Y ) -1 ) ) == 0 )
585
586 //---------------------------------------------------------------------------------------------------------------------------
587 /*! @function IsFieldAligned
588
589 @abstract Returns non-zero if FIELD of type TYPE is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
590 */
591
592 #define IsFieldAligned( X, TYPE, FIELD, Y ) IsAligned( ( (uintptr_t)( X ) ) + offsetof( TYPE, FIELD ), ( Y ) )
593
594 //---------------------------------------------------------------------------------------------------------------------------
595 /*! @function AlignDown
596
597 @abstract Aligns X down to a Y byte boundary. Y must be a power of 2.
598 */
599
600 #define AlignDown( X, Y ) ( ( X ) &~( ( Y ) -1 ) )
601
602 //---------------------------------------------------------------------------------------------------------------------------
603 /*! @function AlignUp
604
605 @abstract Aligns X up to a Y byte boundary. Y must be a power of 2.
606 */
607
608 #define AlignUp( X, Y ) ( ( ( X ) + ( ( Y ) -1 ) ) & ~( ( Y ) -1 ) )
609
610 //---------------------------------------------------------------------------------------------------------------------------
611 /*! @function Min
612
613 @abstract Returns the lesser of X and Y.
614 */
615
616 #if ( !defined( Min ) )
617 #define Min( X, Y ) ( ( ( X ) < ( Y ) ) ? ( X ) : ( Y ) )
618 #endif
619
620 //---------------------------------------------------------------------------------------------------------------------------
621 /*! @function Max
622
623 @abstract Returns the greater of X and Y.
624 */
625
626 #if ( !defined( Max ) )
627 #define Max( X, Y ) ( ( ( X ) > ( Y ) ) ? ( X ) : ( Y ) )
628 #endif
629
630 //---------------------------------------------------------------------------------------------------------------------------
631 /*! @function InsertBits
632
633 @abstract Inserts BITS (both 0 and 1 bits) into X, controlled by MASK and SHIFT, and returns the result.
634
635 @discussion
636
637 MASK is the bitmask of the bits in the final position.
638 SHIFT is the number of bits to shift left for 1 to reach the first bit position of MASK.
639
640 For example, if you wanted to insert 0x3 into the leftmost 4 bits of a 32-bit value:
641
642 InsertBits( 0, 0x3, 0xF0000000U, 28 ) == 0x30000000
643 */
644
645 #define InsertBits( X, BITS, MASK, SHIFT ) ( ( ( X ) &~( MASK ) ) | ( ( ( BITS ) << ( SHIFT ) ) & ( MASK ) ) )
646
647 //---------------------------------------------------------------------------------------------------------------------------
648 /*! @function ExtractBits
649
650 @abstract Extracts bits from X, controlled by MASK and SHIFT, and returns the result.
651
652 @discussion
653
654 MASK is the bitmask of the bits in the final position.
655 SHIFT is the number of bits to shift right to right justify MASK.
656
657 For example, if you had a 32-bit value (e.g. 0x30000000) wanted the left-most 4 bits (e.g. 3 in this example):
658
659 ExtractBits( 0x30000000U, 0xF0000000U, 28 ) == 0x3
660 */
661
662 #define ExtractBits( X, MASK, SHIFT ) ( ( ( X ) >> ( SHIFT ) ) & ( ( MASK ) >> ( SHIFT ) ) )
663
664 //---------------------------------------------------------------------------------------------------------------------------
665 /*! @function Stringify
666
667 @abstract Stringify's an expression.
668
669 @discussion
670
671 Stringify macros to process raw text passed via -D options to C string constants. The double-wrapping is necessary
672 because the C preprocessor doesn't perform its normal argument expansion pre-scan with stringified macros so the
673 -D macro needs to be expanded once via the wrapper macro then stringified so the raw text is stringified. Otherwise,
674 the replacement value would be used instead of the symbolic name (only for preprocessor symbols like #defines).
675
676 For example:
677
678 #define kMyConstant 1
679
680 printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
681 printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "1"
682
683 Non-preprocessor symbols do not have this issue. For example:
684
685 enum
686 {
687 kMyConstant = 1
688 };
689
690 printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
691 printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "kMyConstant"
692
693 See <http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html> for more info on C preprocessor pre-scanning.
694 */
695
696 #define Stringify( X ) # X
697 #define StringifyExpansion( X ) Stringify( X )
698
699 #if 0
700 #pragma mark == Types ==
701 #endif
702
703 //===========================================================================================================================
704 // Standard Types
705 //===========================================================================================================================
706
707 #if ( !defined( INT8_MIN ) )
708
709 #define INT8_MIN SCHAR_MIN
710
711 #if ( defined( _MSC_VER ) )
712
713 // C99 stdint.h not supported in VC++/VS.NET yet.
714
715 typedef INT8 int8_t;
716 typedef UINT8 uint8_t;
717 typedef INT16 int16_t;
718 typedef UINT16 uint16_t;
719 typedef INT32 int32_t;
720 typedef UINT32 uint32_t;
721 typedef __int64 int64_t;
722 typedef unsigned __int64 uint64_t;
723 #endif
724
725 typedef int8_t int_least8_t;
726 typedef int16_t int_least16_t;
727 typedef int32_t int_least32_t;
728 typedef int64_t int_least64_t;
729
730 typedef uint8_t uint_least8_t;
731 typedef uint16_t uint_least16_t;
732 typedef uint32_t uint_least32_t;
733 typedef uint64_t uint_least64_t;
734
735 typedef int8_t int_fast8_t;
736 typedef int16_t int_fast16_t;
737 typedef int32_t int_fast32_t;
738 typedef int64_t int_fast64_t;
739
740 typedef uint8_t uint_fast8_t;
741 typedef uint16_t uint_fast16_t;
742 typedef uint32_t uint_fast32_t;
743 typedef uint64_t uint_fast64_t;
744
745 #if ( !defined( _MSC_VER ) || TARGET_OS_WINDOWS_CE )
746 typedef long int intptr_t;
747 typedef unsigned long int uintptr_t;
748 #endif
749
750 #endif
751
752 // Macros for minimum-width integer constants
753
754 #if ( !defined( INT8_C ) )
755 #define INT8_C( value ) value
756 #endif
757
758 #if ( !defined( INT16_C ) )
759 #define INT16_C( value ) value
760 #endif
761
762 #if ( !defined( INT32_C ) )
763 #define INT32_C( value ) value ## L
764 #endif
765
766 #if ( !defined( INT64_C ) )
767 #if ( defined( _MSC_VER ) )
768 #define INT64_C( value ) value ## i64
769 #else
770 #define INT64_C( value ) value ## LL
771 #endif
772 #endif
773
774 #if ( !defined( UINT8_C ) )
775 #define UINT8_C( value ) value ## U
776 #endif
777
778 #if ( !defined( UINT16_C ) )
779 #define UINT16_C( value ) value ## U
780 #endif
781
782 #if ( !defined( UINT32_C ) )
783 #define UINT32_C( value ) value ## UL
784 #endif
785
786 #if ( !defined( UINT64_C ) )
787 #if ( defined( _MSC_VER ) )
788 #define UINT64_C( value ) value ## UI64
789 #else
790 #define UINT64_C( value ) value ## ULL
791 #endif
792 #endif
793
794 // Limits
795
796 #if( !defined( UINT32_MAX ) )
797 #define UINT32_MAX UINT32_C( 4294967295 )
798 #endif
799
800 #if 0
801 #pragma mark == bool ==
802 #endif
803
804 //===========================================================================================================================
805 // Boolean Constants and Types
806 //===========================================================================================================================
807
808 // C++ defines bool, true, and false. Metrowerks allows this to be controlled by the "bool" option though.
809 // C99 defines __bool_true_false_are_defined when bool, true, and false are defined.
810 // MacTypes.h defines true and false (Mac builds only).
811 //
812 // Note: The Metrowerks has to be in its own block because Microsoft Visual Studio .NET does not completely
813 // short-circuit and gets confused by the option( bool ) portion of the conditional.
814
815 #if ( defined( __MWERKS__ ) )
816
817 // Note: The following test is done on separate lines because CodeWarrior doesn't like it all on one line.
818
819 #if ( !__bool_true_false_are_defined && ( !defined( __cplusplus ) || !__option( bool ) ) )
820 #define COMMON_SERVICES_NEEDS_BOOL 1
821 #else
822 #define COMMON_SERVICES_NEEDS_BOOL 0
823 #endif
824
825 // Workaround when building with CodeWarrior, but using the Apple stdbool.h header, which uses _Bool.
826
827 #if ( __bool_true_false_are_defined && !defined( __cplusplus ) && !__option( c9x ) )
828 #define _Bool int
829 #endif
830
831 // Workaround when building with CodeWarrior for C++ with bool disabled and using the Apple stdbool.h header,
832 // which defines true and false to map to C++ true and false (which are not enabled). Serenity Now!
833
834 #if ( __bool_true_false_are_defined && defined( __cplusplus ) && !__option( bool ) )
835 #define true 1
836 #define false 0
837 #endif
838 #else
839 #if ( !defined( __cplusplus ) && !__bool_true_false_are_defined )
840 #define COMMON_SERVICES_NEEDS_BOOL 1
841 #else
842 #define COMMON_SERVICES_NEEDS_BOOL 0
843 #endif
844 #endif
845
846 #if ( COMMON_SERVICES_NEEDS_BOOL )
847
848 typedef int bool;
849
850 #define bool bool
851
852 #if ( !defined( __MACTYPES__ ) && !defined( true ) && !defined( false ) )
853 #define true 1
854 #define false 0
855 #endif
856
857 #define __bool_true_false_are_defined 1
858 #endif
859
860 // IOKit IOTypes.h typedef's bool if TYPE_BOOL is not defined so define it here to prevent redefinition by IOTypes.h.
861
862 #if ( TARGET_API_MAC_OSX_KERNEL )
863 #define TYPE_BOOL 1
864 #endif
865
866 //---------------------------------------------------------------------------------------------------------------------------
867 /*! @typedef CStr255
868
869 @abstract 255 character null-terminated (C-style) string.
870 */
871
872 typedef char CStr255[ 256 ];
873
874 //---------------------------------------------------------------------------------------------------------------------------
875 /*! @defined TYPE_LONGLONG_NATIVE
876
877 @abstract Defines whether long long (or its equivalent) is natively supported or requires special libraries.
878 */
879
880 #if ( !defined( TYPE_LONGLONG_NATIVE ) )
881 #define TYPE_LONGLONG_NATIVE 1
882 #endif
883
884 //---------------------------------------------------------------------------------------------------------------------------
885 /*! @defined long_long_compat
886
887 @abstract Compatibility type to map to the closest thing to long long and unsigned long long.
888
889 @discussion
890
891 Neither long long nor unsigned long long are supported by Microsoft compilers, but they do support proprietary
892 "__int64" and "unsigned __int64" equivalents so map to those types if the real long long is not supported.
893 */
894
895 #if ( TARGET_OS_WIN32 )
896 typedef __int64 long_long_compat;
897 typedef unsigned __int64 unsigned_long_long_compat;
898 #else
899 typedef signed long long long_long_compat;
900 typedef unsigned long long unsigned_long_long_compat;
901 #endif
902
903 #if 0
904 #pragma mark == Errors ==
905 #endif
906
907 //---------------------------------------------------------------------------------------------------------------------------
908 /*! @enum OSStatus
909
910 @abstract Status Code
911
912 @constant kNoErr 0 No error occurred.
913 @constant kInProgressErr 1 Operation in progress.
914 @constant kUnknownErr -6700 Unknown error occurred.
915 @constant kOptionErr -6701 Option was not acceptable.
916 @constant kSelectorErr -6702 Selector passed in is invalid or unknown.
917 @constant kExecutionStateErr -6703 Call made in the wrong execution state (e.g. called at interrupt time).
918 @constant kPathErr -6704 Path is invalid, too long, or otherwise not usable.
919 @constant kParamErr -6705 Parameter is incorrect, missing, or not appropriate.
920 @constant kParamCountErr -6706 Incorrect or unsupported number of parameters.
921 @constant kCommandErr -6707 Command invalid or not supported.
922 @constant kIDErr -6708 Unknown, invalid, or inappropriate identifier.
923 @constant kStateErr -6709 Not in appropriate state to perform operation.
924 @constant kRangeErr -6710 Index is out of range or not valid.
925 @constant kRequestErr -6711 Request was improperly formed or not appropriate.
926 @constant kResponseErr -6712 Response was incorrect or out of sequence.
927 @constant kChecksumErr -6713 Checksum does not match the actual data.
928 @constant kNotHandledErr -6714 Operation was not handled (or not handled completely).
929 @constant kVersionErr -6715 Version is not incorrect or not compatibile.
930 @constant kSignatureErr -6716 Signature did not match what was expected.
931 @constant kFormatErr -6717 Unknown, invalid, or inappropriate file/data format.
932 @constant kNotInitializedErr -6718 Action request before needed services were initialized.
933 @constant kAlreadyInitializedErr -6719 Attempt made to initialize when already initialized.
934 @constant kNotInUseErr -6720 Object not in use (e.g. cannot abort if not already in use).
935 @constant kInUseErr -6721 Object is in use (e.g. cannot reuse active param blocks).
936 @constant kTimeoutErr -6722 Timeout occurred.
937 @constant kCanceledErr -6723 Operation canceled (successful cancel).
938 @constant kAlreadyCanceledErr -6724 Operation has already been canceled.
939 @constant kCannotCancelErr -6725 Operation could not be canceled (maybe already done or invalid).
940 @constant kDeletedErr -6726 Object has already been deleted.
941 @constant kNotFoundErr -6727 Something was not found.
942 @constant kNoMemoryErr -6728 Not enough memory was available to perform the operation.
943 @constant kNoResourcesErr -6729 Resources unavailable to perform the operation.
944 @constant kDuplicateErr -6730 Duplicate found or something is a duplicate.
945 @constant kImmutableErr -6731 Entity is not changeable.
946 @constant kUnsupportedDataErr -6732 Data is unknown or not supported.
947 @constant kIntegrityErr -6733 Data is corrupt.
948 @constant kIncompatibleErr -6734 Data is not compatible or it is in an incompatible format.
949 @constant kUnsupportedErr -6735 Feature or option is not supported.
950 @constant kUnexpectedErr -6736 Error occurred that was not expected.
951 @constant kValueErr -6737 Value is not appropriate.
952 @constant kNotReadableErr -6738 Could not read or reading is not allowed.
953 @constant kNotWritableErr -6739 Could not write or writing is not allowed.
954 @constant kBadReferenceErr -6740 An invalid or inappropriate reference was specified.
955 @constant kFlagErr -6741 An invalid, inappropriate, or unsupported flag was specified.
956 @constant kMalformedErr -6742 Something was not formed correctly.
957 @constant kSizeErr -6743 Size was too big, too small, or not appropriate.
958 @constant kNameErr -6744 Name was not correct, allowed, or appropriate.
959 @constant kNotReadyErr -6745 Device or service is not ready.
960 @constant kReadErr -6746 Could not read.
961 @constant kWriteErr -6747 Could not write.
962 @constant kMismatchErr -6748 Something does not match.
963 @constant kDateErr -6749 Date is invalid or out-of-range.
964 @constant kUnderrunErr -6750 Less data than expected.
965 @constant kOverrunErr -6751 More data than expected.
966 @constant kEndingErr -6752 Connection, session, or something is ending.
967 @constant kConnectionErr -6753 Connection failed or could not be established.
968 @constant kAuthenticationErr -6754 Authentication failed or is not supported.
969 @constant kOpenErr -6755 Could not open file, pipe, device, etc.
970 @constant kTypeErr -6756 Incorrect or incompatible type (e.g. file, data, etc.).
971 @constant kSkipErr -6757 Items should be or was skipped.
972 @constant kNoAckErr -6758 No acknowledge.
973 @constant kCollisionErr -6759 Collision occurred (e.g. two on bus at same time).
974 @constant kBackoffErr -6760 Backoff in progress and operation intentionally failed.
975 @constant kNoAddressAckErr -6761 No acknowledge of address.
976 @constant kBusyErr -6762 Cannot perform because something is busy.
977 @constant kNoSpaceErr -6763 Not enough space to perform operation.
978 */
979
980 #if ( !TARGET_OS_MAC && !TARGET_API_MAC_OSX_KERNEL )
981 typedef int32_t OSStatus;
982 #endif
983
984 #define kNoErr 0
985 #define kInProgressErr 1
986
987 // Generic error codes are in the range -6700 to -6779.
988
989 #define kGenericErrorBase -6700 // Starting error code for all generic errors.
990
991 #define kUnknownErr -6700
992 #define kOptionErr -6701
993 #define kSelectorErr -6702
994 #define kExecutionStateErr -6703
995 #define kPathErr -6704
996 #define kParamErr -6705
997 #define kParamCountErr -6706
998 #define kCommandErr -6707
999 #define kIDErr -6708
1000 #define kStateErr -6709
1001 #define kRangeErr -6710
1002 #define kRequestErr -6711
1003 #define kResponseErr -6712
1004 #define kChecksumErr -6713
1005 #define kNotHandledErr -6714
1006 #define kVersionErr -6715
1007 #define kSignatureErr -6716
1008 #define kFormatErr -6717
1009 #define kNotInitializedErr -6718
1010 #define kAlreadyInitializedErr -6719
1011 #define kNotInUseErr -6720
1012 #define kInUseErr -6721
1013 #define kTimeoutErr -6722
1014 #define kCanceledErr -6723
1015 #define kAlreadyCanceledErr -6724
1016 #define kCannotCancelErr -6725
1017 #define kDeletedErr -6726
1018 #define kNotFoundErr -6727
1019 #define kNoMemoryErr -6728
1020 #define kNoResourcesErr -6729
1021 #define kDuplicateErr -6730
1022 #define kImmutableErr -6731
1023 #define kUnsupportedDataErr -6732
1024 #define kIntegrityErr -6733
1025 #define kIncompatibleErr -6734
1026 #define kUnsupportedErr -6735
1027 #define kUnexpectedErr -6736
1028 #define kValueErr -6737
1029 #define kNotReadableErr -6738
1030 #define kNotWritableErr -6739
1031 #define kBadReferenceErr -6740
1032 #define kFlagErr -6741
1033 #define kMalformedErr -6742
1034 #define kSizeErr -6743
1035 #define kNameErr -6744
1036 #define kNotReadyErr -6745
1037 #define kReadErr -6746
1038 #define kWriteErr -6747
1039 #define kMismatchErr -6748
1040 #define kDateErr -6749
1041 #define kUnderrunErr -6750
1042 #define kOverrunErr -6751
1043 #define kEndingErr -6752
1044 #define kConnectionErr -6753
1045 #define kAuthenticationErr -6754
1046 #define kOpenErr -6755
1047 #define kTypeErr -6756
1048 #define kSkipErr -6757
1049 #define kNoAckErr -6758
1050 #define kCollisionErr -6759
1051 #define kBackoffErr -6760
1052 #define kNoAddressAckErr -6761
1053 #define kBusyErr -6762
1054 #define kNoSpaceErr -6763
1055
1056 #define kGenericErrorEnd -6779 // Last generic error code (inclusive)
1057
1058 #if 0
1059 #pragma mark == Mac Compatibility ==
1060 #endif
1061
1062 //===========================================================================================================================
1063 // Mac Compatibility
1064 //===========================================================================================================================
1065
1066 //---------------------------------------------------------------------------------------------------------------------------
1067 /*! @enum Duration
1068
1069 @abstract Type used to specify a duration of time.
1070
1071 @constant kDurationImmediate Indicates no delay/wait time.
1072 @constant kDurationMicrosecond Microsecond units.
1073 @constant kDurationMillisecond Millisecond units.
1074 @constant kDurationSecond Second units.
1075 @constant kDurationMinute Minute units.
1076 @constant kDurationHour Hour units.
1077 @constant kDurationDay Day units.
1078 @constant kDurationForever Infinite period of time (no timeout).
1079
1080 @discussion
1081
1082 Duration values are intended to be multiplied by the specific interval to achieve an actual duration. For example,
1083 to wait for 5 seconds you would use "5 * kDurationSecond".
1084 */
1085
1086 #if ( !TARGET_OS_MAC )
1087 typedef int32_t Duration;
1088 #endif
1089
1090 #define kDurationImmediate 0L
1091 #define kDurationMicrosecond -1L
1092 #define kDurationMillisecond 1L
1093 #define kDurationSecond ( 1000L * kDurationMillisecond )
1094 #define kDurationMinute ( 60L * kDurationSecond )
1095 #define kDurationHour ( 60L * kDurationMinute )
1096 #define kDurationDay ( 24L * kDurationHour )
1097 #define kDurationForever 0x7FFFFFFFL
1098
1099 // Seconds <-> Minutes <-> Hours <-> Days <-> Weeks <-> Months <-> Years conversions
1100
1101 #define kNanosecondsPerMicrosecond 1000
1102 #define kNanosecondsPerMillisecond 1000000
1103 #define kNanosecondsPerSecond 1000000000
1104 #define kMicrosecondsPerSecond 1000000
1105 #define kMicrosecondsPerMillisecond 1000
1106 #define kMillisecondsPerSecond 1000
1107 #define kSecondsPerMinute 60
1108 #define kSecondsPerHour ( 60 * 60 ) // 3600
1109 #define kSecondsPerDay ( 60 * 60 * 24 ) // 86400
1110 #define kSecondsPerWeek ( 60 * 60 * 24 * 7 ) // 604800
1111 #define kMinutesPerHour 60
1112 #define kMinutesPerDay ( 60 * 24 ) // 1440
1113 #define kHoursPerDay 24
1114 #define kDaysPerWeek 7
1115 #define kWeeksPerYear 52
1116 #define kMonthsPerYear 12
1117
1118 //---------------------------------------------------------------------------------------------------------------------------
1119 /*! @defined VersionStages
1120
1121 @abstract NumVersion-style version stages.
1122 */
1123
1124 #define kVersionStageDevelopment 0x20
1125 #define kVersionStageAlpha 0x40
1126 #define kVersionStageBeta 0x60
1127 #define kVersionStageFinal 0x80
1128
1129 //---------------------------------------------------------------------------------------------------------------------------
1130 /*! @function NumVersionBuild
1131
1132 @abstract Builds a 32-bit Mac-style NumVersion value (e.g. NumVersionBuild( 1, 2, 3, kVersionStageBeta, 4 ) -> 1.2.3b4).
1133 */
1134
1135 #define NumVersionBuild( MAJOR, MINOR, BUGFIX, STAGE, REV ) \
1136 ( ( ( ( MAJOR ) & 0xFF ) << 24 ) | \
1137 ( ( ( MINOR ) & 0x0F ) << 20 ) | \
1138 ( ( ( BUGFIX ) & 0x0F ) << 16 ) | \
1139 ( ( ( STAGE ) & 0xFF ) << 8 ) | \
1140 ( ( ( REV ) & 0xFF ) ) )
1141
1142 #define NumVersionExtractMajor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 24 ) & 0xFF ) )
1143 #define NumVersionExtractMinorAndBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0xFF ) )
1144 #define NumVersionExtractMinor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 20 ) & 0x0F ) )
1145 #define NumVersionExtractBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0x0F ) )
1146 #define NumVersionExtractStage( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 8 ) & 0xFF ) )
1147 #define NumVersionExtractRevision( VERSION ) ( (uint8_t)( ( VERSION ) & 0xFF ) )
1148
1149 //---------------------------------------------------------------------------------------------------------------------------
1150 /*! @function NumVersionCompare
1151
1152 @abstract Compares two NumVersion values and returns the following values:
1153
1154 left < right -> -1
1155 left > right -> 1
1156 left = right -> 0
1157 */
1158
1159 int NumVersionCompare( uint32_t inLeft, uint32_t inRight );
1160
1161 #if 0
1162 #pragma mark == Binary Constants ==
1163 #endif
1164
1165 //---------------------------------------------------------------------------------------------------------------------------
1166 /*! @defined binary_4
1167
1168 @abstract Macro to generate an 4-bit constant using binary notation (e.g. binary_4( 1010 ) == 0xA).
1169 */
1170
1171 #define binary_4( a ) binary_4_hex_wrap( hex_digit4( a ) )
1172 #define binary_4_hex_wrap( a ) binary_4_hex( a )
1173 #define binary_4_hex( a ) ( 0x ## a )
1174
1175 //---------------------------------------------------------------------------------------------------------------------------
1176 /*! @defined binary_8
1177
1178 @abstract Macro to generate an 8-bit constant using binary notation (e.g. binary_8( 01111011 ) == 0x7B).
1179 */
1180
1181 #define binary_8( a ) binary_8_hex_wrap( hex_digit8( a ) )
1182 #define binary_8_hex_wrap( a ) binary_8_hex( a )
1183 #define binary_8_hex( a ) ( 0x ## a )
1184
1185 //---------------------------------------------------------------------------------------------------------------------------
1186 /*! @defined binary_16
1187
1188 @abstract Macro to generate an 16-bit constant using binary notation (e.g. binary_16( 01111011, 01111011 ) == 0x7B7B).
1189 */
1190
1191 #define binary_16( a, b ) binary_16_hex_wrap( hex_digit8( a ), hex_digit8( b ) )
1192 #define binary_16_hex_wrap( a, b ) binary_16_hex( a, b )
1193 #define binary_16_hex( a, b ) ( 0x ## a ## b )
1194
1195 //---------------------------------------------------------------------------------------------------------------------------
1196 /*! @defined binary_32
1197
1198 @abstract Macro to generate an 32-bit constant using binary notation
1199 (e.g. binary_32( 01111011, 01111011, 01111011, 01111011 ) == 0x7B7B7B7B).
1200 */
1201
1202 #define binary_32( a, b, c, d ) binary_32_hex_wrap( hex_digit8( a ), hex_digit8( b ), hex_digit8( c ), hex_digit8( d ) )
1203 #define binary_32_hex_wrap( a, b, c, d ) binary_32_hex( a, b, c, d )
1204 #define binary_32_hex( a, b, c, d ) ( 0x ## a ## b ## c ## d )
1205
1206 // Binary Constant Helpers
1207
1208 #define hex_digit8( a ) HEX_DIGIT_ ## a
1209 #define hex_digit4( a ) HEX_DIGIT_ ## 0000 ## a
1210
1211 #define HEX_DIGIT_00000000 00
1212 #define HEX_DIGIT_00000001 01
1213 #define HEX_DIGIT_00000010 02
1214 #define HEX_DIGIT_00000011 03
1215 #define HEX_DIGIT_00000100 04
1216 #define HEX_DIGIT_00000101 05
1217 #define HEX_DIGIT_00000110 06
1218 #define HEX_DIGIT_00000111 07
1219 #define HEX_DIGIT_00001000 08
1220 #define HEX_DIGIT_00001001 09
1221 #define HEX_DIGIT_00001010 0A
1222 #define HEX_DIGIT_00001011 0B
1223 #define HEX_DIGIT_00001100 0C
1224 #define HEX_DIGIT_00001101 0D
1225 #define HEX_DIGIT_00001110 0E
1226 #define HEX_DIGIT_00001111 0F
1227 #define HEX_DIGIT_00010000 10
1228 #define HEX_DIGIT_00010001 11
1229 #define HEX_DIGIT_00010010 12
1230 #define HEX_DIGIT_00010011 13
1231 #define HEX_DIGIT_00010100 14
1232 #define HEX_DIGIT_00010101 15
1233 #define HEX_DIGIT_00010110 16
1234 #define HEX_DIGIT_00010111 17
1235 #define HEX_DIGIT_00011000 18
1236 #define HEX_DIGIT_00011001 19
1237 #define HEX_DIGIT_00011010 1A
1238 #define HEX_DIGIT_00011011 1B
1239 #define HEX_DIGIT_00011100 1C
1240 #define HEX_DIGIT_00011101 1D
1241 #define HEX_DIGIT_00011110 1E
1242 #define HEX_DIGIT_00011111 1F
1243 #define HEX_DIGIT_00100000 20
1244 #define HEX_DIGIT_00100001 21
1245 #define HEX_DIGIT_00100010 22
1246 #define HEX_DIGIT_00100011 23
1247 #define HEX_DIGIT_00100100 24
1248 #define HEX_DIGIT_00100101 25
1249 #define HEX_DIGIT_00100110 26
1250 #define HEX_DIGIT_00100111 27
1251 #define HEX_DIGIT_00101000 28
1252 #define HEX_DIGIT_00101001 29
1253 #define HEX_DIGIT_00101010 2A
1254 #define HEX_DIGIT_00101011 2B
1255 #define HEX_DIGIT_00101100 2C
1256 #define HEX_DIGIT_00101101 2D
1257 #define HEX_DIGIT_00101110 2E
1258 #define HEX_DIGIT_00101111 2F
1259 #define HEX_DIGIT_00110000 30
1260 #define HEX_DIGIT_00110001 31
1261 #define HEX_DIGIT_00110010 32
1262 #define HEX_DIGIT_00110011 33
1263 #define HEX_DIGIT_00110100 34
1264 #define HEX_DIGIT_00110101 35
1265 #define HEX_DIGIT_00110110 36
1266 #define HEX_DIGIT_00110111 37
1267 #define HEX_DIGIT_00111000 38
1268 #define HEX_DIGIT_00111001 39
1269 #define HEX_DIGIT_00111010 3A
1270 #define HEX_DIGIT_00111011 3B
1271 #define HEX_DIGIT_00111100 3C
1272 #define HEX_DIGIT_00111101 3D
1273 #define HEX_DIGIT_00111110 3E
1274 #define HEX_DIGIT_00111111 3F
1275 #define HEX_DIGIT_01000000 40
1276 #define HEX_DIGIT_01000001 41
1277 #define HEX_DIGIT_01000010 42
1278 #define HEX_DIGIT_01000011 43
1279 #define HEX_DIGIT_01000100 44
1280 #define HEX_DIGIT_01000101 45
1281 #define HEX_DIGIT_01000110 46
1282 #define HEX_DIGIT_01000111 47
1283 #define HEX_DIGIT_01001000 48
1284 #define HEX_DIGIT_01001001 49
1285 #define HEX_DIGIT_01001010 4A
1286 #define HEX_DIGIT_01001011 4B
1287 #define HEX_DIGIT_01001100 4C
1288 #define HEX_DIGIT_01001101 4D
1289 #define HEX_DIGIT_01001110 4E
1290 #define HEX_DIGIT_01001111 4F
1291 #define HEX_DIGIT_01010000 50
1292 #define HEX_DIGIT_01010001 51
1293 #define HEX_DIGIT_01010010 52
1294 #define HEX_DIGIT_01010011 53
1295 #define HEX_DIGIT_01010100 54
1296 #define HEX_DIGIT_01010101 55
1297 #define HEX_DIGIT_01010110 56
1298 #define HEX_DIGIT_01010111 57
1299 #define HEX_DIGIT_01011000 58
1300 #define HEX_DIGIT_01011001 59
1301 #define HEX_DIGIT_01011010 5A
1302 #define HEX_DIGIT_01011011 5B
1303 #define HEX_DIGIT_01011100 5C
1304 #define HEX_DIGIT_01011101 5D
1305 #define HEX_DIGIT_01011110 5E
1306 #define HEX_DIGIT_01011111 5F
1307 #define HEX_DIGIT_01100000 60
1308 #define HEX_DIGIT_01100001 61
1309 #define HEX_DIGIT_01100010 62
1310 #define HEX_DIGIT_01100011 63
1311 #define HEX_DIGIT_01100100 64
1312 #define HEX_DIGIT_01100101 65
1313 #define HEX_DIGIT_01100110 66
1314 #define HEX_DIGIT_01100111 67
1315 #define HEX_DIGIT_01101000 68
1316 #define HEX_DIGIT_01101001 69
1317 #define HEX_DIGIT_01101010 6A
1318 #define HEX_DIGIT_01101011 6B
1319 #define HEX_DIGIT_01101100 6C
1320 #define HEX_DIGIT_01101101 6D
1321 #define HEX_DIGIT_01101110 6E
1322 #define HEX_DIGIT_01101111 6F
1323 #define HEX_DIGIT_01110000 70
1324 #define HEX_DIGIT_01110001 71
1325 #define HEX_DIGIT_01110010 72
1326 #define HEX_DIGIT_01110011 73
1327 #define HEX_DIGIT_01110100 74
1328 #define HEX_DIGIT_01110101 75
1329 #define HEX_DIGIT_01110110 76
1330 #define HEX_DIGIT_01110111 77
1331 #define HEX_DIGIT_01111000 78
1332 #define HEX_DIGIT_01111001 79
1333 #define HEX_DIGIT_01111010 7A
1334 #define HEX_DIGIT_01111011 7B
1335 #define HEX_DIGIT_01111100 7C
1336 #define HEX_DIGIT_01111101 7D
1337 #define HEX_DIGIT_01111110 7E
1338 #define HEX_DIGIT_01111111 7F
1339 #define HEX_DIGIT_10000000 80
1340 #define HEX_DIGIT_10000001 81
1341 #define HEX_DIGIT_10000010 82
1342 #define HEX_DIGIT_10000011 83
1343 #define HEX_DIGIT_10000100 84
1344 #define HEX_DIGIT_10000101 85
1345 #define HEX_DIGIT_10000110 86
1346 #define HEX_DIGIT_10000111 87
1347 #define HEX_DIGIT_10001000 88
1348 #define HEX_DIGIT_10001001 89
1349 #define HEX_DIGIT_10001010 8A
1350 #define HEX_DIGIT_10001011 8B
1351 #define HEX_DIGIT_10001100 8C
1352 #define HEX_DIGIT_10001101 8D
1353 #define HEX_DIGIT_10001110 8E
1354 #define HEX_DIGIT_10001111 8F
1355 #define HEX_DIGIT_10010000 90
1356 #define HEX_DIGIT_10010001 91
1357 #define HEX_DIGIT_10010010 92
1358 #define HEX_DIGIT_10010011 93
1359 #define HEX_DIGIT_10010100 94
1360 #define HEX_DIGIT_10010101 95
1361 #define HEX_DIGIT_10010110 96
1362 #define HEX_DIGIT_10010111 97
1363 #define HEX_DIGIT_10011000 98
1364 #define HEX_DIGIT_10011001 99
1365 #define HEX_DIGIT_10011010 9A
1366 #define HEX_DIGIT_10011011 9B
1367 #define HEX_DIGIT_10011100 9C
1368 #define HEX_DIGIT_10011101 9D
1369 #define HEX_DIGIT_10011110 9E
1370 #define HEX_DIGIT_10011111 9F
1371 #define HEX_DIGIT_10100000 A0
1372 #define HEX_DIGIT_10100001 A1
1373 #define HEX_DIGIT_10100010 A2
1374 #define HEX_DIGIT_10100011 A3
1375 #define HEX_DIGIT_10100100 A4
1376 #define HEX_DIGIT_10100101 A5
1377 #define HEX_DIGIT_10100110 A6
1378 #define HEX_DIGIT_10100111 A7
1379 #define HEX_DIGIT_10101000 A8
1380 #define HEX_DIGIT_10101001 A9
1381 #define HEX_DIGIT_10101010 AA
1382 #define HEX_DIGIT_10101011 AB
1383 #define HEX_DIGIT_10101100 AC
1384 #define HEX_DIGIT_10101101 AD
1385 #define HEX_DIGIT_10101110 AE
1386 #define HEX_DIGIT_10101111 AF
1387 #define HEX_DIGIT_10110000 B0
1388 #define HEX_DIGIT_10110001 B1
1389 #define HEX_DIGIT_10110010 B2
1390 #define HEX_DIGIT_10110011 B3
1391 #define HEX_DIGIT_10110100 B4
1392 #define HEX_DIGIT_10110101 B5
1393 #define HEX_DIGIT_10110110 B6
1394 #define HEX_DIGIT_10110111 B7
1395 #define HEX_DIGIT_10111000 B8
1396 #define HEX_DIGIT_10111001 B9
1397 #define HEX_DIGIT_10111010 BA
1398 #define HEX_DIGIT_10111011 BB
1399 #define HEX_DIGIT_10111100 BC
1400 #define HEX_DIGIT_10111101 BD
1401 #define HEX_DIGIT_10111110 BE
1402 #define HEX_DIGIT_10111111 BF
1403 #define HEX_DIGIT_11000000 C0
1404 #define HEX_DIGIT_11000001 C1
1405 #define HEX_DIGIT_11000010 C2
1406 #define HEX_DIGIT_11000011 C3
1407 #define HEX_DIGIT_11000100 C4
1408 #define HEX_DIGIT_11000101 C5
1409 #define HEX_DIGIT_11000110 C6
1410 #define HEX_DIGIT_11000111 C7
1411 #define HEX_DIGIT_11001000 C8
1412 #define HEX_DIGIT_11001001 C9
1413 #define HEX_DIGIT_11001010 CA
1414 #define HEX_DIGIT_11001011 CB
1415 #define HEX_DIGIT_11001100 CC
1416 #define HEX_DIGIT_11001101 CD
1417 #define HEX_DIGIT_11001110 CE
1418 #define HEX_DIGIT_11001111 CF
1419 #define HEX_DIGIT_11010000 D0
1420 #define HEX_DIGIT_11010001 D1
1421 #define HEX_DIGIT_11010010 D2
1422 #define HEX_DIGIT_11010011 D3
1423 #define HEX_DIGIT_11010100 D4
1424 #define HEX_DIGIT_11010101 D5
1425 #define HEX_DIGIT_11010110 D6
1426 #define HEX_DIGIT_11010111 D7
1427 #define HEX_DIGIT_11011000 D8
1428 #define HEX_DIGIT_11011001 D9
1429 #define HEX_DIGIT_11011010 DA
1430 #define HEX_DIGIT_11011011 DB
1431 #define HEX_DIGIT_11011100 DC
1432 #define HEX_DIGIT_11011101 DD
1433 #define HEX_DIGIT_11011110 DE
1434 #define HEX_DIGIT_11011111 DF
1435 #define HEX_DIGIT_11100000 E0
1436 #define HEX_DIGIT_11100001 E1
1437 #define HEX_DIGIT_11100010 E2
1438 #define HEX_DIGIT_11100011 E3
1439 #define HEX_DIGIT_11100100 E4
1440 #define HEX_DIGIT_11100101 E5
1441 #define HEX_DIGIT_11100110 E6
1442 #define HEX_DIGIT_11100111 E7
1443 #define HEX_DIGIT_11101000 E8
1444 #define HEX_DIGIT_11101001 E9
1445 #define HEX_DIGIT_11101010 EA
1446 #define HEX_DIGIT_11101011 EB
1447 #define HEX_DIGIT_11101100 EC
1448 #define HEX_DIGIT_11101101 ED
1449 #define HEX_DIGIT_11101110 EE
1450 #define HEX_DIGIT_11101111 EF
1451 #define HEX_DIGIT_11110000 F0
1452 #define HEX_DIGIT_11110001 F1
1453 #define HEX_DIGIT_11110010 F2
1454 #define HEX_DIGIT_11110011 F3
1455 #define HEX_DIGIT_11110100 F4
1456 #define HEX_DIGIT_11110101 F5
1457 #define HEX_DIGIT_11110110 F6
1458 #define HEX_DIGIT_11110111 F7
1459 #define HEX_DIGIT_11111000 F8
1460 #define HEX_DIGIT_11111001 F9
1461 #define HEX_DIGIT_11111010 FA
1462 #define HEX_DIGIT_11111011 FB
1463 #define HEX_DIGIT_11111100 FC
1464 #define HEX_DIGIT_11111101 FD
1465 #define HEX_DIGIT_11111110 FE
1466 #define HEX_DIGIT_11111111 FF
1467
1468 #if 0
1469 #pragma mark == Debugging ==
1470 #endif
1471
1472 //---------------------------------------------------------------------------------------------------------------------------
1473 /*! @function CommonServicesTest
1474
1475 @abstract Unit test.
1476 */
1477
1478 #if ( DEBUG )
1479 OSStatus CommonServicesTest( void );
1480 #endif
1481
1482 #ifdef __cplusplus
1483 }
1484 #endif
1485
1486 #endif // __COMMON_SERVICES__