summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/getopt.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdlib/getopt.3')
-rw-r--r--lib/libc/stdlib/getopt.334
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3
index 95ff6e6..39cc5de 100644
--- a/lib/libc/stdlib/getopt.3
+++ b/lib/libc/stdlib/getopt.3
@@ -29,16 +29,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getopt.3 8.4 (Berkeley) 4/19/94
+.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
.\"
-.Dd April 19, 1994
+.Dd April 27, 1995
.Dt GETOPT 3
.Os BSD 4.3
.Sh NAME
.Nm getopt
.Nd get option character from command line argument list
.Sh SYNOPSIS
-.Fd #include <stdlib.h>
+.Fd #include <unistd.h>
.Vt extern char *optarg;
.Vt extern int optind;
.Vt extern int optopt;
@@ -120,8 +120,7 @@ must be reinitialized.
The
.Fn getopt
function
-returns an
-.Dv EOF
+returns \-1
when the argument list is exhausted, or a non-recognized
option is encountered.
The interpretation of options in the argument list may be cancelled
@@ -129,13 +128,11 @@ by the option
.Ql --
(double dash) which causes
.Fn getopt
-to signal the end of argument processing and return an
-.Dv EOF .
+to signal the end of argument processing and returns \-1.
When all options have been processed (i.e., up to the first non-option
argument),
.Fn getopt
-returns
-.Dv EOF .
+returns \-1.
.Sh DIAGNOSTICS
If the
.Fn getopt
@@ -177,7 +174,7 @@ extern int optind;
int bflag, ch, fd;
bflag = 0;
-while ((ch = getopt(argc, argv, "bf:")) != EOF)
+while ((ch = getopt(argc, argv, "bf:")) != -1)
switch(ch) {
case 'b':
bflag = 1;
@@ -202,6 +199,18 @@ The
function appeared
.Bx 4.3 .
.Sh BUGS
+The
+.Fn getopt
+function was once specified to return
+.Dv EOF
+instead of \-1.
+This was changed by
+.St -p1003.2-92
+to decouple
+.Fn getopt
+from
+.Pa <stdio.h> .
+.Pp
A single dash
.Dq Li -
may be specified as an character in
@@ -219,8 +228,7 @@ It is provided for backward compatibility
.Em only .
By default, a single dash causes
.Fn getopt
-to return
-.Dv EOF .
+to return \-1.
This is, we believe, compatible with System V.
.Pp
It is also possible to handle digits as option letters.
@@ -237,7 +245,7 @@ The following code fragment works in most cases.
int length;
char *p;
-while ((c = getopt(argc, argv, "0123456789")) != EOF)
+while ((c = getopt(argc, argv, "0123456789")) != -1)
switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
OpenPOWER on IntegriCloud