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