fgms 0.11.8
The
FlightGear MultiPlayer Server
project
stdint.hxx
Go to the documentation of this file.
1 
2 #ifndef _STDINT_HXX
3 #define _STDINT_HXX 1
4 
5 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // Written by Curtis Olson - http://www.flightgear.org/~curt
8 // Started September 2001.
9 //
10 // This file is in the Public Domain, and comes with no warranty.
11 //
12 // $Id: stdint.hxx,v 1.1.1.1 2007/06/12 10:10:24 oliver Exp $
13 
14 
15 //////////////////////////////////////////////////////////////////////
16 //
17 // There are many sick systems out there:
18 //
19 // check for sizeof(float) and sizeof(double)
20 // if sizeof(float) != 4 this code must be patched
21 // if sizeof(double) != 8 this code must be patched
22 //
23 // Those are comments I fetched out of glibc source:
24 // - s390 is big-endian
25 // - Sparc is big-endian, but v9 supports endian conversion
26 // on loads/stores and GCC supports such a mode. Be prepared.
27 // - The MIPS architecture has selectable endianness.
28 // - x86_64 is little-endian.
29 // - CRIS is little-endian.
30 // - m68k is big-endian.
31 // - Alpha is little-endian.
32 // - PowerPC can be little or big endian.
33 // - SH is bi-endian but with a big-endian FPU.
34 // - hppa1.1 big-endian.
35 // - ARM is (usually) little-endian but with a big-endian FPU.
36 //
37 //////////////////////////////////////////////////////////////////////
38 
39 
40 #ifdef _MSC_VER
41 typedef signed char int8_t;
42 typedef signed short int16_t;
43 typedef signed int int32_t;
44 typedef signed __int64 int64_t;
45 typedef unsigned char uint8_t;
46 typedef unsigned short uint16_t;
47 typedef unsigned int uint32_t;
48 typedef unsigned __int64 uint64_t;
49 
50 typedef int ssize_t;
51 #elif defined(sgi) || defined(__sun)
52 # include <sys/types.h>
53 #else
54 # include <stdint.h>
55 #endif
56 
57 
58 inline uint16_t sg_bswap_16(uint16_t x) {
59  x = (x >> 8) | (x << 8);
60  return x;
61 }
62 
63 inline uint32_t sg_bswap_32(uint32_t x) {
64  x = ((x >> 8) & 0x00FF00FFL) | ((x << 8) & 0xFF00FF00L);
65  x = (x >> 16) | (x << 16);
66  return x;
67 }
68 
69 inline uint64_t sg_bswap_64(uint64_t x) {
70  x = ((x >> 8) & 0x00FF00FF00FF00FFLL) | ((x << 8) & 0xFF00FF00FF00FF00LL);
71  x = ((x >> 16) & 0x0000FFFF0000FFFFLL) | ((x << 16) & 0xFFFF0000FFFF0000LL);
72  x = (x >> 32) | (x << 32);
73  return x;
74 }
75 
76 
77 inline bool sgIsLittleEndian() {
78  static const int sgEndianTest = 1;
79  return (*((char *) &sgEndianTest ) != 0);
80 }
81 
82 inline bool sgIsBigEndian() {
83  static const int sgEndianTest = 1;
84  return (*((char *) &sgEndianTest ) == 0);
85 }
86 
87 inline void sgEndianSwap(uint16_t *x) { *x = sg_bswap_16(*x); }
88 inline void sgEndianSwap(uint32_t *x) { *x = sg_bswap_32(*x); }
89 inline void sgEndianSwap(uint64_t *x) { *x = sg_bswap_64(*x); }
90 
91 
92 
93 #endif // !_STDINT_HXX
94 
uint16_t sg_bswap_16(uint16_t x)
Definition: stdint.hxx:58
void sgEndianSwap(uint16_t *x)
Definition: stdint.hxx:87
uint64_t sg_bswap_64(uint64_t x)
Definition: stdint.hxx:69
bool sgIsLittleEndian()
Definition: stdint.hxx:77
bool sgIsBigEndian()
Definition: stdint.hxx:82
uint32_t sg_bswap_32(uint32_t x)
Definition: stdint.hxx:63