|
|
@ -25,7 +25,7 @@ |
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
|
|
.\" SUCH DAMAGE. |
|
|
|
.\" |
|
|
|
.\" $OpenBSD: getopt.3,v 1.26 2003/09/02 18:24:21 jmc Exp $ |
|
|
|
.\" $OpenBSD: getopt.3,v 1.27 2003/09/18 09:29:27 jmc Exp $ |
|
|
|
.\" |
|
|
|
.Dd December 17, 2002 |
|
|
|
.Dt GETOPT 3 |
|
|
@ -47,9 +47,11 @@ The |
|
|
|
.Fn getopt |
|
|
|
function incrementally parses a command line argument list |
|
|
|
.Fa argv |
|
|
|
and returns the next known option character. |
|
|
|
and returns the next |
|
|
|
.Em known |
|
|
|
option character. |
|
|
|
An option character is |
|
|
|
.Dq known |
|
|
|
.Em known |
|
|
|
if it has been specified in the string of accepted option characters, |
|
|
|
.Fa optstring . |
|
|
|
.Pp |
|
|
@ -113,7 +115,7 @@ by the option |
|
|
|
.Ql -- |
|
|
|
(double dash) which causes |
|
|
|
.Fn getopt |
|
|
|
to signal the end of argument processing and returns \-1. |
|
|
|
to signal the end of argument processing and return \-1. |
|
|
|
When all options have been processed (i.e., up to the first non-option |
|
|
|
argument), |
|
|
|
.Fn getopt |
|
|
@ -134,9 +136,9 @@ it returns |
|
|
|
If |
|
|
|
.Fa optstring |
|
|
|
has a leading |
|
|
|
.Sq \: |
|
|
|
.Sq \&: |
|
|
|
then a missing option argument causes |
|
|
|
.Sq \: |
|
|
|
.Sq \&: |
|
|
|
to be returned instead of |
|
|
|
.Sq \&? . |
|
|
|
In either case, the variable |
|
|
@ -147,6 +149,8 @@ The |
|
|
|
function returns \-1 when the argument list is exhausted. |
|
|
|
.Sh EXAMPLES |
|
|
|
.Bd -literal -compact |
|
|
|
extern char *optarg; |
|
|
|
extern int optind; |
|
|
|
int bflag, ch, fd; |
|
|
|
|
|
|
|
bflag = 0; |
|
|
@ -174,7 +178,7 @@ argv += optind; |
|
|
|
If the |
|
|
|
.Fn getopt |
|
|
|
function encounters a character not found in the string |
|
|
|
.Va optstring |
|
|
|
.Fa optstring |
|
|
|
or detects |
|
|
|
a missing option argument it writes an error message to |
|
|
|
.Em stderr |
|
|
@ -184,7 +188,7 @@ Setting |
|
|
|
.Va opterr |
|
|
|
to a zero will disable these error messages. |
|
|
|
If |
|
|
|
.Va optstring |
|
|
|
.Fa optstring |
|
|
|
has a leading |
|
|
|
.Ql \&: |
|
|
|
then a missing option argument causes a |
|
|
@ -198,7 +202,7 @@ this is reasonable but reduces the amount of error checking possible. |
|
|
|
.Xr getopt 1 , |
|
|
|
.Xr getopt_long 3 , |
|
|
|
.Xr getsubopt 3 |
|
|
|
.Sh EXTENSIONS |
|
|
|
.Sh STANDARDS |
|
|
|
The |
|
|
|
.Va optreset |
|
|
|
variable was added to make it possible to call the |
|
|
@ -223,7 +227,7 @@ This was changed by |
|
|
|
to decouple |
|
|
|
.Fn getopt |
|
|
|
from |
|
|
|
.Pa <stdio.h> . |
|
|
|
.Aq Pa stdio.h . |
|
|
|
.Pp |
|
|
|
A single dash |
|
|
|
.Pq Ql - |
|
|
|