block: add enable_write_cache flag
[qemu/kevin.git] / osdep.h
blob32ee94b5ad48892eced2158f4c5b3d3ff5d53cb7
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 #define typeof_field(type, field) typeof(((type *)0)->field)
40 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
42 #ifndef MIN
43 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
44 #endif
45 #ifndef MAX
46 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
47 #endif
49 #ifndef ARRAY_SIZE
50 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
51 #endif
53 #ifndef always_inline
54 #if !((__GNUC__ < 3) || defined(__APPLE__))
55 #ifdef __OPTIMIZE__
56 #define inline __attribute__ (( always_inline )) __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