This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Proper Conditionals for POSIX CX and XSI

On 7/18/2013 3:01 AM, Yaakov (Cygwin/X) wrote:
On 2013-07-17 19:56, Sebastian Huber wrote:
On 2013-07-18 06:15, Yaakov (Cygwin/X) wrote:
On 2013-07-17 15:34, Joel Sherrill wrote:
While this was still fresh, I wanted to ask what was the
proper conditional for methods marked as CX or XSI
in the POSIX standard.
This is what is done in glibc:

In short, <features.h> recognizes _*_SOURCE macros, which it uses to set
various __USE_* private macros which are used throughout the headers as
conditionals to control which APIs are made available.

Having this done *properly* in the Newlib/Cygwin headers would be a
big step to
fixing a lot of compiling incompatibilities with glibc.  It is also a
tedious task, although it may not have to be done all at once
Unfortunately the GNU and BSD people don't talk much with each other.
In FreeBSD we have this _*_SOURCE evaluation in <sys/cdefs.h>.  Since I
updated Newlibs "newlib/libc/include/sys/cdefs.h" a couple of weeks ago
we should consider to use the infrastructure already available (see line
535 and below).  Due to license issues it is more likely that Newlib
will use code from BSD sources.
AFAIK it doesn't really matter which header provides this functionality,
as long as all affected headers include that one.  However, IMO we need
to support all the _*_SOURCE options, particularly _GNU_SOURCE.  It is
also necessary to #undef all the __*_VISIBLE macros at the beginning of
that section, otherwise you can get redefinition warnings in certain

Let's try to make that more compatible with feature_test_macros(7), then
we can start working on conditionalizing the standard headers.
Some of the feature macros are already used in newlib.

FWIW glibc uses this for memccpy() which is an XSI routine. It is
not protected in newlib:

#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN
extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
                      int __c, size_t __n)
     __THROW __nonnull ((1, 2));
#endif /* SVID.  */
:e #
:e #
For strdup() which is an CX method, there is this:

newlib: #if !defined(__STRICT_ANSI__) || (_XOPEN_SOURCE - 0) >= 500
glibc: #if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED \
    || defined __USE_XOPEN2K8

Could newlib use the same set of conditionals? Should it use the exact
same test?

I didn't mean to start a deep philosophical discussion. This
should be a simple matter of 'X is marked CX/XSI in
POSIX, wrap it in this boilerplate." And we define the boilerplate.

If something isn't tripped properly by cdefs.h, it is a bug in cdefs.h
but that should be unlikely since we have the FreeBSD cdefs.h.


Joel Sherrill, Ph.D.             Director of Research & Development        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]