aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-05-08 14:13:35 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-05-10 18:14:18 +0000
commitea72f6d5a8b9386a09e23fbdc933effb007ca899 (patch)
tree5a3563def161538e43e05384bf244b63a5037598
parent5e4947f7e08a90ba50f9e8cea9ae5e128717cb5f (diff)
sys/cdefs.h: move __BEGIN_DECLS/__END_DECLS into a helper sys/_decls.h
There are situations where nothing from sys/cdefs.h is needed except for the declaration braces. More, the other facilities from sys/cdefs.h might unnecessarly pollute the namespace. Reviewed by: markj, imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D56889
-rw-r--r--sys/sys/_decls.h46
-rw-r--r--sys/sys/cdefs.h8
-rw-r--r--tools/build/Makefile1
3 files changed, 48 insertions, 7 deletions
diff --git a/sys/sys/_decls.h b/sys/sys/_decls.h
new file mode 100644
index 000000000000..2ef61671dd70
--- /dev/null
+++ b/sys/sys/_decls.h
@@ -0,0 +1,46 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Berkeley Software Design, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS__DECLS_H_
+#define _SYS__DECLS_H_
+
+#if defined(__cplusplus)
+#define __BEGIN_DECLS extern "C" {
+#define __END_DECLS }
+#else
+#define __BEGIN_DECLS
+#define __END_DECLS
+#endif
+
+#endif
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index a08c50c8439a..d0a34f1bdfc0 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -61,13 +61,7 @@
#define __has_builtin(x) 0
#endif
-#if defined(__cplusplus)
-#define __BEGIN_DECLS extern "C" {
-#define __END_DECLS }
-#else
-#define __BEGIN_DECLS
-#define __END_DECLS
-#endif
+#include <sys/_decls.h>
/*
* This code has been put in place to help reduce the addition of
diff --git a/tools/build/Makefile b/tools/build/Makefile
index f0856900b281..d71cc710be87 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -360,6 +360,7 @@ DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h
.if ${.MAKE.OS} == "FreeBSD"
# Needed to build most of the things below, which include sys/cdefs.h either
# directly or transitively
+SYSINCS+= ${SRCTOP}/sys/sys/_decls.h
SYSINCS+= ${SRCTOP}/sys/sys/_visible.h
SYSINCS+= ${SRCTOP}/sys/sys/cdefs.h
.endif