raw-posix: split hdev drivers
[qemu-kvm/fedora.git] / osdep.h
blobffbf221d7f540f3aaf2f93a3e77d6032931c77b6
1 #ifndef QEMU_OSDEP_H
2 #define QEMU_OSDEP_H
4 #include <stdarg.h>
5 #ifdef __OpenBSD__
6 #include <sys/types.h>
7 #include <sys/signal.h>
8 #endif
10 #ifndef _WIN32
11 #include <sys/time.h>
12 #endif
14 #ifndef glue
15 #define xglue(x, y) x ## y
16 #define glue(x, y) xglue(x, y)
17 #define stringify(s) tostring(s)
18 #define tostring(s) #s
19 #endif
21 #ifndef likely
22 #if __GNUC__ < 3
23 #define __builtin_expect(x, n) (x)
24 #endif
26 #define likely(x) __builtin_expect(!!(x), 1)
27 #define unlikely(x) __builtin_expect(!!(x), 0)
28 #endif
30 #ifndef offsetof
31 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
32 #endif
33 #ifndef container_of
34 #define container_of(ptr, type, member) ({ \
35 const typeof(((type *) 0)->member) *__mptr = (ptr); \
36 (type *) ((char *) __mptr - offsetof(type, member));})
37 #endif
39 #ifndef MIN
40 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
41 #endif
42 #ifndef MAX
43 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
44 #endif
46 #ifndef ARRAY_SIZE
47 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48 #endif
50 #ifndef always_inline
51 #if (__GNUC__ < 3) || defined(__APPLE__)
52 #define always_inline inline
53 #else
54 #define always_inline __attribute__ (( always_inline )) __inline__
55 #ifdef __OPTIMIZE__
56 #define inline always_inline
57 #endif
58 #endif
59 #else
60 #define inline always_inline
61 #endif
63 #ifdef __i386__
64 #define REGPARM __attribute((regparm(3)))
65 #else
66 #define REGPARM
67 #endif
69 #define qemu_printf printf
71 #if defined (__GNUC__) && defined (__GNUC_MINOR__)
72 # define QEMU_GNUC_PREREQ(maj, min) \
73 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
74 #else
75 # define QEMU_GNUC_PREREQ(maj, min) 0
76 #endif
78 void *qemu_memalign(size_t alignment, size_t size);
79 void *qemu_vmalloc(size_t size);
80 void qemu_vfree(void *ptr);
82 int qemu_create_pidfile(const char *filename);
84 #ifdef _WIN32
85 int ffs(int i);
87 typedef struct {
88 long tv_sec;
89 long tv_usec;
90 } qemu_timeval;
91 int qemu_gettimeofday(qemu_timeval *tp);
92 #else
93 typedef struct timeval qemu_timeval;
94 #define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
95 #endif /* !_WIN32 */
97 #endif