gwenhywfar  5.14.1
endianfns.h
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tuet Apr 26 2016
3  copyright : (C) 2016 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library 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 GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 #ifndef GWENHYWFAR_ENDIANFNS_H
26 #define GWENHYWFAR_ENDIANFNS_H
27 
28 #include <gwenhywfar/gwenhywfarapi.h>
29 
30 
31 #if GWENHYWFAR_SYS_IS_WINDOWS
32 /* assume little endian for now (is there any big endian Windows system??) */
33 # define GWEN_ENDIAN_LE16TOH(x) (x)
34 # define GWEN_ENDIAN_HTOLE16(x) (x)
35 
36 # define GWEN_ENDIAN_LE32TOH(x) (x)
37 # define GWEN_ENDIAN_HTOLE32(x) (x)
38 
39 # define GWEN_ENDIAN_LE64TOH(x) (x)
40 # define GWEN_ENDIAN_HTOLE64(x) (x)
41 
42 #elif defined(__APPLE__)
43 /* inspired by https://stackoverflow.com/questions/20813028/endian-h-not-found-on-mac-osx */
44 #include <libkern/OSByteOrder.h>
45 
46 #define GWEN_ENDIAN_HTOLE16(x) OSSwapHostToLittleInt16(x)
47 #define GWEN_ENDIAN_LE16TOH(x) OSSwapLittleToHostInt16(x)
48 
49 #define GWEN_ENDIAN_HTOLE32(x) OSSwapHostToLittleInt32(x)
50 #define GWEN_ENDIAN_LE32TOH(x) OSSwapLittleToHostInt32(x)
51 
52 #define GWEN_ENDIAN_HTOLE64(x) OSSwapHostToLittleInt64(x)
53 #define GWEN_ENDIAN_LE64TOH(x) OSSwapLittleToHostInt64(x)
54 
55 #define GWEN_ENDIAN_HTOBE16(x) OSSwapHostToBigInt16(x)
56 #define GWEN_ENDIAN_BE16TOH(x) OSSwapBigToHostInt16(x)
57 
58 #define GWEN_ENDIAN_HTOBE32(x) OSSwapHostToBigInt32(x)
59 #define GWEN_ENDIAN_BE32TOH(x) OSSwapBigToHostInt32(x)
60 
61 #define GWEN_ENDIAN_HTOBE64(x) OSSwapHostToBigInt64(x)
62 #define GWEN_ENDIAN_BE64TOH(x) OSSwapBigToHostInt64(x)
63 
64 #else
65 /* for Linux and others use definitions from endian.h */
66 # include <endian.h>
67 
68 # define GWEN_ENDIAN_LE16TOH(x) le16toh(x)
69 # define GWEN_ENDIAN_HTOLE16(x) htole16(x)
70 
71 # define GWEN_ENDIAN_LE32TOH(x) le32toh(x)
72 # define GWEN_ENDIAN_HTOLE32(x) htole32(x)
73 
74 # define GWEN_ENDIAN_LE64TOH(x) le64toh(x)
75 # define GWEN_ENDIAN_HTOLE64(x) htole64(x)
76 #endif
77 
78 
79 
80 
81 #endif