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