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