git: 4ccd5e64b76b - stable/13 - _endian.h: Include sys/cdefs.h for visibility macros

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 22 Mar 2023 22:31:38 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ccd5e64b76bbaa874c50755d17394a7ed195f93

commit 4ccd5e64b76bbaa874c50755d17394a7ed195f93
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-03-22 02:25:58 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-03-22 22:30:51 +0000

    _endian.h: Include sys/cdefs.h for visibility macros
    
    BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN will be required by the
    forthcoming POSIX Issue 8. In addition, they are provided in the BSD
    compilation environments. However, depending on the order includes
    happend, sys/cdefs.h may or may not be included when endian.h is
    included. Include it here so we can safely test __BSD_VISIBLE.  Add
    visibility when we're compiling in the future for issue 8, but since the
    date number for issue 8 hasn't been fixed, use strictly greater than the
    issue 7 date.of 200809.
    
    This had the side effect of sometimes (in the traditional BSD
    compliation environment)
     #if BYTE_ORDER == LITTLE_ENDIAN
    and
     #if BYTE_ORDER == BIG_ENDIAN
    both being true because none of these were defined. This fixes
    that. It also fixes including it after <stdio.h> but not before.
    
    PR:                     269249
    MFC After:              1d (build related)
    Reviewed by:            kib, emaste
    Differential Revision:  https://reviews.freebsd.org/D39176
    
    Sponsored by:           Netflix
    
    (cherry picked from commit ed52baf51bd142b5e32701842346452a7ebe37a5)
---
 sys/sys/_endian.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h
index 7ac39386e2e1..3b4460472eb6 100644
--- a/sys/sys/_endian.h
+++ b/sys/sys/_endian.h
@@ -36,6 +36,8 @@
 #error "sys/_endian.h should not be included directly"
 #endif
 
+#include <sys/cdefs.h>				/* visibility macros */
+
 /* BSD Compatiblity */
 #define	_BYTE_ORDER	__BYTE_ORDER__
 
@@ -66,10 +68,11 @@
 #endif
 
 /*
- * Deprecated variants that don't have enough underscores to be useful in more
- * strict namespaces.
+ * POSIX Issue 8 will require these for endian.h. Define them there and in the
+ * traditional BSD compilation environment. Since issue 8 doesn't yet have an
+ * assigned date, use strictly greater than issue 7's date.
  */
-#if __BSD_VISIBLE
+#if __BSD_VISIBLE || _POSIX_C_SOURCE > 200809
 #define	LITTLE_ENDIAN   _LITTLE_ENDIAN
 #define	BIG_ENDIAN      _BIG_ENDIAN
 #define	PDP_ENDIAN      _PDP_ENDIAN