stddef.h: centralize definition of offsetof()
Move to sys/_offsetof.h and use __builtin_offsetof() instead of __offsetof to avoid reintroducing sys/cdefs.h polution in stddef.h. This has the side effect of allowing sys/stddef.h to be included after stddef.h which can happen in compatability headers. Effort: CHERI upstreaming Sponsored by: DARPA, AFRL Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D55307
This commit is contained in:
+1
-4
@@ -33,6 +33,7 @@
|
||||
#define _STDDEF_H_
|
||||
|
||||
#include <sys/_null.h>
|
||||
#include <sys/_offsetof.h>
|
||||
#include <sys/_types.h>
|
||||
#include <sys/_visible.h>
|
||||
|
||||
@@ -68,10 +69,6 @@ typedef __max_align_t max_align_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, field) __builtin_offsetof(type, field)
|
||||
#endif
|
||||
|
||||
#if __EXT1_VISIBLE
|
||||
/* ISO/IEC 9899:2011 K.3.3.2 */
|
||||
#ifndef _RSIZE_T_DEFINED
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Capabilities Limited
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This software was developed by SRI International, the University of
|
||||
* Cambridge Computer Laboratory (Department of Computer Science and
|
||||
* Technology), and Capabilities Limited under Defense Advanced Research
|
||||
* Projects Agency / Air Force Research Laboratory (DARPA/AFRL) Contract
|
||||
* No. FA8750-24-C-B047 ("DEC").
|
||||
*/
|
||||
#ifndef _SYS__OFFSETOF_H_
|
||||
#define _SYS__OFFSETOF_H_
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, field) __builtin_offsetof(type, field)
|
||||
#endif
|
||||
|
||||
#endif /* _SYS__OFFSETOF_H_ */
|
||||
+1
-2
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/_null.h>
|
||||
#include <sys/_offsetof.h>
|
||||
#include <sys/_types.h>
|
||||
#include <sys/_visible.h>
|
||||
|
||||
@@ -46,6 +47,4 @@ typedef __ptrdiff_t ptrdiff_t;
|
||||
#define _PTRDIFF_T_DECLARED
|
||||
#endif
|
||||
|
||||
#define offsetof(type, field) __offsetof(type, field)
|
||||
|
||||
#endif /* !_SYS_STDDEF_H_ */
|
||||
|
||||
Reference in New Issue
Block a user