Debian Codegraph @

templates/man3/getopt.3.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:25+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "getopt"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
28 #: opensuse-tumbleweed
29 #, no-wrap
30 msgid "2026-02-08"
31 msgstr ""
32
33 #. type: TH
34 #: archlinux debian-unstable
35 #, no-wrap
36 msgid "Linux man-pages 6.18"
37 msgstr ""
38
39 #. type: SH
40 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
41 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
42 #, no-wrap
43 msgid "NAME"
44 msgstr ""
45
46 #. type: Plain text
47 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
48 #: opensuse-tumbleweed
49 msgid "getopt, optarg, optind, opterr, optopt - Parse command-line options"
50 msgstr ""
51
52 #. type: SH
53 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
54 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
55 #, no-wrap
56 msgid "LIBRARY"
57 msgstr ""
58
59 #. type: Plain text
60 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
61 #: opensuse-leap-16-1 opensuse-tumbleweed
62 msgid "Standard C library (I<libc>,\\ I<-lc>)"
63 msgstr ""
64
65 #. type: SH
66 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
67 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
68 #, no-wrap
69 msgid "SYNOPSIS"
70 msgstr ""
71
72 #. type: Plain text
73 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
74 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
75 #, no-wrap
76 msgid "B<#include E<lt>unistd.hE<gt>>\n"
77 msgstr ""
78
79 #. type: Plain text
80 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
81 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
82 #, no-wrap
83 msgid ""
84 "B<int getopt(int >I<argc>B<, char *>I<argv>B<[],>\n"
85 "B< const char *>I<optstring>B<);>\n"
86 msgstr ""
87
88 #. type: Plain text
89 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
90 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
91 #, no-wrap
92 msgid ""
93 "B<extern char *>I<optarg>B<;>\n"
94 "B<extern int >I<optind>B<, >I<opterr>B<, >I<optopt>B<;>\n"
95 msgstr ""
96
97 #. type: Plain text
98 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
99 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
100 msgid ""
101 "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
102 msgstr ""
103
104 #. type: Plain text
105 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
106 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
107 msgid "B<getopt>():"
108 msgstr ""
109
110 #. type: Plain text
111 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
112 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
113 #, no-wrap
114 msgid " _POSIX_C_SOURCE E<gt>= 2 || _XOPEN_SOURCE\n"
115 msgstr ""
116
117 #. type: SH
118 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
119 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
120 #, no-wrap
121 msgid "DESCRIPTION"
122 msgstr ""
123
124 #. type: Plain text
125 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
126 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
127 msgid ""
128 "The B<getopt>() function parses the command-line arguments. Its arguments "
129 "I<argc> and I<argv> are the argument count and array as passed to the "
130 "I<main>() function on program invocation. An element of I<argv> that "
131 "starts with \\[aq]-\\[aq] (and is not exactly \"-\" or \"--\") is an option "
132 "element. The characters of this element (aside from the initial \\[aq]-\\"
133 "[aq]) are option characters. If B<getopt>() is called repeatedly, it "
134 "returns successively each of the option characters from each of the option "
135 "elements."
136 msgstr ""
137
138 #. type: Plain text
139 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
140 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
141 msgid ""
142 "The variable I<optind> is the index of the next element to be processed in "
143 "I<argv>. The system initializes this value to 1. The caller can reset it "
144 "to 1 to restart scanning of the same I<argv>, or when scanning a new "
145 "argument vector."
146 msgstr ""
147
148 #. type: Plain text
149 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
150 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
151 msgid ""
152 "If B<getopt>() finds another option character, it returns that character, "
153 "updating the external variable I<optind> and a static variable I<nextchar> "
154 "so that the next call to B<getopt>() can resume the scan with the following "
155 "option character or I<argv>-element."
156 msgstr ""
157
158 #. type: Plain text
159 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
160 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
161 msgid ""
162 "If there are no more option characters, B<getopt>() returns -1. Then "
163 "I<optind> is the index in I<argv> of the first I<argv>-element that is not "
164 "an option."
165 msgstr ""
166
167 #. type: Plain text
168 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
169 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
170 msgid ""
171 "I<optstring> is a string containing the legitimate option characters. A "
172 "legitimate option character is any visible one byte B<ascii>(7) character "
173 "(for which B<isgraph>(3) would return nonzero) that is not \\[aq]-\\[aq], \\"
174 "[aq]:\\[aq], or \\[aq];\\[aq]. If such a character is followed by a colon, "
175 "the option requires an argument, so B<getopt>() places a pointer to the "
176 "following text in the same I<argv>-element, or the text of the following "
177 "I<argv>-element, in I<optarg>. Two colons mean an option takes an optional "
178 "arg; if there is text in the current I<argv>-element (i.e., in the same word "
179 "as the option name itself, for example, \"-oarg\"), then it is returned in "
180 "I<optarg>, otherwise I<optarg> is set to zero. This is a GNU extension. If "
181 "I<optstring> contains B<W> followed by a semicolon, then B<-W foo> is "
182 "treated as the long option B<--foo>. (The B<-W> option is reserved by "
183 "POSIX.2 for implementation extensions.) This behavior is a GNU extension, "
184 "not available with libraries before glibc 2."
185 msgstr ""
186
187 #. type: Plain text
188 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
189 #: opensuse-tumbleweed
190 msgid ""
191 "By default, B<getopt>() permutes the contents of I<argv> as it scans, so "
192 "that eventually all the nonoptions are at the end. Two other scanning modes "
193 "are also implemented. If the first character of I<optstring> is \\[aq]+\\"
194 "[aq] or the environment variable B<\\%POSIXLY_CORRECT> is set, then option "
195 "processing stops as soon as a nonoption argument is encountered. If \\[aq]+"
196 "\\[aq] is not the first character of I<optstring>, it is treated as a normal "
197 "option. If B<\\%POSIXLY_CORRECT> behavior is required in this case "
198 "I<optstring> will contain two \\[aq]+\\[aq] symbols. If the first character "
199 "of I<optstring> is \\[aq]-\\[aq], then each nonoption I<argv>-element is "
200 "handled as if it were the argument of an option with character code 1. "
201 "(This is used by programs that were written to expect options and other "
202 "I<argv>-elements in any order and that care about the ordering of the two.) "
203 "The special argument \"--\" forces an end of option-scanning regardless of "
204 "the scanning mode."
205 msgstr ""
206
207 #. type: Plain text
208 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
209 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
210 msgid ""
211 "While processing the option list, B<getopt>() can detect two kinds of "
212 "errors: (1) an option character that was not specified in I<optstring> and "
213 "(2) a missing option argument (i.e., an option at the end of the command "
214 "line without an expected argument). Such errors are handled and reported as "
215 "follows:"
216 msgstr ""
217
218 #. type: IP
219 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
220 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
221 #, no-wrap
222 msgid "\\[bu]"
223 msgstr ""
224
225 #. type: Plain text
226 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
227 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
228 msgid ""
229 "By default, B<getopt>() prints an error message on standard error, places "
230 "the erroneous option character in I<optopt>, and returns \\[aq]?\\[aq] as "
231 "the function result."
232 msgstr ""
233
234 #. type: Plain text
235 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
236 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
237 msgid ""
238 "If the caller has set the global variable I<opterr> to zero, then "
239 "B<getopt>() does not print an error message. The caller can determine that "
240 "there was an error by testing whether the function return value is \\[aq]?\\"
241 "[aq]. (By default, I<opterr> has a nonzero value.)"
242 msgstr ""
243
244 #. type: Plain text
245 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
246 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
247 msgid ""
248 "If the first character (following any optional \\[aq]+\\[aq] or \\[aq]-\\"
249 "[aq] described above) of I<optstring> is a colon (\\[aq]:\\[aq]), then "
250 "B<getopt>() likewise does not print an error message. In addition, it "
251 "returns \\[aq]:\\[aq] instead of \\[aq]?\\[aq] to indicate a missing option "
252 "argument. This allows the caller to distinguish the two different types of "
253 "errors."
254 msgstr ""
255
256 #. type: SH
257 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
258 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
259 #, no-wrap
260 msgid "RETURN VALUE"
261 msgstr ""
262
263 #. type: Plain text
264 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
265 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
266 msgid ""
267 "If an option was successfully found, then B<getopt>() returns the option "
268 "character. If all command-line options have been parsed, then B<getopt>() "
269 "returns -1. If B<getopt>() encounters an option character that was not in "
270 "I<optstring>, then \\[aq]?\\[aq] is returned. If B<getopt>() encounters an "
271 "option with a missing argument, then the return value depends on the first "
272 "character in I<optstring>: if it is \\[aq]:\\[aq], then \\[aq]:\\[aq] is "
273 "returned; otherwise \\[aq]?\\[aq] is returned."
274 msgstr ""
275
276 #. type: SH
277 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
278 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
279 #, no-wrap
280 msgid "ENVIRONMENT"
281 msgstr ""
282
283 #. type: TP
284 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
285 #: opensuse-tumbleweed
286 #, no-wrap
287 msgid "B<\\%POSIXLY_CORRECT>"
288 msgstr ""
289
290 #. type: Plain text
291 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
292 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
293 msgid ""
294 "If this is set, then option processing stops as soon as a nonoption argument "
295 "is encountered."
296 msgstr ""
297
298 #. type: SH
299 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
300 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
301 #, no-wrap
302 msgid "ATTRIBUTES"
303 msgstr ""
304
305 #. type: Plain text
306 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
307 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
308 msgid ""
309 "For an explanation of the terms used in this section, see B<attributes>(7)."
310 msgstr ""
311
312 #. type: tbl table
313 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
314 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
315 #, no-wrap
316 msgid "Interface"
317 msgstr ""
318
319 #. type: tbl table
320 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
321 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
322 #, no-wrap
323 msgid "Attribute"
324 msgstr ""
325
326 #. type: tbl table
327 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
328 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
329 #, no-wrap
330 msgid "Value"
331 msgstr ""
332
333 #. type: tbl table
334 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
335 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
336 #, no-wrap
337 msgid ".na\n"
338 msgstr ""
339
340 #. type: tbl table
341 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
342 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
343 #, no-wrap
344 msgid ".nh\n"
345 msgstr ""
346
347 #. type: TP
348 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
349 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
350 #, no-wrap
351 msgid "B<getopt>()"
352 msgstr ""
353
354 #. type: tbl table
355 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
356 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
357 #, no-wrap
358 msgid "Thread safety"
359 msgstr ""
360
361 #. type: tbl table
362 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
363 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
364 #, no-wrap
365 msgid "MT-Unsafe race:getopt env"
366 msgstr ""
367
368 #. type: SH
369 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
370 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
371 #, no-wrap
372 msgid "VERSIONS"
373 msgstr ""
374
375 #. type: Plain text
376 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
377 #: opensuse-tumbleweed
378 msgid ""
379 "POSIX specifies that the I<argv> array argument should be I<const>, but "
380 "these functions permute its elements unless the environment variable B<\\"
381 "%POSIXLY_CORRECT> is set. I<const> is used in the actual prototype to be "
382 "compatible with other systems; however, this page doesn't show the "
383 "qualifier, to avoid confusing readers."
384 msgstr ""
385
386 #. type: SH
387 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
388 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
389 #, no-wrap
390 msgid "STANDARDS"
391 msgstr ""
392
393 #. type: Plain text
394 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
395 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
396 msgid "POSIX.1-2008."
397 msgstr ""
398
399 #. type: Plain text
400 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
401 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
402 msgid ""
403 "The use of \\[aq]+\\[aq] and \\[aq]-\\[aq] in I<optstring> is a GNU "
404 "extension."
405 msgstr ""
406
407 #. type: SH
408 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
409 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
410 #, no-wrap
411 msgid "HISTORY"
412 msgstr ""
413
414 #. type: Plain text
415 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
416 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
417 msgid "POSIX.1-2001, and POSIX.2."
418 msgstr ""
419
420 #. type: Plain text
421 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
422 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
423 msgid ""
424 "On some older implementations, B<getopt>() was declared in "
425 "I<E<lt>stdio.hE<gt>>. SUSv1 permitted the declaration to appear in either "
426 "I<E<lt>unistd.hE<gt>> or I<E<lt>stdio.hE<gt>>. POSIX.1-1996 marked the use "
427 "of I<E<lt>stdio.hE<gt>> for this purpose as LEGACY. POSIX.1-2001 does not "
428 "require the declaration to appear in I<E<lt>stdio.hE<gt>>."
429 msgstr ""
430
431 #. type: Plain text
432 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
433 #: opensuse-tumbleweed
434 msgid ""
435 "Very old versions of glibc were affected by a E<.UR https:\\://"
436 "\\:sourceware.org/\\:git/\\:?"
437 "p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05> B<\\"
438 "%_>I<PID>B<_GNU_nonoption_argv_flags_> environment variable E<.UE .>"
439 msgstr ""
440
441 #. type: SH
442 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
443 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
444 #, no-wrap
445 msgid "NOTES"
446 msgstr ""
447
448 #. type: Plain text
449 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
450 #: opensuse-tumbleweed
451 msgid ""
452 "A program that scans multiple argument vectors, or rescans the same vector "
453 "more than once, and wants to make use of GNU extensions such as \\[aq]+\\"
454 "[aq] and \\[aq]-\\[aq] at the start of I<optstring>, or changes the value of "
455 "B<\\%POSIXLY_CORRECT> between scans, must reinitialize B<getopt>() by "
456 "resetting I<optind> to 0, rather than the traditional value of 1. "
457 "(Resetting to 0 forces the invocation of an internal initialization routine "
458 "that rechecks B<\\%POSIXLY_CORRECT> and checks for GNU extensions in "
459 "I<optstring>.)"
460 msgstr ""
461
462 #. type: Plain text
463 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
464 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
465 msgid ""
466 "Command-line arguments are parsed in strict order meaning that an option "
467 "requiring an argument will consume the next argument, regardless of whether "
468 "that argument is the correctly specified option argument or simply the next "
469 "option (in the scenario the user mis-specifies the command line). For "
470 "example, if I<optstring> is specified as \"1n:\" and the user specifies the "
471 "command line arguments incorrectly as I<prog\\ -n\\ -1>, the I<-n> option "
472 "will be given the B<optarg> value \"-1\", and the I<-1> option will be "
473 "considered to have not been specified."
474 msgstr ""
475
476 #. type: SH
477 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
478 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
479 #, no-wrap
480 msgid "EXAMPLES"
481 msgstr ""
482
483 #. type: SS
484 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
485 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
486 #, no-wrap
487 msgid "getopt()"
488 msgstr ""
489
490 #. type: Plain text
491 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
492 #: opensuse-tumbleweed
493 msgid ""
494 "The following trivial example program uses B<getopt>() to handle two "
495 "program options: I<-n>, with no associated value; and I<-t\\ val>, which "
496 "expects an associated value."
497 msgstr ""
498
499 #. type: Plain text
500 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
501 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
502 #, no-wrap
503 msgid ""
504 "#include E<lt>stdio.hE<gt>\n"
505 "#include E<lt>stdlib.hE<gt>\n"
506 "#include E<lt>unistd.hE<gt>\n"
507 "\\&\n"
508 "int\n"
509 "main(int argc, char *argv[])\n"
510 "{\n"
511 " int flags, opt;\n"
512 " int nsecs, tfnd;\n"
513 "\\&\n"
514 " nsecs = 0;\n"
515 " tfnd = 0;\n"
516 " flags = 0;\n"
517 " while ((opt = getopt(argc, argv, \"nt:\")) != -1) {\n"
518 " switch (opt) {\n"
519 " case \\[aq]n\\[aq]:\n"
520 " flags = 1;\n"
521 " break;\n"
522 " case \\[aq]t\\[aq]:\n"
523 " nsecs = atoi(optarg);\n"
524 " tfnd = 1;\n"
525 " break;\n"
526 " default: /* \\[aq]?\\[aq] */\n"
527 " fprintf(stderr, \"Usage: %s [-t nsecs] [-n] name\\[rs]n\",\n"
528 " argv[0]);\n"
529 " exit(EXIT_FAILURE);\n"
530 " }\n"
531 " }\n"
532 "\\&\n"
533 " printf(\"flags=%d; tfnd=%d; nsecs=%d; optind=%d\\[rs]n\",\n"
534 " flags, tfnd, nsecs, optind);\n"
535 "\\&\n"
536 " if (optind E<gt>= argc) {\n"
537 " fprintf(stderr, \"Expected argument after options\\[rs]n\");\n"
538 " exit(EXIT_FAILURE);\n"
539 " }\n"
540 "\\&\n"
541 " printf(\"name argument = %s\\[rs]n\", argv[optind]);\n"
542 "\\&\n"
543 " /* Other code omitted */\n"
544 "\\&\n"
545 " exit(EXIT_SUCCESS);\n"
546 "}\n"
547 msgstr ""
548
549 #. SRC END
550 #. type: SH
551 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
552 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
553 #, no-wrap
554 msgid "SEE ALSO"
555 msgstr ""
556
557 #. type: Plain text
558 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
559 #: opensuse-tumbleweed
560 msgid ""
561 "B<getopt>(1), B<getopt_long>(3), B<getopt_long_only>(3), B<getsubopt>(3)"
562 msgstr ""
563
564 #. type: TH
565 #: debian-trixie
566 #, no-wrap
567 msgid "2024-06-15"
568 msgstr ""
569
570 #. type: TH
571 #: debian-trixie
572 #, no-wrap
573 msgid "Linux man-pages 6.9.1"
574 msgstr ""
575
576 #. type: Plain text
577 #: debian-trixie fedora-44 fedora-rawhide
578 msgid ""
579 "getopt, getopt_long, getopt_long_only, optarg, optind, opterr, optopt - "
580 "Parse command-line options"
581 msgstr ""
582
583 #. type: Plain text
584 #: debian-trixie
585 msgid "Standard C library (I<libc>, I<-lc>)"
586 msgstr ""
587
588 #. type: Plain text
589 #: debian-trixie fedora-44 fedora-rawhide
590 #, no-wrap
591 msgid "B<#include E<lt>getopt.hE<gt>>\n"
592 msgstr ""
593
594 #. type: Plain text
595 #: debian-trixie fedora-44 fedora-rawhide
596 #, no-wrap
597 msgid ""
598 "B<int getopt_long(int >I<argc>B<, char *>I<argv>B<[],>\n"
599 "B< const char *>I<optstring>B<,>\n"
600 "B< const struct option *>I<longopts>B<, int *>I<longindex>B<);>\n"
601 "B<int getopt_long_only(int >I<argc>B<, char *>I<argv>B<[],>\n"
602 "B< const char *>I<optstring>B<,>\n"
603 "B< const struct option *>I<longopts>B<, int *>I<longindex>B<);>\n"
604 msgstr ""
605
606 #. type: Plain text
607 #: debian-trixie fedora-44 fedora-rawhide
608 msgid "B<getopt_long>(), B<getopt_long_only>():"
609 msgstr ""
610
611 #. type: Plain text
612 #: debian-trixie fedora-44 fedora-rawhide
613 #, no-wrap
614 msgid " _GNU_SOURCE\n"
615 msgstr ""
616
617 #. type: Plain text
618 #: debian-trixie fedora-44 fedora-rawhide
619 msgid ""
620 "By default, B<getopt>() permutes the contents of I<argv> as it scans, so "
621 "that eventually all the nonoptions are at the end. Two other scanning modes "
622 "are also implemented. If the first character of I<optstring> is \\[aq]+\\"
623 "[aq] or the environment variable B<POSIXLY_CORRECT> is set, then option "
624 "processing stops as soon as a nonoption argument is encountered. If \\[aq]+"
625 "\\[aq] is not the first character of I<optstring>, it is treated as a normal "
626 "option. If B<POSIXLY_CORRECT> behaviour is required in this case "
627 "I<optstring> will contain two \\[aq]+\\[aq] symbols. If the first character "
628 "of I<optstring> is \\[aq]-\\[aq], then each nonoption I<argv>-element is "
629 "handled as if it were the argument of an option with character code 1. "
630 "(This is used by programs that were written to expect options and other "
631 "I<argv>-elements in any order and that care about the ordering of the two.) "
632 "The special argument \"--\" forces an end of option-scanning regardless of "
633 "the scanning mode."
634 msgstr ""
635
636 #. type: SS
637 #: debian-trixie fedora-44 fedora-rawhide
638 #, no-wrap
639 msgid "getopt_long() and getopt_long_only()"
640 msgstr ""
641
642 #. type: Plain text
643 #: debian-trixie fedora-44 fedora-rawhide
644 msgid ""
645 "The B<getopt_long>() function works like B<getopt>() except that it also "
646 "accepts long options, started with two dashes. (If the program accepts only "
647 "long options, then I<optstring> should be specified as an empty string "
648 "(\"\"), not NULL.) Long option names may be abbreviated if the abbreviation "
649 "is unique or is an exact match for some defined option. A long option may "
650 "take a parameter, of the form B<--arg=param> or B<--arg param>."
651 msgstr ""
652
653 #. type: Plain text
654 #: debian-trixie fedora-44 fedora-rawhide
655 msgid ""
656 "I<longopts> is a pointer to the first element of an array of I<struct "
657 "option> declared in I<E<lt>getopt.hE<gt>> as"
658 msgstr ""
659
660 #. type: Plain text
661 #: debian-trixie fedora-44 fedora-rawhide
662 #, no-wrap
663 msgid ""
664 "struct option {\n"
665 " const char *name;\n"
666 " int has_arg;\n"
667 " int *flag;\n"
668 " int val;\n"
669 "};\n"
670 msgstr ""
671
672 #. type: Plain text
673 #: debian-trixie fedora-44 fedora-rawhide
674 msgid "The meanings of the different fields are:"
675 msgstr ""
676
677 #. type: TP
678 #: debian-trixie fedora-44 fedora-rawhide
679 #, no-wrap
680 msgid "I<name>"
681 msgstr ""
682
683 #. type: Plain text
684 #: debian-trixie fedora-44 fedora-rawhide
685 msgid "is the name of the long option."
686 msgstr ""
687
688 #. type: TP
689 #: debian-trixie fedora-44 fedora-rawhide
690 #, no-wrap
691 msgid "I<has_arg>"
692 msgstr ""
693
694 #. type: Plain text
695 #: debian-trixie fedora-44 fedora-rawhide
696 msgid ""
697 "is: B<no_argument> (or 0) if the option does not take an argument; "
698 "B<required_argument> (or 1) if the option requires an argument; or "
699 "B<optional_argument> (or 2) if the option takes an optional argument."
700 msgstr ""
701
702 #. type: TP
703 #: debian-trixie fedora-44 fedora-rawhide
704 #, no-wrap
705 msgid "I<flag>"
706 msgstr ""
707
708 #. type: Plain text
709 #: debian-trixie fedora-44 fedora-rawhide
710 msgid ""
711 "specifies how results are returned for a long option. If I<flag> is NULL, "
712 "then B<getopt_long>() returns I<val>. (For example, the calling program "
713 "may set I<val> to the equivalent short option character.) Otherwise, "
714 "B<getopt_long>() returns 0, and I<flag> points to a variable which is set "
715 "to I<val> if the option is found, but left unchanged if the option is not "
716 "found."
717 msgstr ""
718
719 #. type: TP
720 #: debian-trixie fedora-44 fedora-rawhide
721 #, no-wrap
722 msgid "I<val>"
723 msgstr ""
724
725 #. type: Plain text
726 #: debian-trixie fedora-44 fedora-rawhide
727 msgid ""
728 "is the value to return, or to load into the variable pointed to by I<flag>."
729 msgstr ""
730
731 #. type: Plain text
732 #: debian-trixie fedora-44 fedora-rawhide
733 msgid "The last element of the array has to be filled with zeros."
734 msgstr ""
735
736 #. type: Plain text
737 #: debian-trixie fedora-44 fedora-rawhide
738 msgid ""
739 "If I<longindex> is not NULL, it points to a variable which is set to the "
740 "index of the long option relative to I<longopts>."
741 msgstr ""
742
743 #. type: Plain text
744 #: debian-trixie fedora-44 fedora-rawhide
745 msgid ""
746 "B<getopt_long_only>() is like B<getopt_long>(), but \\[aq]-\\[aq] as well "
747 "as \"--\" can indicate a long option. If an option that starts with \\[aq]-"
748 "\\[aq] (not \"--\") doesn't match a long option, but does match a short "
749 "option, it is parsed as a short option instead."
750 msgstr ""
751
752 #. type: Plain text
753 #: debian-trixie fedora-44 fedora-rawhide
754 msgid ""
755 "B<getopt_long>() and B<getopt_long_only>() also return the option "
756 "character when a short option is recognized. For a long option, they return "
757 "I<val> if I<flag> is NULL, and 0 otherwise. Error and -1 returns are the "
758 "same as for B<getopt>(), plus \\[aq]?\\[aq] for an ambiguous match or an "
759 "extraneous parameter."
760 msgstr ""
761
762 #. type: TP
763 #: debian-trixie fedora-44 fedora-rawhide
764 #, no-wrap
765 msgid "B<POSIXLY_CORRECT>"
766 msgstr ""
767
768 #. type: TP
769 #: debian-trixie
770 #, no-wrap
771 msgid "B<_E<lt>PIDE<gt>_GNU_nonoption_argv_flags_>"
772 msgstr ""
773
774 #. type: Plain text
775 #: debian-trixie
776 msgid ""
777 "This variable was used by B<bash>(1) 2.0 to communicate to glibc which "
778 "arguments are the results of wildcard expansion and so should not be "
779 "considered as options. This behavior was removed in B<bash>(1) 2.01, but "
780 "the support remains in glibc."
781 msgstr ""
782
783 #. type: tbl table
784 #: debian-trixie fedora-44 fedora-rawhide
785 #, no-wrap
786 msgid ""
787 "B<getopt>(),\n"
788 "B<getopt_long>(),\n"
789 "B<getopt_long_only>()"
790 msgstr ""
791
792 #. type: Plain text
793 #: debian-trixie fedora-44 fedora-rawhide
794 msgid ""
795 "POSIX specifies that the I<argv> array argument should be I<const>, but "
796 "these functions permute its elements unless the environment variable "
797 "B<POSIXLY_CORRECT> is set. I<const> is used in the actual prototype to be "
798 "compatible with other systems; however, this page doesn't show the "
799 "qualifier, to avoid confusing readers."
800 msgstr ""
801
802 #. type: TP
803 #: debian-trixie fedora-44 fedora-rawhide
804 #, no-wrap
805 msgid "B<getopt_long>()"
806 msgstr ""
807
808 #. type: TQ
809 #: debian-trixie fedora-44 fedora-rawhide
810 #, no-wrap
811 msgid "B<getopt_long_only>()"
812 msgstr ""
813
814 #. type: Plain text
815 #: debian-trixie fedora-44 fedora-rawhide
816 msgid "GNU."
817 msgstr ""
818
819 #. type: Plain text
820 #: debian-trixie fedora-44 fedora-rawhide
821 msgid ""
822 "A program that scans multiple argument vectors, or rescans the same vector "
823 "more than once, and wants to make use of GNU extensions such as \\[aq]+\\"
824 "[aq] and \\[aq]-\\[aq] at the start of I<optstring>, or changes the value of "
825 "B<POSIXLY_CORRECT> between scans, must reinitialize B<getopt>() by "
826 "resetting I<optind> to 0, rather than the traditional value of 1. "
827 "(Resetting to 0 forces the invocation of an internal initialization routine "
828 "that rechecks B<POSIXLY_CORRECT> and checks for GNU extensions in "
829 "I<optstring>.)"
830 msgstr ""
831
832 #. type: Plain text
833 #: debian-trixie fedora-44 fedora-rawhide
834 msgid ""
835 "The following trivial example program uses B<getopt>() to handle two "
836 "program options: I<-n>, with no associated value; and I<-t val>, which "
837 "expects an associated value."
838 msgstr ""
839
840 #. SRC END
841 #. type: SS
842 #: debian-trixie fedora-44 fedora-rawhide
843 #, no-wrap
844 msgid "getopt_long()"
845 msgstr ""
846
847 #. type: Plain text
848 #: debian-trixie fedora-44 fedora-rawhide
849 msgid ""
850 "The following example program illustrates the use of B<getopt_long>() with "
851 "most of its features."
852 msgstr ""
853
854 #. type: Plain text
855 #: debian-trixie fedora-44 fedora-rawhide
856 #, no-wrap
857 msgid ""
858 "#include E<lt>getopt.hE<gt>\n"
859 "#include E<lt>stdio.hE<gt> /* for printf */\n"
860 "#include E<lt>stdlib.hE<gt> /* for exit */\n"
861 "\\&\n"
862 "int\n"
863 "main(int argc, char *argv[])\n"
864 "{\n"
865 " int c;\n"
866 " int digit_optind = 0;\n"
867 "\\&\n"
868 " while (1) {\n"
869 " int this_option_optind = optind ? optind : 1;\n"
870 " int option_index = 0;\n"
871 " static struct option long_options[] = {\n"
872 " {\"add\", required_argument, 0, 0 },\n"
873 " {\"append\", no_argument, 0, 0 },\n"
874 " {\"delete\", required_argument, 0, 0 },\n"
875 " {\"verbose\", no_argument, 0, 0 },\n"
876 " {\"create\", required_argument, 0, \\[aq]c\\[aq]},\n"
877 " {\"file\", required_argument, 0, 0 },\n"
878 " {0, 0, 0, 0 }\n"
879 " };\n"
880 "\\&\n"
881 " c = getopt_long(argc, argv, \"abc:d:012\",\n"
882 " long_options, &option_index);\n"
883 " if (c == -1)\n"
884 " break;\n"
885 "\\&\n"
886 " switch (c) {\n"
887 " case 0:\n"
888 " printf(\"option %s\", long_options[option_index].name);\n"
889 " if (optarg)\n"
890 " printf(\" with arg %s\", optarg);\n"
891 " printf(\"\\[rs]n\");\n"
892 " break;\n"
893 "\\&\n"
894 " case \\[aq]0\\[aq]:\n"
895 " case \\[aq]1\\[aq]:\n"
896 " case \\[aq]2\\[aq]:\n"
897 " if (digit_optind != 0 && digit_optind != this_option_optind)\n"
898 " printf(\"digits occur in two different argv-elements.\\[rs]n\");\n"
899 " digit_optind = this_option_optind;\n"
900 " printf(\"option %c\\[rs]n\", c);\n"
901 " break;\n"
902 "\\&\n"
903 " case \\[aq]a\\[aq]:\n"
904 " printf(\"option a\\[rs]n\");\n"
905 " break;\n"
906 "\\&\n"
907 " case \\[aq]b\\[aq]:\n"
908 " printf(\"option b\\[rs]n\");\n"
909 " break;\n"
910 "\\&\n"
911 " case \\[aq]c\\[aq]:\n"
912 " printf(\"option c with value \\[aq]%s\\[aq]\\[rs]n\", optarg);\n"
913 " break;\n"
914 "\\&\n"
915 " case \\[aq]d\\[aq]:\n"
916 " printf(\"option d with value \\[aq]%s\\[aq]\\[rs]n\", optarg);\n"
917 " break;\n"
918 "\\&\n"
919 " case \\[aq]?\\[aq]:\n"
920 " break;\n"
921 "\\&\n"
922 " default:\n"
923 " printf(\"?? getopt returned character code 0%o ??\\[rs]n\", c);\n"
924 " }\n"
925 " }\n"
926 "\\&\n"
927 " if (optind E<lt> argc) {\n"
928 " printf(\"non-option ARGV-elements: \");\n"
929 " while (optind E<lt> argc)\n"
930 " printf(\"%s \", argv[optind++]);\n"
931 " printf(\"\\[rs]n\");\n"
932 " }\n"
933 "\\&\n"
934 " exit(EXIT_SUCCESS);\n"
935 "}\n"
936 msgstr ""
937
938 #. type: Plain text
939 #: debian-trixie fedora-44 fedora-rawhide
940 msgid "B<getopt>(1), B<getsubopt>(3)"
941 msgstr ""
942
943 #. type: TH
944 #: fedora-44 fedora-rawhide
945 #, no-wrap
946 msgid "2024-12-19"
947 msgstr ""
948
949 #. type: TH
950 #: fedora-44 fedora-rawhide
951 #, no-wrap
952 msgid "Linux man-pages 6.13"
953 msgstr ""
954
955 #. type: Plain text
956 #: fedora-44 fedora-rawhide
957 msgid ""
958 "Very old versions of glibc were affected by a E<.UR https://"
959 "\\:sourceware.org/\\:git/\\:?"
960 "p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05> "
961 "B<_>I<PID>B<_GNU_nonoption_argv_flags_> environment variable E<.UE .>"
962 msgstr ""
963
964 #. type: TH
965 #: mageia-cauldron
966 #, no-wrap
967 msgid "Linux man-pages 6.17"
968 msgstr ""
969
970 #. type: TH
971 #: opensuse-leap-16-1 opensuse-tumbleweed
972 #, no-wrap
973 msgid "Linux man-pages (unreleased)"
974 msgstr ""