Subject: Re: Solaris like __EXTENSIONS__ ?
To: Marc Recht <marc@informatik.uni-bremen.de>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 04/25/2003 00:05:56
On Thu, 24 Apr 2003, Ben Harris wrote:

> I'm already working on it.  I've got most of a patch worked out, and will
> post a URL for it here when it's ready for review (probably later today).

Right.  I've got a first draft of the patch.  I haven't tried actually
compiling anything with it yet, but it's at
<http://www.chiark.greenend.org.uk/~bjharris/featuretest.diff>.  People
should tell me what I've got wrong.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them.  In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

There are a lot of places where our headers get things wrong that I
haven't fixed in this patch.  I plan to make another pass through our
standardised headers from <arpa/inet.h> to <wctype.h> cleaning things up
once I've got this committed.

The interesting part of this current patch is the comment in
<sys/featuretest.h> explaining what's going on.  Here it is for your
corrections and enhancements:

/*
 * Feature-test macros are defined by several standards, and allow an
 * application to specify what symbols they want the system headers to
 * expose, and hence what standard they want them to conform to.
 * There are two classes of feature-test macros.  The first class
 * specify complete standards, and if one of these is defined, header
 * files will try to conform to the relevant standard.  They are:
 *
 * ANSI macros:
 * _ANSI_SOURCE                 ANSI C89
 *
 * POSIX macros:
 * _POSIX_SOURCE == 1           IEEE Std 1003.1 (version?)
 * _POSIX_C_SOURCE == 1         IEEE Std 1003.1-1990
 * _POSIX_C_SOURCE == 2         IEEE Std 1003.2-1992
 * _POSIX_C_SOURCE == 199309L   IEEE Std 1003.1b-1993
 * _POSIX_C_SOURCE == 199506L   ISO/IEC 9945-1:1996
 * _POSIX_C_SOURCE == 200112L   IEEE Std 1003.1-2001
 *
 * X/Open macros:
 * _XOPEN_SOURCE                System Interfaces and Headers, Issue 4, Ver 2
 * _XOPEN_SOURCE_EXTENDED == 1  XSH4.2 UNIX extensions
 * _XOPEN_SOURCE == 500         System Interfaces and Headers, Issue 5
 * _XOPEN_SOURCE == 600         IEEE Std 1003.1-2001, XSI option
 *
 * NetBSD macros:
 * _NETBSD_SOURCE == 1          Make all NetBSD features available.
 *
 * If more than one of these "major" feature-test macros is defined,
 * then the set of facilities provided (and namespace used) is the
 * union of that specified by the relevant standards, and in case of
 * conflict, the earlier standard in the above list has precedence (so
 * if both _POSIX_C_SOURCE and _NETBSD_SOURCE are defined, the version
 * of rename() that's used is the POSIX one).  If none of the "major"
 * feature-test macros is defined, _NETBSD_SOURCE is assumed.
 *
 * There are also "minor" feature-test macros, which enable extra
 * functionality in addition to some base standard.  They should be
 * defined along with one of the "major" macros.  The "minor" macros
 * are:
 *
 * _REENTRANT
 * _ISO_C99_SOURCE
 * _LARGEFILE_SOURCE
 */

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26           <URL:http://www.netbsd.org/Ports/acorn26/>