From owner-freebsd-standards Tue Feb 26 21:40:34 2002 Delivered-To: freebsd-standards@freebsd.org Received: from espresso.q9media.com (espresso.q9media.com [216.254.138.122]) by hub.freebsd.org (Postfix) with ESMTP id 92A1F37B41A for ; Tue, 26 Feb 2002 21:39:51 -0800 (PST) Received: (from mike@localhost) by espresso.q9media.com (8.11.6/8.11.6) id g1R5Yli24966 for standards@FreeBSD.org; Wed, 27 Feb 2002 00:34:47 -0500 (EST) (envelope-from mike) Date: Wed, 27 Feb 2002 00:34:47 -0500 From: Mike Barcroft To: standards@FreeBSD.org Subject: Garrett's POSIX versions patch for review Message-ID: <20020227003447.O31007@espresso.q9media.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="sdtB3X0nJg68CQEu" Content-Disposition: inline Organization: The FreeBSD Project Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Rather than take forever updating Garrett's patch to a more recent -current, I thought I'd post just the changes to , and work on using the primitive as I work on various headers. Attached is a diff against my version of . I added __ISO_C_VISIBLE in order to identify ISO C features. There is no way to specify a pristine ISO C environment, but we could require a #define before any headers, and document that requirement in the soon- to-be-created c99(7) manual. I also changed the logic, which wasn't quite right (POSIX versions would always be demoted because of fallthru). This meant using a ANSI C construct, specificly #elif. Yes, this means K&R would not work on FreeBSD anymore. But since there is an effort to actively remove K&R support, I don't see this as a problem. If there are objections to this, I can change it to use a long indented list of #if/#else's (yuk!). Best regards, Mike Barcroft --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cdefs.diff" Index: cdefs.h =================================================================== RCS file: /work/repo/src/sys/sys/cdefs.h,v retrieving revision 1.49 diff -u -r1.49 cdefs.h --- cdefs.h 4 Dec 2001 01:29:54 -0000 1.49 +++ cdefs.h 27 Feb 2002 03:28:19 -0000 @@ -268,4 +268,99 @@ #define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) #endif +/*- + * The following definitions are an extension of the behavior + * originally implemented in , but with a different + * level of granularity. POSIX.1 requires that the macros we test + * be defined before any standard header file is included. + * + * Here's a quick run-down of the versions: + * defined(_POSIX_SOURCE) 1003.1-1988 + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 199309 1003.1b-1993 + * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1: 1996 + * _POSIX_C_SOURCE == 200112 1003.1-2001 + * + * In addition, the X/Open Portability Guide, which is now the Single + * UNIX Specification, defines a feature-test macro which indicates the + * version of that specification, and which subsumes _POSIX_C_SOURCE. + * + * Our macros begin with two underscores to avoid namespace screwage. + */ + +/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 199309 +# undef _POSIX_C_SOURCE /* probably illegal, but beyond caring now */ +# define _POSIX_C_SOURCE 199009 +#endif + +/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +#if defined(_XOPEN_SOURCE) +# if _XOPEN_SOURCE >= 600 +# define __XSI_VISIBLE 600 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112 +# elif _XOPEN_SOURCE >= 500 +# define __XSI_VISIBLE 500 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506 +# endif +#endif + +/* + * Deal with all versions of POSIX. The ordering relative to the tests above is + * important. + */ +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +# define _POSIX_C_SOURCE 198808 +#endif +#if defined(_POSIX_C_SOURCE) +# if _POSIX_C_SOURCE >= 200112 +# define __POSIX_VISIBLE 200112 +# define __ISO_C_VISIBLE 1999 +# elif _POSIX_C_SOURCE >= 199506 +# define __POSIX_VISIBLE 199506 +# define __ISO_C_VISIBLE 1990 +# elif _POSIX_C_SOURCE >= 199309 +# define __POSIX_VISIBLE 199309 +# define __ISO_C_VISIBLE 1990 +# elif _POSIX_C_SOURCE >= 199009 +# define __POSIX_VISIBLE 199009 +# define __ISO_C_VISIBLE 1990 +# else +# define __POSIX_VISIBLE 198808 +# define __ISO_C_VISIBLE 0 +# endif +#else +/*- + * Deal with _ANSI_SOURCE: + * If it is defined, and no other compilation environment is explicitly + * requested, then define our internal feature-test macros to zero. + * This makes no difference to the preprocessor (undefined symbols in + * preprocessing expressions are defined to have value zero), but makes + * it more convenient for a test program to print out the values. + * + * If a program mistakenly defines _ANSI_SOURCE and some other macro + * such as _POSIX_C_SOURCE, we will assume that it wants the broader + * compilation environment (and in fact we will never get here). + */ +# if defined(_ANSI_SOURCE) /* hide almost everything */ +# define __POSIX_VISIBLE 0 +# define __XSI_VISIBLE 0 +# define __BSD_VISIBLE 0 +# define __ISO_C_VISIBLE 1990 +# else /* default environment: show everything */ +# define __POSIX_VISIBLE 200112 +# define __XSI_VISIBLE 600 +# define __BSD_VISIBLE 1 +# define __ISO_C_VISIBLE 1999 +# endif +#endif + +#if __POSIX_VISIBLE +#define _POSIX_VERSION 200112 +#define _KPOSIX_VERSION 200112 +#endif + #endif /* !_SYS_CDEFS_H_ */ --sdtB3X0nJg68CQEu-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message