]> mj.ucw.cz Git - pciutils.git/blob - lib/sysdep.h
c6c248eac740e8c7cd11c6612f1702d7feec34eb
[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.
7  */
8
9 #ifdef __GNUC__
10 #define UNUSED __attribute__((unused))
11 #define NONRET __attribute__((noreturn))
12 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
13 #else
14 #define UNUSED
15 #define NONRET
16 #define FORMAT_CHECK(x,y,z)
17 #define inline
18 #endif
19
20 typedef u8 byte;
21 typedef u16 word;
22
23 #ifdef PCI_OS_WINDOWS
24 #define strcasecmp _strcmpi
25 #endif
26
27 #ifdef PCI_HAVE_LINUX_BYTEORDER_H
28
29 #include <asm/byteorder.h>
30 #define cpu_to_le16 __cpu_to_le16
31 #define cpu_to_le32 __cpu_to_le32
32 #define le16_to_cpu __le16_to_cpu
33 #define le32_to_cpu __le32_to_cpu
34
35 #else
36
37 #ifdef PCI_OS_LINUX
38 #include <endian.h>
39 #define BYTE_ORDER __BYTE_ORDER
40 #define BIG_ENDIAN __BIG_ENDIAN
41 #endif
42
43 #ifdef PCI_OS_SUNOS
44 #include <sys/byteorder.h>
45 #if defined(__i386) && defined(LITTLE_ENDIAN)
46 # define BYTE_ORDER LITTLE_ENDIAN
47 #elif defined(__sparc) && defined(BIG_ENDIAN)
48 # define BYTE_ORDER BIG_ENDIAN
49 #else
50 #define BIG_ENDIAN 4321
51 #endif
52 #ifndef BYTE_ORDER
53 #ifdef _LITTLE_ENDIAN
54 #define BYTE_ORDER 1234
55 #else
56 #define BYTE_ORDER 4321
57 #endif
58 #endif /* BYTE_ORDER */
59 #endif /* PCI_OS_SUNOS */
60
61 #ifdef PCI_OS_WINDOWS
62 #ifdef __MINGW32__
63   #include <sys/param.h>
64 #else
65   #include <io.h>
66   #define BIG_ENDIAN 4321
67   #define LITTLE_ENDIAN 1234
68   #define BYTE_ORDER LITTLE_ENDIAN
69   #define snprintf _snprintf
70 #endif
71 #endif
72
73 #ifdef PCI_OS_SYLIXOS
74 #include <endian.h>
75 #endif
76
77 #ifdef PCI_OS_DJGPP
78   #define BIG_ENDIAN 4321
79   #define LITTLE_ENDIAN 1234
80   #define BYTE_ORDER LITTLE_ENDIAN
81 #endif
82
83 #if !defined(BYTE_ORDER)
84 #error "BYTE_ORDER not defined for your platform"
85 #endif
86
87 #if BYTE_ORDER == BIG_ENDIAN
88 #define cpu_to_le16 swab16
89 #define cpu_to_le32 swab32
90 #define le16_to_cpu swab16
91 #define le32_to_cpu swab32
92
93 static inline word swab16(word w)
94 {
95   return (w << 8) | ((w >> 8) & 0xff);
96 }
97
98 static inline u32 swab32(u32 w)
99 {
100   return ((w & 0xff000000) >> 24) |
101          ((w & 0x00ff0000) >> 8) |
102          ((w & 0x0000ff00) << 8)  |
103          ((w & 0x000000ff) << 24);
104 }
105 #else
106 #define cpu_to_le16(x) (x)
107 #define cpu_to_le32(x) (x)
108 #define le16_to_cpu(x) (x)
109 #define le32_to_cpu(x) (x)
110 #endif
111
112 #endif