Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the __DARWIN_C_LEVEL C-preprocessor symbol?

I recently received a patch that used __DARWIN_C_LEVEL. I think the person providing it uses OS X 10.10.

I have OS 10.9, 10.8 and 10.5 for testing, but none of them appear to define it.

10.5:

$ uname -a
Darwin PowerMac.home.pvt 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009;
root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh
$ cpp -dM < /dev/null | grep -i darwin
$

10.8:

$ uname -a
Darwin riemann.home.pvt 12.6.0 Darwin Kernel Version 12.6.0: Wed Mar 18 16:23:48 PDT 2015;
root:xnu-2050.48.19~1/RELEASE_X86_64 x86_64
$ cpp -dM </dev/null | grep -i darwin
$

There are lots of hits for it, but its either a rip of Apple's source code or someone's patch. Confer, "__DARWIN_C_LEVEL" site:opensource.apple.com.

Apple uses it like so, but its not clear to me what they are trying to achieve:

#if __DARWIN_C_LEVEL > __DARWIN_C_ANSI
#define _POSIX_ARG_MAX      4096
#define _POSIX_CHILD_MAX    25
...
#endif

What is __DARWIN_C_LEVEL, and how should it be used?

like image 352
jww Avatar asked Sep 27 '15 01:09

jww


1 Answers

In <sys/cdefs.h> you will find:

/*
 * Set a single macro which will always be defined and can be used to determine
 * the appropriate namespace.  For POSIX, these values will correspond to
 * _POSIX_C_SOURCE value.  Currently there are two additional levels corresponding
 * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
 */
#define __DARWIN_C_ANSI         010000L
#define __DARWIN_C_FULL         900000L

#if   defined(_ANSI_SOURCE)
#define __DARWIN_C_LEVEL        __DARWIN_C_ANSI
#elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
#define __DARWIN_C_LEVEL        _POSIX_C_SOURCE
#else
#define __DARWIN_C_LEVEL        __DARWIN_C_FULL
#endif

So __DARWIN_C_LEVEL will either be a valid _POSIX_C_SOURCE value (which look like dates like 199808L) or it will be two values well outside that range 010000L and 900000L connoting, apparently, lots less posixy and lots more posixy.

  • If _ANSI_SOURCE is defined __DARWIN_C_LEVEL will be 010000L;
  • else if _POSIX_C_SOURCE is defined, but _DARWIN_C_SOURCE and _NONSTD_SOURCE aren't, __DARWIN_C_LEVEL will be whatever _POSIX_C_SOURCEs value is;
  • else __DARWIN_C_LEVEL will be 900000L.
like image 195
John Hascall Avatar answered Oct 03 '22 02:10

John Hascall