X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmisc%2Fstdint.hxx;h=f90734edc6eb6c49e61de814c9a425620fa0b5ce;hb=619163d40e6beeaf08759944d80256692395ec9e;hp=aba705d1c17433fed2bdc6558fbf38f38287958a;hpb=832e8219193032e1333687bd3c2aa425d02c1f21;p=simgear.git diff --git a/simgear/misc/stdint.hxx b/simgear/misc/stdint.hxx index aba705d1..f90734ed 100644 --- a/simgear/misc/stdint.hxx +++ b/simgear/misc/stdint.hxx @@ -4,20 +4,10 @@ // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. +// Written by Curtis Olson - http://www.flightgear.org/~curt +// Started September 2001. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// This file is in the Public Domain, and comes with no warranty. // // $Id$ @@ -56,27 +46,27 @@ typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; + +typedef int ssize_t; +#elif defined(sgi) || defined(__sun) +# include #else # include #endif -#include - -inline uint16_t sg_bswap_16(uint16_t b) { - unsigned short x = b; - ulEndianSwap(&x); +inline uint16_t sg_bswap_16(uint16_t x) { + x = (x >> 8) | (x << 8); return x; } -inline uint32_t sg_bswap_32(uint32_t b) { - unsigned x = b; - ulEndianSwap(&x); +inline uint32_t sg_bswap_32(uint32_t x) { + x = ((x >> 8) & 0x00FF00FFL) | ((x << 8) & 0xFF00FF00L); + x = (x >> 16) | (x << 16); return x; } -inline uint64_t sg_bswap_64(uint64_t b) { - uint64_t x = b; +inline uint64_t sg_bswap_64(uint64_t x) { x = ((x >> 8) & 0x00FF00FF00FF00FFLL) | ((x << 8) & 0xFF00FF00FF00FF00LL); x = ((x >> 16) & 0x0000FFFF0000FFFFLL) | ((x << 16) & 0xFFFF0000FFFF0000LL); x = (x >> 32) | (x << 32); @@ -94,13 +84,9 @@ inline bool sgIsBigEndian() { return (*((char *) &sgEndianTest ) == 0); } -inline void sgEndianSwap(unsigned short *x) { ulEndianSwap(x); } -inline void sgEndianSwap(unsigned int *x) { ulEndianSwap(x); } -#if (SIZEOF_LONG_INT == 8) -inline void sgEndianSwap(unsigned long int *x) { *x = sg_bswap_64(*x); } -#else -inline void sgEndianSwap(unsigned long long *x) { *x = sg_bswap_64(*x); } -#endif +inline void sgEndianSwap(uint16_t *x) { *x = sg_bswap_16(*x); } +inline void sgEndianSwap(uint32_t *x) { *x = sg_bswap_32(*x); } +inline void sgEndianSwap(uint64_t *x) { *x = sg_bswap_64(*x); }