_POSIX_C_SOURCE

On GNOME bug 561962 I have someone complaining that Metacity defines _POSIX_C_SOURCE before using POSIX functions (as you’re supposed to). He says that defining this breaks the build on OS X. Do some of you know much about POSIX on OS X and can explain to me why this should be, here or on the bug? It seems to me that if your toolchain knows about _POSIX_C_SOURCE then you’ll need it to use POSIX-only functions, and if it doesn’t it’s just another symbol. I can’t see why removing it would fix something.

Published by

Thomas Thurman

Mostly themes, triaging, and patch review.

6 thoughts on “_POSIX_C_SOURCE”

  1. “_POSIX_C_SOURCE means ‘I want to use POSIX and I don’t want to use any *non*-POSIX calls?'”

    I guess not only on OSX, but on all compliant POSIX sources. From the spec: “Additional symbols not required or explicitly permitted by IEEE Std 1003.1-2001 to be in that header shall not be made visible, except when enabled by another feature test macro.”

    I guess on OSX that “enabled by another feature test macro” thing is the “_DARWIN_C_SOURCE” macro.

  2. The compilation is stopping on a line like

    #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1

    Try changing your #define to something like

    #define _POSIX_C_SOURCE 1

    which is probably what you wanted in the first place.

  3. The problem is that _POSIX_C_SOURCE is stupid, and doesn’t mean “I need POSIX features”. It means “I need POSIX features and I *don’t* need non-POSIX features. Basically this means that you only use _POSIX_C_SOURCE when you want to treat all platforms as being completely identical. If you are using autoconf, then pretty much by definition you don’t want to use _POSIX_C_SOURCE. (Yes, this means _POSIX_C_SOURCE is completely useless in the real world. It’s not meant for the real world, it’s meant for POSIX-compliance test suites.)

    If you get a “not defined” warning on linux when you remove _POSIX_C_SOURCE, then set _GNU_SOURCE instead.

Leave a Reply

Your email address will not be published. Required fields are marked *