libusbgx: Add offsetof() and container_of() macros
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 14 Apr 2015 09:00:45 +0000 (11:00 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:35 +0000 (21:45 +0100)
Add some macros which are widely used in linux
kernel and may be useful also in this library.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
include/usbg/usbg_internal.h

index dbbd0dd..793319c 100644 (file)
  * @file include/usbg/usbg_internal.h
  */
 
+#ifndef offsetof
+#define offsetof(type, member)  __builtin_offsetof (type, member)
+#endif /* offsetof */
+
+#ifndef container_of
+#define container_of(ptr, type, field) ({                               \
+                        const typeof(((type *)0)->field) *member = (ptr); \
+                        (type *)( (char *)member - offsetof(type, field) ); \
+                })
+#endif /* container_of */
 
 struct usbg_state
 {