]> mj.ucw.cz Git - pciutils.git/blob - lib/sysdep.h
Merge branch 'amiga'
[pciutils.git] / lib / sysdep.h
1 /*
2  *      The PCI Library -- System-Dependent Stuff
3  *
4  *      Copyright (c) 1997--2020 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifdef __GNUC__
12 #define UNUSED __attribute__((unused))
13 #define NONRET __attribute__((noreturn))
14 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
15 #else
16 #define UNUSED
17 #define NONRET
18 #define FORMAT_CHECK(x,y,z)
19 #define inline
20 #endif
21
22 typedef u8 byte;
23 typedef u16 word;
24
25 #ifdef PCI_OS_WINDOWS
26 #define strcasecmp _strcmpi
27 #define strncasecmp _strnicmp
28 #if defined(_MSC_VER) && _MSC_VER < 1800
29 #if _MSC_VER < 1300
30 #define strtoull strtoul
31 #else
32 #define strtoull _strtoui64
33 #endif
34 #endif
35 #if defined(_MSC_VER) && _MSC_VER < 1900
36 #define snprintf _snprintf
37 #define vsnprintf _vsnprintf
38 #endif
39 #endif
40
41 #ifdef PCI_HAVE_LINUX_BYTEORDER_H
42
43 #include <asm/byteorder.h>
44 #define cpu_to_le16 __cpu_to_le16
45 #define cpu_to_le32 __cpu_to_le32
46 #define le16_to_cpu __le16_to_cpu
47 #define le32_to_cpu __le32_to_cpu
48
49 #else
50
51 #ifdef PCI_OS_LINUX
52 #include <endian.h>
53 #define BYTE_ORDER __BYTE_ORDER
54 #define BIG_ENDIAN __BIG_ENDIAN
55 #endif
56
57 #ifdef PCI_OS_SUNOS
58 #include <sys/byteorder.h>
59 #if defined(__i386) && defined(LITTLE_ENDIAN)
60 # define BYTE_ORDER LITTLE_ENDIAN
61 #elif defined(__sparc) && defined(BIG_ENDIAN)
62 # define BYTE_ORDER BIG_ENDIAN
63 #else
64 #define BIG_ENDIAN 4321
65 #endif
66 #ifndef BYTE_ORDER
67 #ifdef _LITTLE_ENDIAN
68 #define BYTE_ORDER 1234
69 #else
70 #define BYTE_ORDER 4321
71 #endif
72 #endif /* BYTE_ORDER */
73 #endif /* PCI_OS_SUNOS */
74
75 #ifdef PCI_OS_WINDOWS
76 #ifdef __MINGW32__
77   #include <sys/param.h>
78 #else
79   #include <io.h>
80   #define BIG_ENDIAN 4321
81   #define LITTLE_ENDIAN 1234
82   #define BYTE_ORDER LITTLE_ENDIAN
83 #endif
84 #endif
85
86 #ifdef PCI_OS_SYLIXOS
87 #include <endian.h>
88 #endif
89
90 #ifdef PCI_OS_DJGPP
91   #define BIG_ENDIAN 4321
92   #define LITTLE_ENDIAN 1234
93   #define BYTE_ORDER LITTLE_ENDIAN
94 #endif
95
96 #ifdef PCI_OS_AMIGAOS
97   #include <machine/endian.h>
98 #endif
99
100 #if !defined(BYTE_ORDER)
101 #error "BYTE_ORDER not defined for your platform"
102 #endif
103
104 #if BYTE_ORDER == BIG_ENDIAN
105 #define cpu_to_le16 swab16
106 #define cpu_to_le32 swab32
107 #define le16_to_cpu swab16
108 #define le32_to_cpu swab32
109
110 static inline word swab16(word w)
111 {
112   return (w << 8) | ((w >> 8) & 0xff);
113 }
114
115 static inline u32 swab32(u32 w)
116 {
117   return ((w & 0xff000000) >> 24) |
118          ((w & 0x00ff0000) >> 8) |
119          ((w & 0x0000ff00) << 8)  |
120          ((w & 0x000000ff) << 24);
121 }
122 #else
123 #define cpu_to_le16(x) (x)
124 #define cpu_to_le32(x) (x)
125 #define le16_to_cpu(x) (x)
126 #define le32_to_cpu(x) (x)
127 #endif
128
129 #endif