xref: /titanic_54/usr/src/uts/common/sys/stddef.h (revision 4bf09fcc5e5ab0db7ee126d7d83cbb3f7bdc605d)
1*4bf09fccSToomas Soome /*
2*4bf09fccSToomas Soome  * This file and its contents are supplied under the terms of the
3*4bf09fccSToomas Soome  * Common Development and Distribution License ("CDDL"), version 1.0.
4*4bf09fccSToomas Soome  * You may only use this file in accordance with the terms of version
5*4bf09fccSToomas Soome  * 1.0 of the CDDL.
6*4bf09fccSToomas Soome  *
7*4bf09fccSToomas Soome  * A full copy of the text of the CDDL should have accompanied this
8*4bf09fccSToomas Soome  * source.  A copy of the CDDL is also available via the Internet at
9*4bf09fccSToomas Soome  * http://www.illumos.org/license/CDDL.
10*4bf09fccSToomas Soome  */
11*4bf09fccSToomas Soome 
12*4bf09fccSToomas Soome /*
13*4bf09fccSToomas Soome  * Copyright 2017 Toomas Soome <tsoome@me.com>
14*4bf09fccSToomas Soome  */
15*4bf09fccSToomas Soome 
16*4bf09fccSToomas Soome #ifndef _SYS_STDDEF_H
17*4bf09fccSToomas Soome #define	_SYS_STDDEF_H
18*4bf09fccSToomas Soome 
19*4bf09fccSToomas Soome /*
20*4bf09fccSToomas Soome  * Commonly used macros and definitions.
21*4bf09fccSToomas Soome  */
22*4bf09fccSToomas Soome 
23*4bf09fccSToomas Soome #ifdef __cplusplus
24*4bf09fccSToomas Soome extern "C" {
25*4bf09fccSToomas Soome #endif
26*4bf09fccSToomas Soome 
27*4bf09fccSToomas Soome #if !defined(offsetof)
28*4bf09fccSToomas Soome #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
29*4bf09fccSToomas Soome #define	offsetof(s, m)	__builtin_offsetof(s, m)
30*4bf09fccSToomas Soome #else
31*4bf09fccSToomas Soome #if __cplusplus >= 199711L
32*4bf09fccSToomas Soome #define	offsetof(s, m)	(std::size_t)(&(((s *)NULL)->m))
33*4bf09fccSToomas Soome #else
34*4bf09fccSToomas Soome #define	offsetof(s, m)	((size_t)(&(((s *)NULL)->m)))
35*4bf09fccSToomas Soome #endif
36*4bf09fccSToomas Soome #endif
37*4bf09fccSToomas Soome #endif /* !offsetof */
38*4bf09fccSToomas Soome 
39*4bf09fccSToomas Soome #if !defined(container_of)
40*4bf09fccSToomas Soome #define	container_of(m, s, name)			\
41*4bf09fccSToomas Soome 	(void *)((uintptr_t)(m) - (uintptr_t)offsetof(s, name))
42*4bf09fccSToomas Soome #endif /* !container_of */
43*4bf09fccSToomas Soome 
44*4bf09fccSToomas Soome #ifdef __cplusplus
45*4bf09fccSToomas Soome }
46*4bf09fccSToomas Soome #endif
47*4bf09fccSToomas Soome 
48*4bf09fccSToomas Soome #endif /* _SYS_STDDEF_H */
49