What is the __DARWIN_C_LEVEL C preprocessor character?

I recently got 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 defines 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 many hits for him, but this is either a copy of Apple's source code, or some kind of patch. Confer, "__ DARWIN_C_LEVEL": opensource.apple.com .

Apple uses it this way, but its not clear what they are aiming for:

 #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 to use it?

+7
c c-preprocessor posix macos
source share
1 answer

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 real _POSIX_C_SOURCE value (which looks like dates like 199808L ), or it will have two values ​​outside the range 010000L and 900000L , meaning, apparently, much less posixy and lots more than posixy.

  • If _ANSI_SOURCE defined __DARWIN_C_LEVEL will be 010000L ;
  • else if _POSIX_C_SOURCE defined, but _DARWIN_C_SOURCE and _NONSTD_SOURCE are not present, __DARWIN_C_LEVEL will be anything _POSIX_C_SOURCE Value:
  • else __DARWIN_C_LEVEL will be 900000L .
+1
source share

All Articles