Search code examples
clinuxposixglibcstandards-compliance

Requesting GNU extensions but otherwise POSIX-conformant functions?


Is there a way with feature test macros to have glibc expose GNU extensions (functions not specified in POSIX, and additional flag/argument macros for standard functions, like MAP_ANONYMOUS), but still prefer POSIX semantics whenever the POSIX and GNU definitions conflict? I'm thinking things like basename, strerror_r, etc.


Solution

  • For the specific case of basename(), including <libgen.h> header gives you the XPG / POSIX definition.

    MAP_ANONYMOUS isn't a GNU extension (_GNU_SOURCE), it's defined if either _BSD_SOURCE or _SVID_SOURCE is defined.