bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | platform.h (14.05.13) |
| 3 | OS-specific code (libc-specific in fact). Note that systems with the |
| 4 | same kernel can use different libc implementations. |
| 5 | |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 6 | Copyright (C) 2010-2013 Andrew Nayenko |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 7 | |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 8 | This program is free software: you can redistribute it and/or modify |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 9 | it under the terms of the GNU General Public License as published by |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 10 | the Free Software Foundation, either version 3 of the License, or |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef PLATFORM_H_INCLUDED |
| 23 | #define PLATFORM_H_INCLUDED |
| 24 | |
| 25 | #if defined(__GLIBC__) |
| 26 | |
| 27 | #include <endian.h> |
| 28 | #include <byteswap.h> |
| 29 | |
| 30 | #elif defined(__APPLE__) |
| 31 | |
| 32 | #include <machine/endian.h> |
| 33 | #include <libkern/OSByteOrder.h> |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 34 | #define bswap_16(x) OSSwapInt16(x) |
| 35 | #define bswap_32(x) OSSwapInt32(x) |
| 36 | #define bswap_64(x) OSSwapInt64(x) |
| 37 | #define __BYTE_ORDER BYTE_ORDER |
| 38 | #define __LITTLE_ENDIAN LITTLE_ENDIAN |
| 39 | #define __BIG_ENDIAN BIG_ENDIAN |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 40 | |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 41 | #elif defined(__FreeBSD__) || defined(__DragonFlyBSD__) || defined(__NetBSD__) |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 42 | |
| 43 | #include <sys/endian.h> |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 44 | #define bswap_16(x) bswap16(x) |
| 45 | #define bswap_32(x) bswap32(x) |
| 46 | #define bswap_64(x) bswap64(x) |
| 47 | #define __BYTE_ORDER _BYTE_ORDER |
| 48 | #define __LITTLE_ENDIAN _LITTLE_ENDIAN |
| 49 | #define __BIG_ENDIAN _BIG_ENDIAN |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 50 | |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 51 | #elif defined(__OpenBSD__) |
| 52 | |
| 53 | #include <machine/endian.h> |
| 54 | #define bswap_16(x) swap16(x) |
| 55 | #define bswap_32(x) swap32(x) |
| 56 | #define bswap_64(x) swap64(x) |
| 57 | #define __BYTE_ORDER _BYTE_ORDER |
| 58 | #define __LITTLE_ENDIAN _LITTLE_ENDIAN |
| 59 | #define __BIG_ENDIAN _BIG_ENDIAN |
| 60 | |
| 61 | #elif defined(__sun) |
| 62 | |
| 63 | #include <sys/byteorder.h> |
| 64 | #define bswap_16(x) BSWAP_16(x) |
| 65 | #define bswap_32(x) BSWAP_32(x) |
| 66 | #define bswap_64(x) BSWAP_64(x) |
| 67 | #define __LITTLE_ENDIAN 1234 |
| 68 | #define __BIG_ENDIAN 4321 |
| 69 | #ifdef _LITTLE_ENDIAN |
| 70 | #define __BYTE_ORDER __LITTLE_ENDIAN |
| 71 | #else |
| 72 | #define __BYTE_ORDER __BIG_ENDIAN |
| 73 | #endif |
| 74 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 75 | #else |
| 76 | #error Unknown platform |
bigbiff | c40c1c5 | 2014-11-01 09:34:57 -0400 | [diff] [blame] | 77 | #endif |
| 78 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 79 | #endif /* ifndef PLATFORM_H_INCLUDED */ |