Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
posh.h
Go to the documentation of this file.
1 
149 #if defined FORCE_DOXYGEN
150 # define POSH_OS_STRING
151 #endif
152 
153 /* ------------------------------------------------------------------
154 ** Linux
155 ** ------------------------------------------------------------------
156 */
157 #if defined linux || defined __linux__ || defined FORCE_DOXYGEN
158 # define POSH_OS_LINUX
159 # if !defined FORCE_DOXYGEN
160 # define POSH_OS_STRING "Linux"
161 # endif
162 #endif
163 
164 /* ------------------------------------------------------------------
165 ** Haiku
166 ** ------------------------------------------------------------------
167 */
168 #if defined(__HAIKU__) || defined FORCE_DOXYGEN
169 # define POSH_OS_HAIKU
170 # if !defined FORCE_DOXYGEN
171 # define POSH_OS_STRING "Haiku"
172 # endif
173 #endif
174 
175 /* ------------------------------------------------------------------
176 ** Cygwin32
177 ** ------------------------------------------------------------------
178 */
179 #if defined __CYGWIN32__ || defined FORCE_DOXYGEN
180 # define POSH_OS_CYGWIN32
181 # if !defined FORCE_DOXYGEN
182 # define POSH_OS_STRING "Cygwin"
183 # endif
184 #endif
185 
186 /* ------------------------------------------------------------------
187 ** DJGPP/GO32
188 ** ------------------------------------------------------------------
189 */
190 #if defined GO32 && defined DJGPP && defined __MSDOS__ || defined FORCE_DOXYGEN
191 # define POSH_OS_GO32
192 # if !defined FORCE_DOXYGEN
193 # define POSH_OS_STRING "GO32/MS-DOS"
194 # endif
195 #endif
196 
197 /* ------------------------------------------------------------------
198 ** 32-bit DOS via Watcom
199 ** NOTE: make sure you use /bt=DOS if compiling for 32-bit DOS,
200 ** otherwise Watcom assumes host=target
201 ** ------------------------------------------------------------------
202 */
203 #if (defined __WATCOMC__ && defined __386__ && defined __DOS__) || defined FORCE_DOXYGEN
204 # define POSH_OS_DOS32
205 # if !defined FORCE_DOXYGEN
206 # define POSH_OS_STRING "DOS/32-bit"
207 # endif
208 #endif
209 
210 /* ------------------------------------------------------------------
211 ** Cray UNICOS
212 ** ------------------------------------------------------------------
213 */
214 #if defined _UNICOS || defined FORCE_DOXYGEN
215 # define POSH_OS_UNICOS
216 # if !defined FORCE_DOXYGEN
217 # define POSH_OS_STRING "UNICOS"
218 # endif
219 #endif
220 
221 /* ------------------------------------------------------------------
222 ** Mac OS X
223 ** ------------------------------------------------------------------
224 */
225 #if (defined __MWERKS__ && defined __powerc && !defined macintosh) || defined __APPLE_CC__ || defined macosx \
226  || defined FORCE_DOXYGEN
227 # define POSH_OS_OSX
228 # if !defined FORCE_DOXYGEN
229 # define POSH_OS_STRING "MacOS X"
230 # endif
231 #endif
232 
233 /* ------------------------------------------------------------------
234 ** Solaris/SunOS
235 ** ------------------------------------------------------------------
236 */
237 #if defined __sun__ || defined sun || defined __sun || defined __solaris__ || defined FORCE_DOXYGEN
238 # if defined __SVR4 || defined __svr4__ || defined __solaris__ || defined FORCE_DOXYGEN
239 # if !defined FORCE_DOXYGEN
240 # define POSH_OS_STRING "Solaris"
241 # endif
242 # define POSH_OS_SOLARIS
243 # endif
244 # if defined FORCE_DOXYGEN || !defined POSH_OS_STRING
245 # define POSH_OS_SUNOS
246 # if !defined FORCE_DOXYGEN
247 # define POSH_OS_STRING "SunOS"
248 # endif
249 # endif
250 #endif
251 
252 /* ------------------------------------------------------------------
253 ** SGI Irix
254 ** ------------------------------------------------------------------
255 */
256 #if defined __sgi__ || defined sgi || defined __sgi || defined FORCE_DOXYGEN
257 # define POSH_OS_IRIX
258 # if !defined FORCE_DOXYGEN
259 # define POSH_OS_STRING "Irix"
260 # endif
261 #endif
262 
263 /* ------------------------------------------------------------------
264 ** HP-UX
265 ** ------------------------------------------------------------------
266 */
267 #if defined __hpux__ || defined __hpux || defined FORCE_DOXYGEN
268 # define POSH_OS_HPUX
269 # if !defined FORCE_DOXYGEN
270 # define POSH_OS_STRING "HP-UX"
271 # endif
272 #endif
273 
274 /* ------------------------------------------------------------------
275 ** AIX
276 ** ------------------------------------------------------------------
277 */
278 #if defined _AIX || defined FORCE_DOXYGEN
279 # define POSH_OS_AIX
280 # if !defined FORCE_DOXYGEN
281 # define POSH_OS_STRING "AIX"
282 # endif
283 #endif
284 
285 /* ------------------------------------------------------------------
286 ** DEC Alpha/Tru64
287 ** ------------------------------------------------------------------
288 */
289 #if (defined __alpha && defined __osf__) || defined FORCE_DOXYGEN
290 # define POSH_OS_TRU64
291 # if !defined FORCE_DOXYGEN
292 # define POSH_OS_STRING "Tru64"
293 # endif
294 #endif
295 
296 /* ------------------------------------------------------------------
297 ** BeOS (untested)
298 ** ------------------------------------------------------------------
299 */
300 #if defined __BEOS__ || defined __beos__ || defined FORCE_DOXYGEN
301 # define POSH_OS_BEOS
302 # if !defined FORCE_DOXYGEN
303 # define POSH_OS_STRING "BeOS"
304 # endif
305 #endif
306 
307 /* ------------------------------------------------------------------
308 ** Amiga (untested)
309 ** ------------------------------------------------------------------
310 */
311 #if defined amiga || defined amigados || defined AMIGA || defined _AMIGA || defined FORCE_DOXYGEN
312 # define POSH_OS_AMIGA
313 # if !defined FORCE_DOXYGEN
314 # define POSH_OS_STRING "Amiga"
315 # endif
316 #endif
317 
318 /* ------------------------------------------------------------------
319 ** Generic UNIX-like fallback
320 ** ------------------------------------------------------------------
321 */
322 #if defined __unix__ || defined FORCE_DOXYGEN
323 # define POSH_OS_UNIX
324 # if !defined POSH_OS_STRING
325 # define POSH_OS_STRING "Unix-like(generic)"
326 # endif
327 #endif
328 
329 /* ------------------------------------------------------------------
330 ** WinCE
331 ** ------------------------------------------------------------------
332 */
333 #if defined _WIN32_WCE || defined FORCE_DOXYGEN
334 # define POSH_OS_WINCE
335 # if !defined FORCE_DOXYGEN
336 # define POSH_OS_STRING "Windows CE"
337 # endif
338 #endif
339 
340 /* ------------------------------------------------------------------
341 ** Win32/Win64
342 ** ------------------------------------------------------------------
343 */
344 #if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__ || defined FORCE_DOXYGEN
345 # define POSH_OS_WIN32
346 # if defined _WIN64 || defined FORCE_DOXYGEN
347 # define POSH_OS_WIN64
348 # if !defined FORCE_DOXYGEN
349 # define POSH_OS_STRING "Win64"
350 # endif
351 # else
352 # if !defined FORCE_DOXYGEN
353 # define POSH_OS_STRING "Win32"
354 # endif
355 # endif
356 #endif
357 
358 /* ------------------------------------------------------------------
359 ** PalmOS
360 ** ------------------------------------------------------------------
361 */
362 #if defined __palmos__ || defined FORCE_DOXYGEN
363 # define POSH_OS_PALM
364 # if !defined FORCE_DOXYGEN
365 # define POSH_OS_STRING "PalmOS"
366 # endif
367 #endif
368 
369 /* ------------------------------------------------------------------
370 ** MacOS
371 ** ------------------------------------------------------------------
372 */
373 #if (defined __MWERKS__ && !defined __powerc) || defined THINK_C || defined macintosh || defined FORCE_DOXYGEN
374 # define POSH_OS_MACOS
375 # if !defined FORCE_DOXYGEN
376 # define POSH_OS_STRING "MacOS"
377 # endif
378 #endif
379 
386 #if defined FORCE_DOXYGEN
387 # define POSH_CPU_STRING
388 #endif
389 
390 /* ------------------------------------------------------------------
391 ** Motorola 68000
392 ** ------------------------------------------------------------------
393 */
394 #if defined mc68000 || defined m68k || defined __MC68K__ || defined m68000 || defined FORCE_DOXYGEN
395 # define POSH_CPU_68K
396 # if !defined FORCE_DOXYGEN
397 # define POSH_CPU_STRING "MC68000"
398 # endif
399 #endif
400 
401 /* ------------------------------------------------------------------
402 ** PowerPC
403 ** ------------------------------------------------------------------
404 */
405 #if defined __PPC__ || defined __POWERPC__ || defined powerpc || defined _POWER || defined __ppc__ || defined __powerpc__ \
406  || defined FORCE_DOXYGEN
407 # define POSH_CPU_PPC
408 # if !defined FORCE_DOXYGEN
409 # if defined __powerpc64__
410 # define POSH_CPU_STRING "PowerPC64"
411 # else
412 # define POSH_CPU_STRING "PowerPC"
413 # endif
414 # endif
415 #endif
416 
417 /* ------------------------------------------------------------------
418 ** Cray T3E
419 ** ------------------------------------------------------------------
420 */
421 #if defined _CRAYT3E || defined _CRAYMPP || defined FORCE_DOXYGEN
422 # define POSH_CPU_CRAYT3E
423 # if !defined FORCE_DOXYGEN
424 # define POSH_CPU_STRING "Cray T3E (Alpha 21164)"
425 # endif
426 #endif
427 
428 /* ------------------------------------------------------------------
429 ** Cray (non-21164)
430 ** ------------------------------------------------------------------
431 */
432 #if defined CRAY || defined _CRAY && !defined _CRAYT3E
433 # error Non-AXP Cray systems not supported
434 #endif
435 
436 /* ------------------------------------------------------------------
437 ** Hitachi SH3
438 ** ------------------------------------------------------------------
439 */
440 #if defined _SH3 || defined FORCE_DOXYGEN
441 # define POSH_CPU_SH3
442 # if !defined FORCE_DOXYGEN
443 # define POSH_CPU_STRING "Hitachi SH-3"
444 # endif
445 #endif
446 
447 /* ------------------------------------------------------------------
448 ** Hitachi SH4 (presumably Dreamcast)
449 ** ------------------------------------------------------------------
450 */
451 #if defined __sh4__ || defined __SH4__ || defined FORCE_DOXYGEN
452 # define POSH_CPU_SH3
453 # define POSH_CPU_SH4
454 # if !defined FORCE_DOXYGEN
455 # define POSH_CPU_STRING "Hitachi SH-4"
456 # endif
457 #endif
458 
459 /* ------------------------------------------------------------------
460 ** Sun SPARC
461 ** ------------------------------------------------------------------
462 */
463 #if defined __sparc__ || defined __sparc || defined FORCE_DOXYGEN
464 # if defined __arch64__ || defined __sparcv9 || defined __sparc_v9__ || defined FORCE_DOXYGEN
465 # define POSH_CPU_SPARC64
466 # if !defined FORCE_DOXYGEN
467 # define POSH_CPU_STRING "Sparc/64"
468 # endif
469 # else
470 # if !defined FORCE_DOXYGEN
471 # define POSH_CPU_STRING "Sparc/32"
472 # endif
473 # endif
474 # define POSH_CPU_SPARC
475 #endif
476 
477 /* ------------------------------------------------------------------
478 ** StrongARM
479 ** ------------------------------------------------------------------
480 */
481 #if defined __arm__ || defined _ARM || defined FORCE_DOXYGEN
482 # define POSH_CPU_STRONGARM
483 # if !defined FORCE_DOXYGEN
484 # define POSH_CPU_STRING "ARM"
485 # endif
486 #endif
487 
488 /* ------------------------------------------------------------------
489 ** MIPS (various, including SGI and Sony PS2)
490 ** ------------------------------------------------------------------
491 */
492 #if defined mips || defined __mips__ || defined __MIPS__ || defined _MIPS || defined FORCE_DOXYGEN
493 # define POSH_CPU_MIPS
494 # if defined _R5900 && !defined FORCE_DOXYGEN
495 # define POSH_CPU_STRING "MIPS R5900 (PS2)"
496 # elif !defined FORCE_DOXYGEN
497 # define POSH_CPU_STRING "MIPS"
498 # endif
499 #endif
500 
501 /* ------------------------------------------------------------------
502 ** Intel Itanium IA64
503 ** ------------------------------------------------------------------
504 */
505 #if defined __ia64 || defined _M_IA64 || defined __ia64__ || defined FORCE_DOXYGEN
506 # define POSH_CPU_IA64
507 # if !defined FORCE_DOXYGEN
508 # define POSH_CPU_STRING "IA64"
509 # endif
510 #endif
511 
512 /* ------------------------------------------------------------------
513 ** Intel x86 and AMD x86-64
514 ** ------------------------------------------------------------------
515 */
516 #if defined __X86__ || defined __i386__ || defined i386 || defined _M_IX86 || defined __386__ || defined FORCE_DOXYGEN \
517  || defined __amd64__ || defined __AMD64__ || defined __x86_64__
518 # define POSH_CPU_X86
519 # if defined __x86_64__ || defined FORCE_DOXYGEN || defined __amd64__ || defined __AMD64__
520 # define POSH_CPU_X86_64
521 # endif
522 # if !defined FORCE_DOXYGEN
523 # if defined POSH_CPU_X86_64
524 # define POSH_CPU_STRING "AMD x86-64"
525 # else
526 # define POSH_CPU_STRING "Intel 386+"
527 # endif
528 # endif
529 #endif
530 
531 /* ------------------------------------------------------------------
532 ** IBM S/390
533 ** ------------------------------------------------------------------
534 */
535 #if defined __s390__ || defined FORCE_DOXYGEN
536 # define POSH_CPU_S390
537 # if !defined FORCE_DOXYGEN
538 # define POSH_CPU_STRING "S/390"
539 # endif
540 #endif
541 
542 /* ------------------------------------------------------------------
543 ** DEC/Compaq Alpha
544 ** ------------------------------------------------------------------
545 */
546 #if defined __alpha || defined alpha || defined _M_ALPHA || defined __alpha__ || defined FORCE_DOXYGEN
547 # define POSH_CPU_AXP
548 # if !defined FORCE_DOXYGEN
549 # define POSH_CPU_STRING "AXP"
550 # endif
551 #endif
552 
553 /* ------------------------------------------------------------------
554 ** HP PA-RISC
555 ** ------------------------------------------------------------------
556 */
557 #if defined __hppa || defined hppa || defined FORCE_DOXYGEN
558 # define POSH_CPU_HPPA
559 # if !defined FORCE_DOXYGEN
560 # define POSH_CPU_STRING "PA-RISC"
561 # endif
562 #endif
563 
566 #if !defined POSH_CPU_STRING
567 # error POSH cannot determine target CPU
568 #endif
569 
570 /* Attempt to autodetect building for embedded on Sony PS2 */
571 #if (!defined POSH_OS_STRING) || defined FORCE_DOXYGEN
572 # define POSH_OS_EMBEDDED
573 # if !defined FORCE_DOXYGEN
574 # if defined _R5900
575 # define POSH_OS_STRING "Sony PS2(embedded)"
576 # elif !defined
577 # define POSH_OS_STRING "Embedded/Unknown"
578 # endif
579 # endif
580 #endif
581 
582 /* ---------------------------------------------------------------------------
583 ** Handle cdecl, stdcall, fastcall, etc.
584 ** ---------------------------------------------------------------------------
585 */
634 #if !defined FORCE_DOXYGEN && (defined _MSC_VER || defined __WATCOMC__ || defined __GNUC__ || defined __BORLANDC__ \
635  || defined __MWERKS__)
636 # define POSH_CDECL __cdecl
637 # define POSH_STDCALL __stdcall
638 # define POSH_FASTCALL __fastcall
639 #else
640 # define POSH_CDECL
641 # define POSH_STDCALL
642 # define POSH_FASTCALL
643 #endif
644 
645 /* ---------------------------------------------------------------------------
646 ** Define POSH_IMPORTEXPORT signature based on POSH_DLL and POSH_BUILDING_LIB
647 ** ---------------------------------------------------------------------------
648 */
690 /*
691 ** We undefine this so that multiple inclusions will work
692 */
693 #if defined POSH_IMPORTEXPORT
694 # undef POSH_IMPORTEXPORT
695 #endif
696 
697 #if defined POSH_DLL
698 # if defined POSH_OS_WIN32
699 # if defined _MSC_VER
700 # if (_MSC_VER >= 800)
701 # if defined POSH_BUILDING_LIB
702 # define POSH_IMPORTEXPORT __declspec( dllexport )
703 # else
704 # define POSH_IMPORTEXPORT __declspec( dllimport )
705 # endif
706 # else
707 # if defined POSH_BUILDING_LIB
708 # define POSH_IMPORTEXPORT __export
709 # else
710 # define POSH_IMPORTEXPORT
711 # endif
712 # endif
713 # endif /* defined _MSC_VER */
714 # if defined __BORLANDC__
715 # if (__BORLANDC__ >= 0x500)
716 # if defined POSH_BUILDING_LIB
717 # define POSH_IMPORTEXPORT __declspec( dllexport )
718 # else
719 # define POSH_IMPORTEXPORT __declspec( dllimport )
720 # endif
721 # else
722 # if defined POSH_BUILDING_LIB
723 # define POSH_IMPORTEXPORT __export
724 # else
725 # define POSH_IMPORTEXPORT
726 # endif
727 # endif
728 # endif /* defined __BORLANDC__ */
729 /* for all other compilers, we're just making a blanket assumption */
730 # if defined __GNUC__ || defined __WATCOMC__ || defined __MWERKS__
731 # if defined POSH_BUILDING_LIB
732 # define POSH_IMPORTEXPORT __declspec( dllexport )
733 # else
734 # define POSH_IMPORTEXPORT __declspec( dllimport )
735 # endif
736 # endif /* all other compilers */
737 # if !defined POSH_IMPORTEXPORT
738 # error Building DLLs not supported on this compiler (poshlib@poshlib.org if you know how)
739 # endif
740 # endif /* defined POSH_OS_WIN32 */
741 #endif /* defined POSH_DLL */
742 
743 /* On pretty much everything else, we can thankfully just ignore this */
744 #if !defined POSH_IMPORTEXPORT
745 # define POSH_IMPORTEXPORT
746 #endif
747 
748 #if defined FORCE_DOXYGEN
749 # define POSH_DLL
750 # define POSH_BUILDING_LIB
751 #endif
752 
753 /* ----------------------------------------------------------------------------
754 ** (Re)define POSH_PUBLIC_API export signature
755 ** ----------------------------------------------------------------------------
756 */
757 #ifdef POSH_PUBLIC_API
758 # undef POSH_PUBLIC_API
759 #endif
760 
761 #if ( ( defined _MSC_VER) && (_MSC_VER < 800 ) ) || (defined __BORLANDC__ && (__BORLANDC__ < 0x500 ) )
762 # define POSH_PUBLIC_API( rtype ) extern rtype POSH_IMPORTEXPORT
763 #else
764 # define POSH_PUBLIC_API( rtype ) extern POSH_IMPORTEXPORT rtype
765 #endif
766 
784 /* ----------------------------------------------------------------------------
785 ** Try to infer endianess. Basically we just go through the CPUs we know are
786 ** little endian, and assume anything that isn't one of those is big endian.
787 ** As a sanity check, we also do this with operating systems we know are
788 ** little endian, such as Windows. Some processors are bi-endian, such as
789 ** the MIPS series, so we have to be careful about those.
790 ** ----------------------------------------------------------------------------
791 */
796 #if defined FORCE_DOXYGEN
797 # define POSH_LITTLE_ENDIAN
798 # define POSH_BIG_ENDIAN
799 #elif defined POSH_CPU_X86 || defined POSH_CPU_AXP || defined POSH_CPU_STRONGARM || defined POSH_OS_WIN32 \
800  || defined POSH_OS_WINCE || defined __MIPSEL__
801 # define POSH_LITTLE_ENDIAN 1
802 # define POSH_ENDIAN_STRING "little"
803 #else
804 # define POSH_BIG_ENDIAN 1
805 # define POSH_ENDIAN_STRING "big"
806 #endif
807 
818 /* ----------------------------------------------------------------------------
819 ** Cross-platform compile time assertion macro
820 ** ----------------------------------------------------------------------------
821 */
822 #if defined FORCE_DOXYGEN
823 # define POSH_COMPILE_TIME_ASSERT( name, x )
824 #else
825 # define POSH_COMPILE_TIME_ASSERT( name, x ) typedef int _POSH_dummy_##name[(x) ? 1 : -1]
826 #endif
827 
833 /* ----------------------------------------------------------------------------
834 ** 64-bit Integer
835 **
836 ** We don't require its presence, nor do we emulate its functionality, we
837 ** simply export it if it's available.
838 ** ----------------------------------------------------------------------------
839 */
843 #if defined FORCE_DOXYGEN
844 # define POSH_64BIT_INTEGER
845 typedef struct compiler_specific posh_i64_t;
846 typedef struct compiler_specific posh_s64_t;
847 typedef struct compiler_specific posh_u64_t;
848 # define POSH_S64( x )
849 # define POSH_U64( x )
850 #elif defined (__LP64__) || defined (__powerpc64__) || defined POSH_CPU_SPARC64
851 # define POSH_64BIT_INTEGER 1
852 typedef long posh_i64_t;
853 typedef long posh_s64_t;
854 typedef unsigned long posh_u64_t;
855 # define POSH_S64( x ) ( (posh_s64_t) x )
856 # define POSH_U64( x ) ( (posh_u64_t) x )
857 #elif defined __GNUC__ || defined __MWERKS__ || defined __SUNPRO_C || defined __SUNPRO_CC || defined __APPLE_CC__ \
858  || defined POSH_OS_IRIX || defined _LONG_LONG || defined _CRAYC
859 # define POSH_64BIT_INTEGER 1
860 typedef long long posh_i64_t;
861 typedef long long posh_s64_t;
862 typedef unsigned long long posh_u64_t;
863 # define POSH_U64( x ) x##LL
864 # define POSH_S64( x ) x##LL
865 #elif defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ || (defined __alpha && defined __DECC)
866 # define POSH_64BIT_INTEGER 1
867 typedef __int64 posh_i64_t;
868 typedef __int64 posh_s64_t;
869 typedef unsigned __int64 posh_u64_t;
870 # define POSH_S64( x ) ( (posh_s64_t) x )
871 # define POSH_U64( x ) ( (posh_u64_t) x )
872 #endif
873 
923 /* ----------------------------------------------------------------------------
924 ** Basic Sized Types
925 **
926 ** These types are expected to be EXACTLY sized so you can use them for
927 ** serialization.
928 ** ----------------------------------------------------------------------------
929 */
932 typedef unsigned char posh_byte_t;
933 typedef unsigned char posh_u8_t;
934 typedef signed char posh_i8_t;
935 typedef signed char posh_s8_t;
936 typedef unsigned short posh_u16_t;
937 typedef short posh_i16_t;
938 typedef short posh_s16_t;
940 #if !defined POSH_OS_PALM
941 typedef unsigned posh_u32_t;
942 typedef int posh_i32_t;
943 typedef int posh_s32_t;
944 #else
945 typedef unsigned long posh_u32_t;
946 typedef long posh_i32_t;
947 typedef long posh_s32_t;
948 #endif
949 
951 /* ----------------------------------------------------------------------------
952 ** Floating Point
953 **
954 ** The safe and portable of handling floating point across architectures that
955 ** may or may not properly spuport IEEE floating point formats is problematic
956 ** at best. Because of this, we do what we can to error out during compilation
957 ** on those platforms.
958 **
959 ** If you find that you HAVE to support such an architecture, then
960 ** define POSH_NO_FLOAT and the floating point assertions and
961 ** routines will be immediately stubbed out
962 ** ----------------------------------------------------------------------------
963 */
964 #if defined FORCE_DOXYGEN
965 # define POSH_NO_FLOAT
966 
974 # undef POSH_NO_FLOAT
975 #endif
976 
977 /* ----------------------------------------------------------------------------
978 ** Do sanity checks on expected sizes
979 ** ----------------------------------------------------------------------------
980 */
991 
992 #if !defined POSH_NO_FLOAT
993 POSH_COMPILE_TIME_ASSERT( posh_testfloat_t, sizeof (float) == 4 );
994 POSH_COMPILE_TIME_ASSERT( posh_testdouble_t, sizeof (double) == 8 );
995 #endif
996 
997 #if defined POSH_64BIT_INTEGER
998 POSH_COMPILE_TIME_ASSERT( posh_u64_t, sizeof (posh_u64_t) == 8 );
999 POSH_COMPILE_TIME_ASSERT( posh_s64_t, sizeof (posh_s64_t) == 8 );
1000 POSH_COMPILE_TIME_ASSERT( posh_i64_t, sizeof (posh_i64_t) == 8 );
1001 #endif
1002 
1003 /* ----------------------------------------------------------------------------
1004 ** 64-bit pointer support
1005 **
1006 ** NOTE: Just because a pointer is 64-bits does NOT mean that you have a
1007 ** a 64-bit address space. In practice on most platforms this may be true,
1008 ** but on some platforms, such as the Cray vector processors, this is not
1009 ** the case. Similarly, 32-bit pointers do not necessarily mean 32-bit
1010 ** address spaces, such as on early 68K processors that had 24-bit address
1011 ** space.
1012 ** ----------------------------------------------------------------------------
1013 */
1014 #if defined FORCE_DOXYGEN
1015 
1021 # define POSH_64BIT_POINTER
1022 
1023 #endif /* defined FORCE_DOXYGEN */
1024 
1025 #if defined POSH_CPU_AXP && (defined POSH_OS_TRU64 || defined POSH_OS_LINUX || defined __FreeBSD__)
1026 # define POSH_64BIT_POINTER 1
1027 #endif
1028 
1029 #if defined POSH_CPU_X86_64 && defined POSH_OS_LINUX
1030 # define POSH_64BIT_POINTER 1
1031 #endif
1032 
1033 #if defined POSH_CPU_SPARC64 || defined POSH_OS_WIN64 || defined __64BIT__ || defined __LP64 || defined _LP64 \
1034  || defined __LP64__ || defined _ADDR64 || defined _CRAYC
1035 # define POSH_64BIT_POINTER 1
1036 #endif
1037 
1038 #if defined POSH_64BIT_POINTER
1039 POSH_COMPILE_TIME_ASSERT( posh_64bit_pointer, sizeof (void*) == 8 );
1040 #else
1041 /* if this assertion is hit then you're on a system that either has 64-bit
1042  * addressing and we didn't catch it, or you're on a system with 16-bit
1043  * pointers. In the latter case, POSH doesn't actually care, we're just
1044  * triggering this assertion to make sure you're aware of the situation,
1045  * so feel free to just delete the following line.
1046  *
1047  * If this assertion is triggered on a known 32 or 64-bit architecture,
1048  * please let us know (poshlib@poshlib.org) */
1049 POSH_COMPILE_TIME_ASSERT( posh_32bit_pointer, sizeof (void*) == 4 );
1050 #endif
1051 
1052 /* ----------------------------------------------------------------------------
1053 ** POSH Utility Functions
1054 **
1055 ** These are optional POSH utility functions that are not required if you don't
1056 ** need anything except static checking of your host and target environment.
1057 **
1058 ** These functions are NOT wrapped with POSH_PUBLIC_API because I didn't want
1059 ** to enforce their export if your own library is only using them internally.
1060 ** ----------------------------------------------------------------------------
1061 */
1062 
1066 extern const char * POSH_GetArchString( void );
1108 #if !defined POSH_NO_FLOAT
1109 extern posh_u32_t POSH_LittleFloatBits( float f );
1110 extern posh_u32_t POSH_BigFloatBits( float f );
1111 extern float POSH_FloatFromLittleBits( posh_u32_t bits );
1112 extern float POSH_FloatFromBigBits( posh_u32_t bits );
1113 
1114 extern void POSH_DoubleBits( double d, posh_byte_t dst[8] );
1115 extern double POSH_DoubleFromBits( const posh_byte_t src[8] );
1116 
1117 extern float * POSH_WriteFloatToLittle( void *dst, float f );
1118 extern float * POSH_WriteFloatToBig( void *dst, float f );
1119 extern float POSH_ReadFloatFromLittle( const void *src );
1120 extern float POSH_ReadFloatFromBig( const void *src );
1121 
1122 extern double * POSH_WriteDoubleToLittle( void *dst, double d );
1123 extern double * POSH_WriteDoubleToBig( void *dst, double d );
1124 extern double POSH_ReadDoubleFromLittle( const void *src );
1125 extern double POSH_ReadDoubleFromBig( const void *src );
1126 #endif /* !defined POSH_NO_FLOAT */
1127 
1137 extern posh_u16_t POSH_SwapU16( posh_u16_t u );
1138 extern posh_s16_t POSH_SwapS16( posh_s16_t u );
1139 
1140 extern posh_u32_t POSH_SwapU32( posh_u32_t u );
1141 extern posh_s32_t POSH_SwapS32( posh_s32_t u );
1142 
1145 /* These aren't in the byte swapping group, but are in the (optional)
1146  * 64-bit support group */
1147 #if defined POSH_64BIT_INTEGER
1148 
1149 extern posh_u64_t POSH_SwapU64( posh_u64_t u );
1150 extern posh_s64_t POSH_SwapS64( posh_s64_t u );
1151 
1152 #endif /* defined POSH_64BIT_INTEGER */
1153 
1182 extern posh_u16_t * POSH_WriteU16ToLittle( void *dst, posh_u16_t value );
1183 extern posh_s16_t * POSH_WriteS16ToLittle( void *dst, posh_s16_t value );
1184 extern posh_u32_t * POSH_WriteU32ToLittle( void *dst, posh_u32_t value );
1185 extern posh_s32_t * POSH_WriteS32ToLittle( void *dst, posh_s32_t value );
1186 
1187 extern posh_u16_t * POSH_WriteU16ToBig( void *dst, posh_u16_t value );
1188 extern posh_s16_t * POSH_WriteS16ToBig( void *dst, posh_s16_t value );
1189 extern posh_u32_t * POSH_WriteU32ToBig( void *dst, posh_u32_t value );
1190 extern posh_s32_t * POSH_WriteS32ToBig( void *dst, posh_s32_t value );
1191 
1192 extern posh_u16_t POSH_ReadU16FromLittle( const void *src );
1193 extern posh_s16_t POSH_ReadS16FromLittle( const void *src );
1194 extern posh_u32_t POSH_ReadU32FromLittle( const void *src );
1195 extern posh_s32_t POSH_ReadS32FromLittle( const void *src );
1196 
1197 extern posh_u16_t POSH_ReadU16FromBig( const void *src );
1198 extern posh_s16_t POSH_ReadS16FromBig( const void *src );
1199 extern posh_u32_t POSH_ReadU32FromBig( const void *src );
1200 extern posh_s32_t POSH_ReadS32FromBig( const void *src );
1201 
1204 #if defined POSH_64BIT_INTEGER
1205 extern posh_u64_t * POSH_WriteU64ToLittle( void *dst, posh_u64_t value );
1206 extern posh_s64_t * POSH_WriteS64ToLittle( void *dst, posh_s64_t value );
1207 extern posh_u64_t * POSH_WriteU64ToBig( void *dst, posh_u64_t value );
1208 extern posh_s64_t * POSH_WriteS64ToBig( void *dst, posh_s64_t value );
1209 
1210 extern posh_u64_t POSH_ReadU64FromLittle( const void *src );
1211 extern posh_s64_t POSH_ReadS64FromLittle( const void *src );
1212 extern posh_u64_t POSH_ReadU64FromBig( const void *src );
1213 extern posh_s64_t POSH_ReadS64FromBig( const void *src );
1214 #endif /* POSH_64BIT_INTEGER */
1215 
1222 #if defined FORCE_DOXYGEN
1223 
1224 #define POSH_LittleU16( x )
1225 #define POSH_LittleU32( x )
1226 #define POSH_LittleU64( x )
1227 #define POSH_LittleS16( x )
1228 #define POSH_LittleS32( x )
1229 #define POSH_LittleS64( x )
1231 #define POSH_BigU16( x )
1232 #define POSH_BigU32( x )
1233 #define POSH_BigU64( x )
1234 #define POSH_BigS16( x )
1235 #define POSH_BigS32( x )
1236 #define POSH_BigS64( x )
1238 #elif defined POSH_LITTLE_ENDIAN
1239 
1240 #define POSH_LittleU16( x ) (x)
1241 #define POSH_LittleU32( x ) (x)
1242 #define POSH_LittleS16( x ) (x)
1243 #define POSH_LittleS32( x ) (x)
1244 #if defined POSH_64BIT_INTEGER
1245 # define POSH_LittleU64( x ) (x)
1246 # define POSH_LittleS64( x ) (x)
1247 #endif /* defined POSH_64BIT_INTEGER */
1248 
1249 #define POSH_BigU16( x ) POSH_SwapU16( x )
1250 #define POSH_BigU32( x ) POSH_SwapU32( x )
1251 #define POSH_BigS16( x ) POSH_SwapS16( x )
1252 #define POSH_BigS32( x ) POSH_SwapS32( x )
1253 #if defined POSH_64BIT_INTEGER
1254 # define POSH_BigU64( x ) POSH_SwapU64( x )
1255 # define POSH_BigS64( x ) POSH_SwapS64( x )
1256 #endif /* defined POSH_64BIT_INTEGER */
1257 
1258 #else
1259 
1260 #define POSH_BigU16( x ) (x)
1261 #define POSH_BigU32( x ) (x)
1262 #define POSH_BigS16( x ) (x)
1263 #define POSH_BigS32( x ) (x)
1264 
1265 #if defined POSH_64BIT_INTEGER
1266 # define POSH_BigU64( x ) (x)
1267 # define POSH_BigS64( x ) (x)
1268 #endif /* POSH_64BIT_INTEGER */
1269 
1270 #define POSH_LittleU16( x ) POSH_SwapU16( x )
1271 #define POSH_LittleU32( x ) POSH_SwapU32( x )
1272 #define POSH_LittleS16( x ) POSH_SwapS16( x )
1273 #define POSH_LittleS32( x ) POSH_SwapS32( x )
1274 
1275 #if defined POSH_64BIT_INTEGER
1276 # define POSH_LittleU64( x ) POSH_SwapU64( x )
1277 # define POSH_LittleS64( x ) POSH_SwapS64( x )
1278 #endif /* POSH_64BIT_INTEGER */
1279 
1280 #endif
1281