linux-user: fix coding style nit
[armpft.git] / osdep.h
blob4b4aad4d491a39f3fecbd8869819eddacda548c5
1 #ifndef QEMU_OSDEP_H
2 #define QEMU_OSDEP_H
4 #include <stdarg.h>
5 #include <stddef.h>
6 #ifdef __OpenBSD__
7 #include <sys/types.h>
8 #include <sys/signal.h>
9 #endif
11 #ifndef _WIN32
12 #include <sys/time.h>
13 #endif
15 #ifndef glue
16 #define xglue(x, y) x ## y
17 #define glue(x, y) xglue(x, y)
18 #define stringify(s) tostring(s)
19 #define tostring(s) #s
20 #endif
22 #ifndef likely
23 #if __GNUC__ < 3
24 #define __builtin_expect(x, n) (x)
25 #endif
27 #define likely(x) __builtin_expect(!!(x), 1)
28 #define unlikely(x) __builtin_expect(!!(x), 0)
29 #endif
31 #ifdef CONFIG_NEED_OFFSETOF
32 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
33 #endif
34 #ifndef container_of
35 #define container_of(ptr, type, member) ({ \
36 const typeof(((type *) 0)->member) *__mptr = (ptr); \
37 (type *) ((char *) __mptr - offsetof(type, member));})
38 #endif
40 #define typeof_field(type, field) typeof(((type *)0)->field)
41 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
43 #ifndef MIN
44 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
45 #endif
46 #ifndef MAX
47 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
48 #endif
50 #ifndef ARRAY_SIZE
51 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
52 #endif
54 #ifndef always_inline
55 #if !((__GNUC__ < 3) || defined(__APPLE__))
56 #ifdef __OPTIMIZE__
57 #define inline __attribute__ (( always_inline )) __inline__
58 #endif
59 #endif
60 #else
61 #define inline always_inline
62 #endif
64 #ifdef __i386__
65 #define REGPARM __attribute((regparm(3)))
66 #else
67 #define REGPARM
68 #endif
70 #define qemu_printf printf
72 #if defined (__GNUC__) && defined (__GNUC_MINOR__)
73 # define QEMU_GNUC_PREREQ(maj, min) \
74 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
75 #else
76 # define QEMU_GNUC_PREREQ(maj, min) 0
77 #endif
79 void *qemu_memalign(size_t alignment, size_t size);
80 void *qemu_vmalloc(size_t size);
81 void qemu_vfree(void *ptr);
83 int qemu_create_pidfile(const char *filename);
85 #ifdef _WIN32
86 int ffs(int i);
88 typedef struct {
89 long tv_sec;
90 long tv_usec;
91 } qemu_timeval;
92 int qemu_gettimeofday(qemu_timeval *tp);
93 #else
94 typedef struct timeval qemu_timeval;
95 #define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
96 #endif /* !_WIN32 */
98 #endif