diff options
Diffstat (limited to 'man3/getopt.3')
-rw-r--r-- | man3/getopt.3 | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/man3/getopt.3 b/man3/getopt.3 index 88fd167..71c3675 100644 --- a/man3/getopt.3 +++ b/man3/getopt.3 @@ -20,7 +20,7 @@ .\" the start of optstring .\" Modified 2006-12-15, mtk, Added getopt() example program. .\" -.TH getopt 3 2023-07-20 "Linux man-pages 6.05.01" +.TH getopt 3 2023-10-31 "Linux man-pages 6.7" .SH NAME getopt, getopt_long, getopt_long_only, optarg, optind, opterr, optopt \- Parse command-line options @@ -30,15 +30,15 @@ Standard C library .SH SYNOPSIS .nf .B #include <unistd.h> -.PP +.P .BI "int getopt(int " argc ", char *" argv [], .BI " const char *" optstring ); -.PP +.P .BI "extern char *" optarg ; .BI "extern int " optind ", " opterr ", " optopt ; -.PP +.P .B #include <getopt.h> -.PP +.P .BI "int getopt_long(int " argc ", char *" argv [], .BI " const char *" optstring , .BI " const struct option *" longopts ", int *" longindex ); @@ -46,17 +46,17 @@ Standard C library .BI " const char *" optstring , .BI " const struct option *" longopts ", int *" longindex ); .fi -.PP +.P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE -.PP +.P .BR getopt (): .nf _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE .fi -.PP +.P .BR getopt_long (), .BR getopt_long_only (): .nf @@ -82,7 +82,7 @@ If .BR getopt () is called repeatedly, it returns successively each of the option characters from each of the option elements. -.PP +.P The variable .I optind is the index of the next element to be processed in @@ -91,7 +91,7 @@ The system initializes this value to 1. The caller can reset it to 1 to restart scanning of the same .IR argv , or when scanning a new argument vector. -.PP +.P If .BR getopt () finds another option character, it returns that @@ -101,13 +101,13 @@ variable \fInextchar\fP so that the next call to can resume the scan with the following option character or \fIargv\fP-element. -.PP +.P If there are no more option characters, .BR getopt () returns \-1. Then \fIoptind\fP is the index in \fIargv\fP of the first \fIargv\fP-element that is not an option. -.PP +.P .I optstring is a string containing the legitimate option characters. A legitimate option character is any visible one byte @@ -139,7 +139,7 @@ is treated as the long option option is reserved by POSIX.2 for implementation extensions.) This behavior is a GNU extension, not available with libraries before glibc 2. -.PP +.P By default, .BR getopt () permutes the contents of \fIargv\fP as it @@ -166,7 +166,7 @@ written to expect options and other \fIargv\fP-elements in any order and that care about the ordering of the two.) The special argument "\-\-" forces an end of option-scanning regardless of the scanning mode. -.PP +.P While processing the option list, .BR getopt () can detect two kinds of errors: @@ -220,14 +220,14 @@ may take a parameter, of the form .B \-\-arg=param or .BR "\-\-arg param" . -.PP +.P .I longopts is a pointer to the first element of an array of .I struct option declared in .I <getopt.h> as -.PP +.P .in +4n .EX struct option { @@ -238,7 +238,7 @@ struct option { }; .EE .in -.PP +.P The meanings of the different fields are: .TP .I name @@ -267,13 +267,13 @@ option is found, but left unchanged if the option is not found. \fIval\fP is the value to return, or to load into the variable pointed to by \fIflag\fP. -.PP +.P The last element of the array has to be filled with zeros. -.PP +.P If \fIlongindex\fP is not NULL, it points to a variable which is set to the index of the long option relative to .IR longopts . -.PP +.P .BR getopt_long_only () is like .BR getopt_long (), @@ -301,7 +301,7 @@ then the return value depends on the first character in .IR optstring : if it is \[aq]:\[aq], then \[aq]:\[aq] is returned; otherwise \[aq]?\[aq] is returned. -.PP +.P .BR getopt_long () and .BR getopt_long_only () @@ -347,7 +347,6 @@ T} Thread safety T{ MT-Unsafe race:getopt env T} .TE -.sp 1 .SH VERSIONS POSIX specifies that the .I argv @@ -378,7 +377,7 @@ is a GNU extension. .TP .BR getopt () POSIX.1-2001, and POSIX.2. -.PP +.P On some older implementations, .BR getopt () was declared in @@ -411,7 +410,7 @@ routine that rechecks .B POSIXLY_CORRECT and checks for GNU extensions in .IR optstring .) -.PP +.P Command-line arguments are parsed in strict order meaning that an option requiring an argument will consume the next argument, regardless of whether that argument is the correctly specified option argument @@ -438,7 +437,7 @@ to handle two program options: with no associated value; and .IR "\-t val" , which expects an associated value. -.PP +.P .\" SRC BEGIN (getopt.c) .EX #include <stdio.h> @@ -490,7 +489,7 @@ main(int argc, char *argv[]) The following example program illustrates the use of .BR getopt_long () with most of its features. -.PP +.P .\" SRC BEGIN (getopt_long.c) .EX #include <getopt.h> |