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