[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

_POSIX_C_SOURCE & _XOPEN_SOURCE standards conformance level macros

From: John Hein
Subject: _POSIX_C_SOURCE & _XOPEN_SOURCE standards conformance level macros
Date: Sun, 13 Nov 2016 10:41:07 -0700

On FreeBSD, when using the ncurses port, pkg-config --cflags ncurses gives:

-I/usr/local/include -I/usr/local/include/ncurses -D_BSD_TYPES -D__BSD_VISIBLE 

If you then use those flags to compile a program that happens to use
ncurses, it will force your code to conform to that level of standards

Why would code that includes ncurses headers want or need to use

Here's a example that shows what drives this question:


#include <fcntl.h>
#include <ncurses.h>
    int fd = open("foo", O_RDWR | O_CLOEXEC);
    /* ... do stuff with fd */

% cc -I/usr/local/include -I/usr/local/include/ncurses -D_BSD_TYPES 
-D__BSD_VISIBLE -o /dev/null -c /tmp/nc.c
% cc -I/usr/local/include -I/usr/local/include/ncurses -D_BSD_TYPES 
-D__BSD_VISIBLE -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600  -o /dev/null -c 
/tmp/foo.c: In function 'foo':
/tmp/foo.c:6: error: 'O_CLOEXEC' undeclared (first use in this function)
/tmp/foo.c:6: error: (Each undeclared identifier is reported only once
/tmp/foo.c:6: error: for each function it appears in.)


On FreeBSD, fcntl.h has:

#if __POSIX_VISIBLE >= 200809
/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
#define O_TTY_INIT      0x00080000      /* Restore default termios attributes */

#define O_CLOEXEC       0x00100000

I'm trying to determine if ncurses.pc should be including those -D
options publicly.  Does code that includes ncurses header files
need to be compiled with those levels of standards conformance
macros defined that way?

Or should the .pc file not expose those defines as part of the
exported cflags needed to build code that happens to use the ncurses

In the above example, for instance, it seems pretty clear that ncurses
shouldn't care at all that code uses O_CLOEXEC or not.  But that's
a contrived simplified example.

My initial thought is that ncurses.pc should remove those -D flags
from the "Cflags:" field.  Maybe there's something subtle I haven't
noticed yet, however.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]