diff options
| author | millert <> | 2003-09-22 23:47:26 +0000 |
|---|---|---|
| committer | millert <> | 2003-09-22 23:47:26 +0000 |
| commit | adcc29a58e1b4c60196e548e543281b24b076c98 (patch) | |
| tree | 2e658f55e3b77900e56dd64d3d0a17f3b611d966 /src/lib/libc | |
| parent | fb596a0bc3c3e40564f75af219aaf48a059a9b32 (diff) | |
| download | openbsd-adcc29a58e1b4c60196e548e543281b24b076c98.tar.gz openbsd-adcc29a58e1b4c60196e548e543281b24b076c98.tar.bz2 openbsd-adcc29a58e1b4c60196e548e543281b24b076c98.zip | |
Document the optional argument support and as well as where we differ from
POSIX and/or GNU. deraadt@ and jmc@ OK
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/stdlib/getopt.3 | 115 |
1 files changed, 83 insertions, 32 deletions
diff --git a/src/lib/libc/stdlib/getopt.3 b/src/lib/libc/stdlib/getopt.3 index 50b756bfbb..d210852c6b 100644 --- a/src/lib/libc/stdlib/getopt.3 +++ b/src/lib/libc/stdlib/getopt.3 | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | .\" SUCH DAMAGE. | 26 | .\" SUCH DAMAGE. |
| 27 | .\" | 27 | .\" |
| 28 | .\" $OpenBSD: getopt.3,v 1.27 2003/09/18 09:29:27 jmc Exp $ | 28 | .\" $OpenBSD: getopt.3,v 1.28 2003/09/22 23:47:26 millert Exp $ |
| 29 | .\" | 29 | .\" |
| 30 | .Dd December 17, 2002 | 30 | .Dd December 17, 2002 |
| 31 | .Dt GETOPT 3 | 31 | .Dt GETOPT 3 |
| @@ -57,9 +57,13 @@ if it has been specified in the string of accepted option characters, | |||
| 57 | .Pp | 57 | .Pp |
| 58 | The option string | 58 | The option string |
| 59 | .Fa optstring | 59 | .Fa optstring |
| 60 | may contain the following elements: individual characters and | 60 | may contain the following elements: individual characters, |
| 61 | characters followed by a colon to indicate an option argument | 61 | characters followed by a colon, and characters followed by two colons. |
| 62 | is to follow. | 62 | A character followed by a single colon indicates that an argument |
| 63 | is to follow the option on the command line. | ||
| 64 | Two colons indicates that the argument is optional--this is an | ||
| 65 | extension not covered by | ||
| 66 | .Px . | ||
| 63 | For example, an option string | 67 | For example, an option string |
| 64 | .Qq x | 68 | .Qq x |
| 65 | recognizes an option | 69 | recognizes an option |
| @@ -147,6 +151,15 @@ is set to the character that caused the error. | |||
| 147 | The | 151 | The |
| 148 | .Fn getopt | 152 | .Fn getopt |
| 149 | function returns \-1 when the argument list is exhausted. | 153 | function returns \-1 when the argument list is exhausted. |
| 154 | .Sh ENVIRONMENT | ||
| 155 | .Bl -tag -width POSIXLY_CORRECTXX | ||
| 156 | .It Ev POSIXLY_CORRECT | ||
| 157 | If set, a leading | ||
| 158 | .Sq - | ||
| 159 | in | ||
| 160 | .Ar optstring | ||
| 161 | is ignored. | ||
| 162 | .El | ||
| 150 | .Sh EXAMPLES | 163 | .Sh EXAMPLES |
| 151 | .Bd -literal -compact | 164 | .Bd -literal -compact |
| 152 | extern char *optarg; | 165 | extern char *optarg; |
| @@ -204,31 +217,38 @@ this is reasonable but reduces the amount of error checking possible. | |||
| 204 | .Xr getsubopt 3 | 217 | .Xr getsubopt 3 |
| 205 | .Sh STANDARDS | 218 | .Sh STANDARDS |
| 206 | The | 219 | The |
| 220 | .Fn getopt | ||
| 221 | function implements a superset of the functionality specified by | ||
| 222 | .St -p1003.1 . | ||
| 223 | .Pp | ||
| 224 | The following extensions are supported: | ||
| 225 | .Bl -tag -width "xxx" | ||
| 226 | .It Li o | ||
| 227 | The | ||
| 207 | .Va optreset | 228 | .Va optreset |
| 208 | variable was added to make it possible to call the | 229 | variable was added to make it possible to call the |
| 209 | .Fn getopt | 230 | .Fn getopt |
| 210 | function multiple times. | 231 | function multiple times. |
| 211 | This is an extension to the | 232 | .It Li o |
| 212 | .St -p1003.2 | 233 | If the first character of |
| 213 | specification. | 234 | .Fa optstring |
| 214 | .Sh HISTORY | 235 | is a plus sign |
| 215 | The | 236 | .Pq Ql + , |
| 216 | .Fn getopt | 237 | it will be ignored. |
| 217 | function appeared in | 238 | This is for compatibility with |
| 218 | .Bx 4.3 . | 239 | .Tn GNU |
| 219 | .Sh BUGS | 240 | .Fn getopt . |
| 220 | The | 241 | .It Li o |
| 221 | .Fn getopt | 242 | If the first character of |
| 222 | function was once specified to return | 243 | .Fa optstring |
| 223 | .Dv EOF | 244 | is a dash |
| 224 | instead of \-1. | 245 | .Pq Ql - , |
| 225 | This was changed by | 246 | non-options will be returned as arguments to the option character |
| 226 | .St -p1003.2-92 | 247 | .Ql \e1 . |
| 227 | to decouple | 248 | This is for compatibility with |
| 228 | .Fn getopt | 249 | .Tn GNU |
| 229 | from | 250 | .Fn getopt . |
| 230 | .Aq Pa stdio.h . | 251 | .It Li o |
| 231 | .Pp | ||
| 232 | A single dash | 252 | A single dash |
| 233 | .Pq Ql - | 253 | .Pq Ql - |
| 234 | may be specified as a character in | 254 | may be specified as a character in |
| @@ -250,20 +270,51 @@ as the first character in | |||
| 250 | .Fa optstring | 270 | .Fa optstring |
| 251 | to avoid a semantic conflict with | 271 | to avoid a semantic conflict with |
| 252 | .Tn GNU | 272 | .Tn GNU |
| 253 | .Fn getopt , | 273 | .Fn getopt |
| 254 | which assigns different meaning to an | 274 | semantics (see above). |
| 255 | .Fa optstring | ||
| 256 | that begins with a | ||
| 257 | .Ql - . | ||
| 258 | By default, a single dash causes | 275 | By default, a single dash causes |
| 259 | .Fn getopt | 276 | .Fn getopt |
| 260 | to return \-1. | 277 | to return \-1. |
| 278 | .El | ||
| 279 | .Pp | ||
| 280 | Unlike | ||
| 281 | .Tn GNU | ||
| 282 | .Fn getopt , | ||
| 283 | .Ox | ||
| 284 | does not permute the argument vector to allow non-options to be | ||
| 285 | interspersed with options on the command line. | ||
| 286 | Programs requiring this behavior should use | ||
| 287 | .Xr getopt_long 3 | ||
| 288 | instead. | ||
| 289 | Because of this (and unlike | ||
| 290 | .Tn GNU ) , | ||
| 291 | the | ||
| 292 | .Ox | ||
| 293 | .Fn getopt | ||
| 294 | supports optional arguments separated by whitespace. | ||
| 295 | .Sh HISTORY | ||
| 296 | The | ||
| 297 | .Fn getopt | ||
| 298 | function appeared in | ||
| 299 | .Bx 4.3 . | ||
| 300 | .Sh BUGS | ||
| 301 | The | ||
| 302 | .Fn getopt | ||
| 303 | function was once specified to return | ||
| 304 | .Dv EOF | ||
| 305 | instead of \-1. | ||
| 306 | This was changed by | ||
| 307 | .St -p1003.2-92 | ||
| 308 | to decouple | ||
| 309 | .Fn getopt | ||
| 310 | from | ||
| 311 | .Aq Pa stdio.h . | ||
| 261 | .Pp | 312 | .Pp |
| 262 | It is also possible to handle digits as option letters. | 313 | It is possible to handle digits as option letters. |
| 263 | This allows | 314 | This allows |
| 264 | .Fn getopt | 315 | .Fn getopt |
| 265 | to be used with programs that expect a number | 316 | to be used with programs that expect a number |
| 266 | .Pq Dq Li \&-\&3 | 317 | .Pq Dq Li \-3 |
| 267 | as an option. | 318 | as an option. |
| 268 | This practice is wrong, and should not be used in any current development. | 319 | This practice is wrong, and should not be used in any current development. |
| 269 | It is provided for backward compatibility | 320 | It is provided for backward compatibility |
