Commit ac509d88877c07bb06497206d74a2baa25b6d895

Authored by balrog
1 parent 2acf5af0

Move offsetof to osdep.h, remove local defintions.

With this container_of can actually be used without causing build errors.
Reformat container_of.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5234 c046a42c-6fe2-441c-8c8c-71466251a162
block-qcow2.c
... ... @@ -61,10 +61,6 @@
61 61  
62 62 #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */
63 63  
64   -#ifndef offsetof
65   -#define offsetof(type, field) ((size_t) &((type *)0)->field)
66   -#endif
67   -
68 64 typedef struct QCowHeader {
69 65 uint32_t magic;
70 66 uint32_t version;
... ...
exec-all.h
... ... @@ -256,10 +256,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
256 256  
257 257 TranslationBlock *tb_find_pc(unsigned long pc_ptr);
258 258  
259   -#ifndef offsetof
260   -#define offsetof(type, field) ((size_t) &((type *)0)->field)
261   -#endif
262   -
263 259 #if defined(_WIN32)
264 260 #define ASM_DATA_SECTION ".section \".data\"\n"
265 261 #define ASM_PREVIOUS_SECTION ".section .text\n"
... ...
linux-user/signal.c
... ... @@ -549,10 +549,6 @@ int do_sigaction(int sig, const struct target_sigaction *act,
549 549 return ret;
550 550 }
551 551  
552   -#ifndef offsetof
553   -#define offsetof(type, field) ((size_t) &((type *)0)->field)
554   -#endif
555   -
556 552 static inline int copy_siginfo_to_user(target_siginfo_t *tinfo,
557 553 const target_siginfo_t *info)
558 554 {
... ...
monitor.c
... ... @@ -40,10 +40,6 @@
40 40 //#define DEBUG
41 41 //#define DEBUG_COMPLETION
42 42  
43   -#ifndef offsetof
44   -#define offsetof(type, field) ((size_t) &((type *)0)->field)
45   -#endif
46   -
47 43 /*
48 44 * Supported types:
49 45 *
... ...
... ... @@ -23,9 +23,14 @@
23 23 #define unlikely(x) __builtin_expect(!!(x), 0)
24 24 #endif
25 25  
  26 +#ifndef offsetof
  27 +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
  28 +#endif
  29 +#ifndef container_of
26 30 #define container_of(ptr, type, member) ({ \
27   - const typeof( ((type *)0)->member ) *__mptr = (ptr); \
28   - (type *)( (char *)__mptr - offsetof(type,member) );})
  31 + const typeof(((type *) 0)->member) *__mptr = (ptr); \
  32 + (type *) ((char *) __mptr - offsetof(type, member));})
  33 +#endif
29 34  
30 35 #ifndef MIN
31 36 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
... ...