home | list info | list archive | date index | thread index

Re: "_GNU_SOURCE" versus "__USE_GNU"

On Thu, 27 Jun 2019, Robert P. J. Day wrote:

>
>   minor curiosity regarding GNU C library and feature test macros;
> perhaps i'm just misreading.
>
> from "man 3 getenv":
>
>   SYNOPSIS
>        #include <stdlib.h>
>
>        char *getenv(const char *name);
>
>        char *secure_getenv(const char *name);
>
>    Feature    Test    Macro   Requirements   for   glibc   (see   fea‐
>    ture_test_macros(7)):
>
>        secure_getenv(): _GNU_SOURCE
>
> so i would normally read that as that i need to define "_GNU_SOURCE"
> before including stdlib.h to define the external reference to
> secure_getenv(), but that doesn't work as this is what is in
> /usr/include/stdlib.h:
>
>   #ifdef __USE_GNU
>   /* This function is similar to the above but returns NULL if the
>      programs is running with SUID or SGID enabled.  */
>   extern char *secure_getenv (const char *__name)
>        __THROW __nonnull ((1)) __wur;
>   #endif
>
> and defining "__USE_GNU" makes it work just fine.
>
>   what is the proper usage of feature test macros in such a case,
> since the man page suggests one thing while the header file clearly
> shows another. thoughts?

  never mind, i realized my mistake ... you have to define the feature
test macro(s) as the very first non-comment in the source file, not
just before the header file you want it to affect. my bad.

rday

references

message navigation