Should I expect POSIX to include getopt.h?

According to this , the POSIX library does not include getopt.h. However, I found this in unistd.h:

#ifdef  __USE_POSIX2
/* Get definitions and prototypes for functions to process the
   arguments in ARGV (ARGC of them, minus the program name) for
   options given in OPTS.  */
# define __need_getopt
# include <getopt.h>
#endif

Does this mean that it getopt.himplicitly turns on when turned on unistd.h? I mean, is the code above what I should expect from all implementations of the unistd header file, or is it just something that is in my particular version? Also, is the macro __USE_POSIX2defined in POSIX.2 onwards, or is it just for POSIX.2?

+3
source share
2 answers

__USE_POSIX2 - glibc; _POSIX_C_SOURCE >= 2 _XOPEN_SOURCE. _GNU_SOURCE , ANSI. __USE_.

>= 2, . . feature_test_macros.

, feature.h( - - ):

/* These are defined by the user (or the compiler)
   to specify the desired environment:
...
   _POSIX_C_SOURCE  If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2;
            if >=199309L, add IEEE Std 1003.1b-1993;
            if >=199506L, add IEEE Std 1003.1c-1995;
            if >=200112L, all of IEEE 1003.1-2004
            if >=200809L, all of IEEE 1003.1-2008
   _XOPEN_SOURCE    Includes POSIX and XPG things.  Set to 500 if
            Single Unix conformance is wanted, to 600 for the
            sixth revision, to 700 for the seventh revision.
+2

getopt.h man- getopt(3). getopt, unistd.h ( GLIBC) _XOPEN_SOURCE _POSIX_C_SOURCE=something_greater_than_2 C. / POSIX.

, getopt_long. GNU , , .

+1

All Articles