]> mj.ucw.cz Git - pciutils.git/blob - lib/sysdep.h
a599686efced00a4c53ef2dacd7610d963627023
[pciutils.git] / lib / sysdep.h
1 /*
2  *      The PCI Library -- System-Dependent Stuff
3  *
4  *      Copyright (c) 1997--2004 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 #else
13 #define UNUSED
14 #define NONRET
15 #define inline
16 #endif
17
18 #ifdef PCI_OS_WINDOWS
19 #define bzero(x,y) memset(x,0,y)
20 #define strcasecmp strcmpi
21 #endif
22
23 #ifdef PCI_HAVE_LINUX_BYTEORDER_H
24
25 #include <asm/byteorder.h>
26 #define cpu_to_le16 __cpu_to_le16
27 #define cpu_to_le32 __cpu_to_le32
28 #define le16_to_cpu __le16_to_cpu
29 #define le32_to_cpu __le32_to_cpu
30
31 #else
32
33 #ifdef PCI_OS_LINUX
34 #include <endian.h>
35 #define BYTE_ORDER __BYTE_ORDER
36 #define BIG_ENDIAN __BIG_ENDIAN
37 #endif
38
39 #ifdef PCI_OS_SUNOS
40 #include <sys/byteorder.h>
41 #define BIG_ENDIAN 4321
42 #ifdef _LITTLE_ENDIAN
43 #define BYTE_ORDER 1234
44 #else
45 #define BYTE_ORDER 4321
46 #endif
47 #endif
48
49 #ifdef PCI_OS_WINDOWS
50 #ifdef __MINGW32__
51   #include <sys/param.h>
52 #else
53   #include <io.h>
54   #define BIG_ENDIAN 4321
55   #define LITTLE_ENDIAN 1234
56   #define BYTE_ORDER LITTLE_ENDIAN
57   #define snprintf _snprintf
58 #endif
59 #endif
60
61 #if BYTE_ORDER == BIG_ENDIAN
62 #define cpu_to_le16 swab16
63 #define cpu_to_le32 swab32
64 #define le16_to_cpu swab16
65 #define le32_to_cpu swab32
66
67 static inline word swab16(word w)
68 {
69   return (w << 8) | ((w >> 8) & 0xff);
70 }
71
72 static inline u32 swab32(u32 w)
73 {
74   return ((w & 0xff000000) >> 24) |
75          ((w & 0x00ff0000) >> 8) |
76          ((w & 0x0000ff00) << 8)  |
77          ((w & 0x000000ff) << 24);
78 }
79 #else
80 #define cpu_to_le16(x) (x)
81 #define cpu_to_le32(x) (x)
82 #define le16_to_cpu(x) (x)
83 #define le32_to_cpu(x) (x)
84 #endif
85
86 #endif