Macros like _GNU_SOURCE, what do they mean?

Lots many times referring to linux header files or man files I see the following macros used ..

Example: man mkstemp

In this man page, we see the following macros displayed.

_GNU_SOURCE
_BSD_SOURCE
_SVID_SOURCE
_XOPEN_SOURCE
_XOPEN_SOURCE_EXTENDED

      

What do I need to understand in order to write the correct program if I use these APIs / headers?

+3


source to share


1 answer


Read the feature_test_macros (7) man page (and ยง1.3. 4 Feature Test Macros in the GNU libc documentation chapter).

You can compile your entire program with special function symbols. For example, I often compile a program with -D_GNU_SOURCE

. This means that I need all the additional GNU functionality provided in my GNU libc system, etc. Instead, you can compile with -D_POSIX_C_SOURCE=200112L

if you want strict POSIX 2001 (and nothing more).

Alternatively, if all your files .c

are simple #include

- just for their own header, that header can start with #define _GNU_SOURCE 1

followed by several system #include

...



The point is that the GNU / Linux system obeys several standards (with GNU providing its own standard) and you can choose which ones.

GNU libc (this is the most common libc available on Linux, but you can use some other libc like musl-libc ....) provides many functions, functions and headers not available on other systems, like <argp.h>

(header), fopencookie (function), %m

format control directive in printf

.

This is also true if you intend to code a program that is portable to other POSIX systems (such as MacOSX). On MacOSX or AIX systems, you don't getopt_long

, as this is a specific GNU feature.

+3


source







All Articles