git: f6ed9cd68c28 - main - cdefs.h: Document the _XOPEN_SOURCE - 0 construct
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 15 Nov 2024 02:02:13 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f6ed9cd68c28b18082773c6f77cee4b8492dcfe6 commit f6ed9cd68c28b18082773c6f77cee4b8492dcfe6 Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-11-14 23:53:13 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-11-15 02:01:12 +0000 cdefs.h: Document the _XOPEN_SOURCE - 0 construct Various System V Interface Definition editions, as well as the X/Open group portability guide issue 4, recommend defining _XOPEN_SOURCE and broadly intimating it means the same thing as _POSIX_SOURCE == 2. Starting in X/Open issue 5 (1995), _XOPEN_SOURCE needs to be defined to be 500 to bring in the newer interfaces. However, it is still common hat sources define _XOPEN_SOURCE to be blank. To deal with that, we subtract 0 from _XOPEN_SOURCE to make the other expressions well formed. While here, document that we should define _POSIX_C_SOURCE to be 199209 based on the SVID, the first version of the Single Unix Specification, and X/Open CAE issue 4, version 2. Also document that historically this has been a NOP. Any value of _XOPEN_SOURCE < 500 (including it being blank) was not viewed as a request for a restricted namespace. Reviewed by: brooks (earlier version) Differential Revision: https://reviews.freebsd.org/D47584 Sponsored by: Netflix --- sys/sys/cdefs.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 4100cc0de7a5..0f53ff816527 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -513,7 +513,16 @@ #define _POSIX_C_SOURCE 199209 #endif -/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +/* + * Deal with various X/Open Portability Guides and Single UNIX Spec. We use the + * '- 0' construct so software that defines _XOPEN_SOURCE to nothing doesn't + * cause errors. X/Open CAE Specification, August 1994, System Interfaces and + * Headers, Issue 4, Version 2 section 2.2 states an empty definition means the + * same thing as _POSIX_C_SOURCE == 2. This broadly mirrors "System V Interface + * Definition, Fourth Edition", but earlier editions suggest some ambiguity. + * However, FreeBSD has histoically implemented this as a NOP, so we just + * document what it should be for now to not break ports gratuitously. + */ #ifdef _XOPEN_SOURCE #if _XOPEN_SOURCE - 0 >= 800 #define __XSI_VISIBLE 800 @@ -531,6 +540,8 @@ #define __XSI_VISIBLE 500 #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199506 +#else +/* #define _POSIX_C_SOURCE 199209 */ #endif #endif