From 7eb805f68dc06101274b13f7c0e1aeeaf0a787a4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 16 Apr 2013 10:25:16 +0000 Subject: * libc/sys/rtems/sys/queue.h: Delete file. * libc/include/sys/cdefs.h (__containerof): New define. (__DEQUALIFY): Likewise. * libc/include/sys/queue.h (TRACEBUF_INITIALIZER): Likewise. (TRACEBUF): Likewise. (LIST_FOREACH_SAFE): Likewise. (LIST_PREV): Likewise. (LIST_SWAP): Likewise. (QMD_LIST_CHECK_HEAD): Likewise. (QMD_LIST_CHECK_NEXT): Likewise. (QMD_LIST_CHECK_PREV): Likewise. (QMD_SAVELINK): Likewise. (QMD_TAILQ_CHECK_HEAD): Likewise. (QMD_TAILQ_CHECK_NEXT): Likewise. (QMD_TAILQ_CHECK_PREV): Likewise. (QMD_TAILQ_CHECK_TAIL): Likewise. (QMD_TRACE_ELEM): Likewise. (QMD_TRACE_HEAD): Likewise. (SLIST_FOREACH_PREVPTR): Likewise. (SLIST_FOREACH_SAFE): Likewise. (SLIST_REMOVE_AFTER): Likewise. (SLIST_SWAP): Likewise. (STAILQ_FOREACH_SAFE): Likewise. (STAILQ_REMOVE_AFTER): Likewise. (STAILQ_SWAP): Likewise. (TAILQ_FOREACH_REVERSE_SAFE): Likewise. (TAILQ_FOREACH_SAFE): Likewise. (TAILQ_SWAP): Likewise. (TRASHIT): Likewise. (SLIST_REMOVE): Use SLIST_REMOVE_AFTER(). (STAILQ_LAST): Use __containerof(). (STAILQ_REMOVE): Use STAILQ_REMOVE_AFTER(). --- newlib/libc/include/sys/cdefs.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'newlib/libc/include/sys/cdefs.h') diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index e3298efaf..253258aa8 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -44,6 +44,10 @@ #ifndef _SYS_CDEFS_H #define _SYS_CDEFS_H +#include +#include +#include + #define __FBSDID(x) /* nothing */ /* * Note: the goal here is not compatibility to K&R C. Since we know that we @@ -101,6 +105,26 @@ # define __ptrvalue /* nothing */ #endif +/* + * Given the pointer x to the member m of the struct s, return + * a pointer to the containing structure. When using GCC, we first + * assign pointer x to a local variable, to check that its type is + * compatible with member m. + */ +#if __GNUC_PREREQ(3, 1) +#define __containerof(x, s, m) ({ \ + const volatile __typeof__(((s *)0)->m) *__x = (x); \ + __DEQUALIFY(s *, (const volatile char *)__x - offsetof(s, m));\ +}) +#else +#define __containerof(x, s, m) \ + __DEQUALIFY(s *, (const volatile char *)(x) - offsetof(s, m)) +#endif + +#ifndef __DEQUALIFY +#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) +#endif + #ifdef __GNUC__ #define __strong_reference(sym,aliassym) \ extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))); -- cgit v1.2.3