getopt_long.c revision 1.1 1 1.1 christos /* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */
2 1.1 christos /* $NetBSD: getopt_long.c,v 1.1 2020/03/03 00:11:47 christos Exp $ */
3 1.1 christos
4 1.1 christos /*
5 1.1 christos * Copyright (c) 2002 Todd C. Miller <Todd.Miller (at) courtesan.com>
6 1.1 christos *
7 1.1 christos * Permission to use, copy, modify, and distribute this software for any
8 1.1 christos * purpose with or without fee is hereby granted, provided that the above
9 1.1 christos * copyright notice and this permission notice appear in all copies.
10 1.1 christos *
11 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1 christos *
19 1.1 christos * Sponsored in part by the Defense Advanced Research Projects
20 1.1 christos * Agency (DARPA) and Air Force Research Laboratory, Air Force
21 1.1 christos * Materiel Command, USAF, under agreement number F39502-99-1-0512.
22 1.1 christos */
23 1.1 christos /*-
24 1.1 christos * Copyright (c) 2000 The NetBSD Foundation, Inc.
25 1.1 christos * All rights reserved.
26 1.1 christos *
27 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
28 1.1 christos * by Dieter Baron and Thomas Klausner.
29 1.1 christos *
30 1.1 christos * Redistribution and use in source and binary forms, with or without
31 1.1 christos * modification, are permitted provided that the following conditions
32 1.1 christos * are met:
33 1.1 christos * 1. Redistributions of source code must retain the above copyright
34 1.1 christos * notice, this list of conditions and the following disclaimer.
35 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
36 1.1 christos * notice, this list of conditions and the following disclaimer in the
37 1.1 christos * documentation and/or other materials provided with the distribution.
38 1.1 christos *
39 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
40 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
43 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
50 1.1 christos */
51 1.1 christos
52 1.1 christos /* OPENBSD ORIGINAL: lib/libc/stdlib/getopt_long.c */
53 1.1 christos #include "openbsd-compat.h"
54 1.1 christos
55 1.1 christos #if !defined(HAVE_GETOPT)
56 1.1 christos
57 1.1 christos #if 0
58 1.1 christos #include <err.h>
59 1.1 christos #include <getopt.h>
60 1.1 christos #endif
61 1.1 christos #include <errno.h>
62 1.1 christos #include <stdlib.h>
63 1.1 christos #include <string.h>
64 1.1 christos #include <stdarg.h>
65 1.1 christos
66 1.1 christos int opterr = 1; /* if error message should be printed */
67 1.1 christos int optind = 1; /* index into parent argv vector */
68 1.1 christos int optopt = '?'; /* character checked for validity */
69 1.1 christos int optreset; /* reset getopt */
70 1.1 christos char *optarg; /* argument associated with option */
71 1.1 christos
72 1.1 christos #define PRINT_ERROR ((opterr) && (*options != ':'))
73 1.1 christos
74 1.1 christos #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
75 1.1 christos #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
76 1.1 christos #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
77 1.1 christos
78 1.1 christos /* return values */
79 1.1 christos #define BADCH (int)'?'
80 1.1 christos #define BADARG ((*options == ':') ? (int)':' : (int)'?')
81 1.1 christos #define INORDER (int)1
82 1.1 christos
83 1.1 christos #define EMSG ""
84 1.1 christos
85 1.1 christos static int getopt_internal(int, char * const *, const char *,
86 1.1 christos const struct option *, int *, int);
87 1.1 christos static int parse_long_options(char * const *, const char *,
88 1.1 christos const struct option *, int *, int);
89 1.1 christos static int gcd(int, int);
90 1.1 christos static void permute_args(int, int, int, char * const *);
91 1.1 christos
92 1.1 christos static char *place = EMSG; /* option letter processing */
93 1.1 christos
94 1.1 christos /* XXX: set optreset to 1 rather than these two */
95 1.1 christos static int nonopt_start = -1; /* first non option argument (for permute) */
96 1.1 christos static int nonopt_end = -1; /* first option after non options (for permute) */
97 1.1 christos
98 1.1 christos /* Error messages */
99 1.1 christos static const char recargchar[] = "option requires an argument -- %c";
100 1.1 christos static const char recargstring[] = "option requires an argument -- %s";
101 1.1 christos static const char ambig[] = "ambiguous option -- %.*s";
102 1.1 christos static const char noarg[] = "option doesn't take an argument -- %.*s";
103 1.1 christos static const char illoptchar[] = "unknown option -- %c";
104 1.1 christos static const char illoptstring[] = "unknown option -- %s";
105 1.1 christos
106 1.1 christos /*
107 1.1 christos * Compute the greatest common divisor of a and b.
108 1.1 christos */
109 1.1 christos static int
110 1.1 christos gcd(int a, int b)
111 1.1 christos {
112 1.1 christos int c;
113 1.1 christos
114 1.1 christos c = a % b;
115 1.1 christos while (c != 0) {
116 1.1 christos a = b;
117 1.1 christos b = c;
118 1.1 christos c = a % b;
119 1.1 christos }
120 1.1 christos
121 1.1 christos return (b);
122 1.1 christos }
123 1.1 christos
124 1.1 christos /*
125 1.1 christos * Exchange the block from nonopt_start to nonopt_end with the block
126 1.1 christos * from nonopt_end to opt_end (keeping the same order of arguments
127 1.1 christos * in each block).
128 1.1 christos */
129 1.1 christos static void
130 1.1 christos permute_args(int panonopt_start, int panonopt_end, int opt_end,
131 1.1 christos char * const *nargv)
132 1.1 christos {
133 1.1 christos int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
134 1.1 christos char *swap;
135 1.1 christos
136 1.1 christos /*
137 1.1 christos * compute lengths of blocks and number and size of cycles
138 1.1 christos */
139 1.1 christos nnonopts = panonopt_end - panonopt_start;
140 1.1 christos nopts = opt_end - panonopt_end;
141 1.1 christos ncycle = gcd(nnonopts, nopts);
142 1.1 christos cyclelen = (opt_end - panonopt_start) / ncycle;
143 1.1 christos
144 1.1 christos for (i = 0; i < ncycle; i++) {
145 1.1 christos cstart = panonopt_end+i;
146 1.1 christos pos = cstart;
147 1.1 christos for (j = 0; j < cyclelen; j++) {
148 1.1 christos if (pos >= panonopt_end)
149 1.1 christos pos -= nnonopts;
150 1.1 christos else
151 1.1 christos pos += nopts;
152 1.1 christos swap = nargv[pos];
153 1.1 christos /* LINTED const cast */
154 1.1 christos ((char **) nargv)[pos] = nargv[cstart];
155 1.1 christos /* LINTED const cast */
156 1.1 christos ((char **)nargv)[cstart] = swap;
157 1.1 christos }
158 1.1 christos }
159 1.1 christos }
160 1.1 christos
161 1.1 christos /*
162 1.1 christos * parse_long_options --
163 1.1 christos * Parse long options in argc/argv argument vector.
164 1.1 christos * Returns -1 if short_too is set and the option does not match long_options.
165 1.1 christos */
166 1.1 christos static int
167 1.1 christos parse_long_options(char * const *nargv, const char *options,
168 1.1 christos const struct option *long_options, int *idx, int short_too)
169 1.1 christos {
170 1.1 christos char *current_argv, *has_equal;
171 1.1 christos size_t current_argv_len;
172 1.1 christos int i, match;
173 1.1 christos
174 1.1 christos current_argv = place;
175 1.1 christos match = -1;
176 1.1 christos
177 1.1 christos optind++;
178 1.1 christos
179 1.1 christos if ((has_equal = strchr(current_argv, '=')) != NULL) {
180 1.1 christos /* argument found (--option=arg) */
181 1.1 christos current_argv_len = has_equal - current_argv;
182 1.1 christos has_equal++;
183 1.1 christos } else
184 1.1 christos current_argv_len = strlen(current_argv);
185 1.1 christos
186 1.1 christos for (i = 0; long_options[i].name; i++) {
187 1.1 christos /* find matching long option */
188 1.1 christos if (strncmp(current_argv, long_options[i].name,
189 1.1 christos current_argv_len))
190 1.1 christos continue;
191 1.1 christos
192 1.1 christos if (strlen(long_options[i].name) == current_argv_len) {
193 1.1 christos /* exact match */
194 1.1 christos match = i;
195 1.1 christos break;
196 1.1 christos }
197 1.1 christos /*
198 1.1 christos * If this is a known short option, don't allow
199 1.1 christos * a partial match of a single character.
200 1.1 christos */
201 1.1 christos if (short_too && current_argv_len == 1)
202 1.1 christos continue;
203 1.1 christos
204 1.1 christos if (match == -1) /* partial match */
205 1.1 christos match = i;
206 1.1 christos else {
207 1.1 christos /* ambiguous abbreviation */
208 1.1 christos if (PRINT_ERROR)
209 1.1 christos warnx(ambig, (int)current_argv_len,
210 1.1 christos current_argv);
211 1.1 christos optopt = 0;
212 1.1 christos return (BADCH);
213 1.1 christos }
214 1.1 christos }
215 1.1 christos if (match != -1) { /* option found */
216 1.1 christos if (long_options[match].has_arg == no_argument
217 1.1 christos && has_equal) {
218 1.1 christos if (PRINT_ERROR)
219 1.1 christos warnx(noarg, (int)current_argv_len,
220 1.1 christos current_argv);
221 1.1 christos /*
222 1.1 christos * XXX: GNU sets optopt to val regardless of flag
223 1.1 christos */
224 1.1 christos if (long_options[match].flag == NULL)
225 1.1 christos optopt = long_options[match].val;
226 1.1 christos else
227 1.1 christos optopt = 0;
228 1.1 christos return (BADARG);
229 1.1 christos }
230 1.1 christos if (long_options[match].has_arg == required_argument ||
231 1.1 christos long_options[match].has_arg == optional_argument) {
232 1.1 christos if (has_equal)
233 1.1 christos optarg = has_equal;
234 1.1 christos else if (long_options[match].has_arg ==
235 1.1 christos required_argument) {
236 1.1 christos /*
237 1.1 christos * optional argument doesn't use next nargv
238 1.1 christos */
239 1.1 christos optarg = nargv[optind++];
240 1.1 christos }
241 1.1 christos }
242 1.1 christos if ((long_options[match].has_arg == required_argument)
243 1.1 christos && (optarg == NULL)) {
244 1.1 christos /*
245 1.1 christos * Missing argument; leading ':' indicates no error
246 1.1 christos * should be generated.
247 1.1 christos */
248 1.1 christos if (PRINT_ERROR)
249 1.1 christos warnx(recargstring,
250 1.1 christos current_argv);
251 1.1 christos /*
252 1.1 christos * XXX: GNU sets optopt to val regardless of flag
253 1.1 christos */
254 1.1 christos if (long_options[match].flag == NULL)
255 1.1 christos optopt = long_options[match].val;
256 1.1 christos else
257 1.1 christos optopt = 0;
258 1.1 christos --optind;
259 1.1 christos return (BADARG);
260 1.1 christos }
261 1.1 christos } else { /* unknown option */
262 1.1 christos if (short_too) {
263 1.1 christos --optind;
264 1.1 christos return (-1);
265 1.1 christos }
266 1.1 christos if (PRINT_ERROR)
267 1.1 christos warnx(illoptstring, current_argv);
268 1.1 christos optopt = 0;
269 1.1 christos return (BADCH);
270 1.1 christos }
271 1.1 christos if (idx)
272 1.1 christos *idx = match;
273 1.1 christos if (long_options[match].flag) {
274 1.1 christos *long_options[match].flag = long_options[match].val;
275 1.1 christos return (0);
276 1.1 christos } else
277 1.1 christos return (long_options[match].val);
278 1.1 christos }
279 1.1 christos
280 1.1 christos /*
281 1.1 christos * getopt_internal --
282 1.1 christos * Parse argc/argv argument vector. Called by user level routines.
283 1.1 christos */
284 1.1 christos static int
285 1.1 christos getopt_internal(int nargc, char * const *nargv, const char *options,
286 1.1 christos const struct option *long_options, int *idx, int flags)
287 1.1 christos {
288 1.1 christos char *oli; /* option letter list index */
289 1.1 christos int optchar, short_too;
290 1.1 christos static int posixly_correct = -1;
291 1.1 christos
292 1.1 christos if (options == NULL)
293 1.1 christos return (-1);
294 1.1 christos
295 1.1 christos /*
296 1.1 christos * XXX Some GNU programs (like cvs) set optind to 0 instead of
297 1.1 christos * XXX using optreset. Work around this braindamage.
298 1.1 christos */
299 1.1 christos if (optind == 0)
300 1.1 christos optind = optreset = 1;
301 1.1 christos
302 1.1 christos /*
303 1.1 christos * Disable GNU extensions if POSIXLY_CORRECT is set or options
304 1.1 christos * string begins with a '+'.
305 1.1 christos */
306 1.1 christos if (posixly_correct == -1 || optreset)
307 1.1 christos posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
308 1.1 christos if (*options == '-')
309 1.1 christos flags |= FLAG_ALLARGS;
310 1.1 christos else if (posixly_correct || *options == '+')
311 1.1 christos flags &= ~FLAG_PERMUTE;
312 1.1 christos if (*options == '+' || *options == '-')
313 1.1 christos options++;
314 1.1 christos
315 1.1 christos optarg = NULL;
316 1.1 christos if (optreset)
317 1.1 christos nonopt_start = nonopt_end = -1;
318 1.1 christos start:
319 1.1 christos if (optreset || !*place) { /* update scanning pointer */
320 1.1 christos optreset = 0;
321 1.1 christos if (optind >= nargc) { /* end of argument vector */
322 1.1 christos place = EMSG;
323 1.1 christos if (nonopt_end != -1) {
324 1.1 christos /* do permutation, if we have to */
325 1.1 christos permute_args(nonopt_start, nonopt_end,
326 1.1 christos optind, nargv);
327 1.1 christos optind -= nonopt_end - nonopt_start;
328 1.1 christos }
329 1.1 christos else if (nonopt_start != -1) {
330 1.1 christos /*
331 1.1 christos * If we skipped non-options, set optind
332 1.1 christos * to the first of them.
333 1.1 christos */
334 1.1 christos optind = nonopt_start;
335 1.1 christos }
336 1.1 christos nonopt_start = nonopt_end = -1;
337 1.1 christos return (-1);
338 1.1 christos }
339 1.1 christos if (*(place = nargv[optind]) != '-' ||
340 1.1 christos (place[1] == '\0' && strchr(options, '-') == NULL)) {
341 1.1 christos place = EMSG; /* found non-option */
342 1.1 christos if (flags & FLAG_ALLARGS) {
343 1.1 christos /*
344 1.1 christos * GNU extension:
345 1.1 christos * return non-option as argument to option 1
346 1.1 christos */
347 1.1 christos optarg = nargv[optind++];
348 1.1 christos return (INORDER);
349 1.1 christos }
350 1.1 christos if (!(flags & FLAG_PERMUTE)) {
351 1.1 christos /*
352 1.1 christos * If no permutation wanted, stop parsing
353 1.1 christos * at first non-option.
354 1.1 christos */
355 1.1 christos return (-1);
356 1.1 christos }
357 1.1 christos /* do permutation */
358 1.1 christos if (nonopt_start == -1)
359 1.1 christos nonopt_start = optind;
360 1.1 christos else if (nonopt_end != -1) {
361 1.1 christos permute_args(nonopt_start, nonopt_end,
362 1.1 christos optind, nargv);
363 1.1 christos nonopt_start = optind -
364 1.1 christos (nonopt_end - nonopt_start);
365 1.1 christos nonopt_end = -1;
366 1.1 christos }
367 1.1 christos optind++;
368 1.1 christos /* process next argument */
369 1.1 christos goto start;
370 1.1 christos }
371 1.1 christos if (nonopt_start != -1 && nonopt_end == -1)
372 1.1 christos nonopt_end = optind;
373 1.1 christos
374 1.1 christos /*
375 1.1 christos * If we have "-" do nothing, if "--" we are done.
376 1.1 christos */
377 1.1 christos if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
378 1.1 christos optind++;
379 1.1 christos place = EMSG;
380 1.1 christos /*
381 1.1 christos * We found an option (--), so if we skipped
382 1.1 christos * non-options, we have to permute.
383 1.1 christos */
384 1.1 christos if (nonopt_end != -1) {
385 1.1 christos permute_args(nonopt_start, nonopt_end,
386 1.1 christos optind, nargv);
387 1.1 christos optind -= nonopt_end - nonopt_start;
388 1.1 christos }
389 1.1 christos nonopt_start = nonopt_end = -1;
390 1.1 christos return (-1);
391 1.1 christos }
392 1.1 christos }
393 1.1 christos
394 1.1 christos /*
395 1.1 christos * Check long options if:
396 1.1 christos * 1) we were passed some
397 1.1 christos * 2) the arg is not just "-"
398 1.1 christos * 3) either the arg starts with -- we are getopt_long_only()
399 1.1 christos */
400 1.1 christos if (long_options != NULL && place != nargv[optind] &&
401 1.1 christos (*place == '-' || (flags & FLAG_LONGONLY))) {
402 1.1 christos short_too = 0;
403 1.1 christos if (*place == '-')
404 1.1 christos place++; /* --foo long option */
405 1.1 christos else if (*place != ':' && strchr(options, *place) != NULL)
406 1.1 christos short_too = 1; /* could be short option too */
407 1.1 christos
408 1.1 christos optchar = parse_long_options(nargv, options, long_options,
409 1.1 christos idx, short_too);
410 1.1 christos if (optchar != -1) {
411 1.1 christos place = EMSG;
412 1.1 christos return (optchar);
413 1.1 christos }
414 1.1 christos }
415 1.1 christos
416 1.1 christos if ((optchar = (int)*place++) == (int)':' ||
417 1.1 christos (optchar == (int)'-' && *place != '\0') ||
418 1.1 christos (oli = strchr(options, optchar)) == NULL) {
419 1.1 christos /*
420 1.1 christos * If the user specified "-" and '-' isn't listed in
421 1.1 christos * options, return -1 (non-option) as per POSIX.
422 1.1 christos * Otherwise, it is an unknown option character (or ':').
423 1.1 christos */
424 1.1 christos if (optchar == (int)'-' && *place == '\0')
425 1.1 christos return (-1);
426 1.1 christos if (!*place)
427 1.1 christos ++optind;
428 1.1 christos if (PRINT_ERROR)
429 1.1 christos warnx(illoptchar, optchar);
430 1.1 christos optopt = optchar;
431 1.1 christos return (BADCH);
432 1.1 christos }
433 1.1 christos if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
434 1.1 christos /* -W long-option */
435 1.1 christos if (*place) /* no space */
436 1.1 christos /* NOTHING */;
437 1.1 christos else if (++optind >= nargc) { /* no arg */
438 1.1 christos place = EMSG;
439 1.1 christos if (PRINT_ERROR)
440 1.1 christos warnx(recargchar, optchar);
441 1.1 christos optopt = optchar;
442 1.1 christos return (BADARG);
443 1.1 christos } else /* white space */
444 1.1 christos place = nargv[optind];
445 1.1 christos optchar = parse_long_options(nargv, options, long_options,
446 1.1 christos idx, 0);
447 1.1 christos place = EMSG;
448 1.1 christos return (optchar);
449 1.1 christos }
450 1.1 christos if (*++oli != ':') { /* doesn't take argument */
451 1.1 christos if (!*place)
452 1.1 christos ++optind;
453 1.1 christos } else { /* takes (optional) argument */
454 1.1 christos optarg = NULL;
455 1.1 christos if (*place) /* no white space */
456 1.1 christos optarg = place;
457 1.1 christos else if (oli[1] != ':') { /* arg not optional */
458 1.1 christos if (++optind >= nargc) { /* no arg */
459 1.1 christos place = EMSG;
460 1.1 christos if (PRINT_ERROR)
461 1.1 christos warnx(recargchar, optchar);
462 1.1 christos optopt = optchar;
463 1.1 christos return (BADARG);
464 1.1 christos } else
465 1.1 christos optarg = nargv[optind];
466 1.1 christos }
467 1.1 christos place = EMSG;
468 1.1 christos ++optind;
469 1.1 christos }
470 1.1 christos /* dump back option letter */
471 1.1 christos return (optchar);
472 1.1 christos }
473 1.1 christos
474 1.1 christos /*
475 1.1 christos * getopt --
476 1.1 christos * Parse argc/argv argument vector.
477 1.1 christos *
478 1.1 christos * [eventually this will replace the BSD getopt]
479 1.1 christos */
480 1.1 christos int
481 1.1 christos getopt(int nargc, char * const *nargv, const char *options)
482 1.1 christos {
483 1.1 christos
484 1.1 christos /*
485 1.1 christos * We don't pass FLAG_PERMUTE to getopt_internal() since
486 1.1 christos * the BSD getopt(3) (unlike GNU) has never done this.
487 1.1 christos *
488 1.1 christos * Furthermore, since many privileged programs call getopt()
489 1.1 christos * before dropping privileges it makes sense to keep things
490 1.1 christos * as simple (and bug-free) as possible.
491 1.1 christos */
492 1.1 christos return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
493 1.1 christos }
494 1.1 christos
495 1.1 christos #if 0
496 1.1 christos /*
497 1.1 christos * getopt_long --
498 1.1 christos * Parse argc/argv argument vector.
499 1.1 christos */
500 1.1 christos int
501 1.1 christos getopt_long(int nargc, char * const *nargv, const char *options,
502 1.1 christos const struct option *long_options, int *idx)
503 1.1 christos {
504 1.1 christos
505 1.1 christos return (getopt_internal(nargc, nargv, options, long_options, idx,
506 1.1 christos FLAG_PERMUTE));
507 1.1 christos }
508 1.1 christos
509 1.1 christos /*
510 1.1 christos * getopt_long_only --
511 1.1 christos * Parse argc/argv argument vector.
512 1.1 christos */
513 1.1 christos int
514 1.1 christos getopt_long_only(int nargc, char * const *nargv, const char *options,
515 1.1 christos const struct option *long_options, int *idx)
516 1.1 christos {
517 1.1 christos
518 1.1 christos return (getopt_internal(nargc, nargv, options, long_options, idx,
519 1.1 christos FLAG_PERMUTE|FLAG_LONGONLY));
520 1.1 christos }
521 1.1 christos #endif
522 1.1 christos
523 1.1 christos #endif /* !defined(HAVE_GETOPT) */
524