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