475
476
if (longopts != NULL
476
477
&& (argv[d->optind][1] == '-'
477
|| (long_only && (argv[d->optind][2]
478
|| !strchr (optstring, argv[d->optind][1])))))
478
|| (long_only && (argv[d->optind][2]
479
|| !strchr (optstring, argv[d->optind][1])))))
482
unsigned int namelen;
481
483
const struct option *p;
482
484
const struct option *pfound = NULL;
487
const struct option *p;
488
struct option_list *next;
489
} *ambig_list = NULL;
485
491
int indfound = -1;
486
492
int option_index;
488
494
for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
496
namelen = nameend - d->__nextchar;
491
498
/* Test all long options for either exact match
492
or abbreviated matches. */
499
or abbreviated matches. */
493
500
for (p = longopts, option_index = 0; p->name; p++, option_index++)
494
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
496
if ((unsigned int) (nameend - d->__nextchar)
497
== (unsigned int) strlen (p->name))
499
/* Exact match found. */
501
indfound = option_index;
505
else if (pfound == NULL)
507
/* First nonexact match found. */
509
indfound = option_index;
512
|| pfound->has_arg != p->has_arg
513
|| pfound->flag != p->flag
514
|| pfound->val != p->val)
515
/* Second or later nonexact match found. */
501
if (!strncmp (p->name, d->__nextchar, namelen))
503
if (namelen == (unsigned int) strlen (p->name))
505
/* Exact match found. */
507
indfound = option_index;
511
else if (pfound == NULL)
513
/* First nonexact match found. */
515
indfound = option_index;
518
|| pfound->has_arg != p->has_arg
519
|| pfound->flag != p->flag
520
|| pfound->val != p->val)
522
/* Second or later nonexact match found. */
523
struct option_list *newp = malloc (sizeof (*newp));
525
newp->next = ambig_list;
530
if (ambig_list != NULL && !exact)
534
struct option_list first;
536
first.next = ambig_list;
523
539
#if defined _LIBC && defined USE_IN_LIBIO
526
if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
527
argv[0], argv[d->optind]) >= 0)
529
_IO_flockfile (stderr);
531
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
532
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
534
__fxprintf (NULL, "%s", buf);
536
((_IO_FILE *) stderr)->_flags2 = old_flags2;
537
_IO_funlockfile (stderr);
543
FILE *fp = open_memstream (&buf, &buflen);
547
_("%s: option '%s' is ambiguous; possibilities:"),
548
argv[0], argv[d->optind]);
552
fprintf (fp, " '--%s'", ambig_list->p->name);
553
ambig_list = ambig_list->next;
555
while (ambig_list != NULL);
557
fputc_unlocked ('\n', fp);
559
if (__builtin_expect (fclose (fp) != EOF, 1))
561
_IO_flockfile (stderr);
563
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
564
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
566
__fxprintf (NULL, "%s", buf);
568
((_IO_FILE *) stderr)->_flags2 = old_flags2;
569
_IO_funlockfile (stderr);
542
fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
543
argv[0], argv[d->optind]);
576
_("%s: option '%s' is ambiguous; possibilities:"),
577
argv[0], argv[d->optind]);
580
fprintf (stderr, " '--%s'", ambig_list->p->name);
581
ambig_list = ambig_list->next;
583
while (ambig_list != NULL);
585
fputc ('\n', stderr);
546
d->__nextchar += strlen (d->__nextchar);
588
d->__nextchar += strlen (d->__nextchar);
594
while (ambig_list != NULL)
596
struct option_list *pn = ambig_list->next;
552
601
if (pfound != NULL)
554
option_index = indfound;
558
/* Don't test has_arg with >, because some C compilers don't
559
allow it to be used on enums. */
561
d->optarg = nameend + 1;
566
#if defined _LIBC && defined USE_IN_LIBIO
571
if (argv[d->optind - 1][1] == '-')
574
#if defined _LIBC && defined USE_IN_LIBIO
575
n = __asprintf (&buf, _("\
576
%s: option `--%s' doesn't allow an argument\n"),
577
argv[0], pfound->name);
579
fprintf (stderr, _("\
580
%s: option `--%s' doesn't allow an argument\n"),
581
argv[0], pfound->name);
586
/* +option or -option */
587
#if defined _LIBC && defined USE_IN_LIBIO
588
n = __asprintf (&buf, _("\
589
%s: option `%c%s' doesn't allow an argument\n"),
590
argv[0], argv[d->optind - 1][0],
593
fprintf (stderr, _("\
594
%s: option `%c%s' doesn't allow an argument\n"),
595
argv[0], argv[d->optind - 1][0],
600
#if defined _LIBC && defined USE_IN_LIBIO
603
_IO_flockfile (stderr);
605
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
606
((_IO_FILE *) stderr)->_flags2
607
|= _IO_FLAGS2_NOTCANCEL;
609
__fxprintf (NULL, "%s", buf);
611
((_IO_FILE *) stderr)->_flags2 = old_flags2;
612
_IO_funlockfile (stderr);
619
d->__nextchar += strlen (d->__nextchar);
621
d->optopt = pfound->val;
625
else if (pfound->has_arg == 1)
627
if (d->optind < argc)
628
d->optarg = argv[d->optind++];
633
#if defined _LIBC && defined USE_IN_LIBIO
636
if (__asprintf (&buf, _("\
637
%s: option `%s' requires an argument\n"),
638
argv[0], argv[d->optind - 1]) >= 0)
640
_IO_flockfile (stderr);
642
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
643
((_IO_FILE *) stderr)->_flags2
644
|= _IO_FLAGS2_NOTCANCEL;
646
__fxprintf (NULL, "%s", buf);
648
((_IO_FILE *) stderr)->_flags2 = old_flags2;
649
_IO_funlockfile (stderr);
655
_("%s: option `%s' requires an argument\n"),
656
argv[0], argv[d->optind - 1]);
659
d->__nextchar += strlen (d->__nextchar);
660
d->optopt = pfound->val;
661
return optstring[0] == ':' ? ':' : '?';
664
d->__nextchar += strlen (d->__nextchar);
666
*longind = option_index;
669
*(pfound->flag) = pfound->val;
603
option_index = indfound;
607
/* Don't test has_arg with >, because some C compilers don't
608
allow it to be used on enums. */
610
d->optarg = nameend + 1;
615
#if defined _LIBC && defined USE_IN_LIBIO
620
if (argv[d->optind - 1][1] == '-')
623
#if defined _LIBC && defined USE_IN_LIBIO
624
n = __asprintf (&buf, _("\
625
%s: option '--%s' doesn't allow an argument\n"),
626
argv[0], pfound->name);
628
fprintf (stderr, _("\
629
%s: option '--%s' doesn't allow an argument\n"),
630
argv[0], pfound->name);
635
/* +option or -option */
636
#if defined _LIBC && defined USE_IN_LIBIO
637
n = __asprintf (&buf, _("\
638
%s: option '%c%s' doesn't allow an argument\n"),
639
argv[0], argv[d->optind - 1][0],
642
fprintf (stderr, _("\
643
%s: option '%c%s' doesn't allow an argument\n"),
644
argv[0], argv[d->optind - 1][0],
649
#if defined _LIBC && defined USE_IN_LIBIO
652
_IO_flockfile (stderr);
654
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
655
((_IO_FILE *) stderr)->_flags2
656
|= _IO_FLAGS2_NOTCANCEL;
658
__fxprintf (NULL, "%s", buf);
660
((_IO_FILE *) stderr)->_flags2 = old_flags2;
661
_IO_funlockfile (stderr);
668
d->__nextchar += strlen (d->__nextchar);
670
d->optopt = pfound->val;
674
else if (pfound->has_arg == 1)
676
if (d->optind < argc)
677
d->optarg = argv[d->optind++];
682
#if defined _LIBC && defined USE_IN_LIBIO
685
if (__asprintf (&buf, _("\
686
%s: option '--%s' requires an argument\n"),
687
argv[0], pfound->name) >= 0)
689
_IO_flockfile (stderr);
691
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
692
((_IO_FILE *) stderr)->_flags2
693
|= _IO_FLAGS2_NOTCANCEL;
695
__fxprintf (NULL, "%s", buf);
697
((_IO_FILE *) stderr)->_flags2 = old_flags2;
698
_IO_funlockfile (stderr);
704
_("%s: option '--%s' requires an argument\n"),
705
argv[0], pfound->name);
708
d->__nextchar += strlen (d->__nextchar);
709
d->optopt = pfound->val;
710
return optstring[0] == ':' ? ':' : '?';
713
d->__nextchar += strlen (d->__nextchar);
715
*longind = option_index;
718
*(pfound->flag) = pfound->val;
675
724
/* Can't find it as a long option. If this is not getopt_long_only,
676
or the option starts with '--' or is not a valid short
677
option, then it's an error.
678
Otherwise interpret it as a short option. */
725
or the option starts with '--' or is not a valid short
726
option, then it's an error.
727
Otherwise interpret it as a short option. */
679
728
if (!long_only || argv[d->optind][1] == '-'
680
|| strchr (optstring, *d->__nextchar) == NULL)
684
#if defined _LIBC && defined USE_IN_LIBIO
689
if (argv[d->optind][1] == '-')
692
#if defined _LIBC && defined USE_IN_LIBIO
693
n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
694
argv[0], d->__nextchar);
696
fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
697
argv[0], d->__nextchar);
702
/* +option or -option */
703
#if defined _LIBC && defined USE_IN_LIBIO
704
n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
705
argv[0], argv[d->optind][0], d->__nextchar);
707
fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
708
argv[0], argv[d->optind][0], d->__nextchar);
712
#if defined _LIBC && defined USE_IN_LIBIO
715
_IO_flockfile (stderr);
717
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
718
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
720
__fxprintf (NULL, "%s", buf);
722
((_IO_FILE *) stderr)->_flags2 = old_flags2;
723
_IO_funlockfile (stderr);
729
d->__nextchar = (char *) "";
729
|| strchr (optstring, *d->__nextchar) == NULL)
733
#if defined _LIBC && defined USE_IN_LIBIO
738
if (argv[d->optind][1] == '-')
741
#if defined _LIBC && defined USE_IN_LIBIO
742
n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
743
argv[0], d->__nextchar);
745
fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
746
argv[0], d->__nextchar);
751
/* +option or -option */
752
#if defined _LIBC && defined USE_IN_LIBIO
753
n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
754
argv[0], argv[d->optind][0], d->__nextchar);
756
fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
757
argv[0], argv[d->optind][0], d->__nextchar);
761
#if defined _LIBC && defined USE_IN_LIBIO
764
_IO_flockfile (stderr);
766
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
767
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
769
__fxprintf (NULL, "%s", buf);
771
((_IO_FILE *) stderr)->_flags2 = old_flags2;
772
_IO_funlockfile (stderr);
778
d->__nextchar = (char *) "";
736
785
/* Look at and handle the next short option-character. */
739
788
char c = *d->__nextchar++;
740
char *temp = strchr (optstring, c);
789
const char *temp = strchr (optstring, c);
742
791
/* Increment `optind' when we start to process its last character. */
743
792
if (*d->__nextchar == '\0')
746
if (temp == NULL || c == ':')
795
if (temp == NULL || c == ':' || c == ';')
750
#if defined _LIBC && defined USE_IN_LIBIO
755
if (d->__posixly_correct)
757
/* 1003.2 specifies the format of this message. */
758
#if defined _LIBC && defined USE_IN_LIBIO
759
n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
762
fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
767
#if defined _LIBC && defined USE_IN_LIBIO
768
n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
771
fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
775
#if defined _LIBC && defined USE_IN_LIBIO
778
_IO_flockfile (stderr);
780
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
781
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
783
__fxprintf (NULL, "%s", buf);
785
((_IO_FILE *) stderr)->_flags2 = old_flags2;
786
_IO_funlockfile (stderr);
799
#if defined _LIBC && defined USE_IN_LIBIO
804
#if defined _LIBC && defined USE_IN_LIBIO
805
n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
808
fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
811
#if defined _LIBC && defined USE_IN_LIBIO
814
_IO_flockfile (stderr);
816
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
817
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
819
__fxprintf (NULL, "%s", buf);
821
((_IO_FILE *) stderr)->_flags2 = old_flags2;
822
_IO_funlockfile (stderr);
795
831
/* Convenience. Treat POSIX -W foo same as long option --foo */
796
832
if (temp[0] == 'W' && temp[1] == ';')
799
const struct option *p;
800
const struct option *pfound = NULL;
806
/* This is an option that requires an argument. */
807
if (*d->__nextchar != '\0')
809
d->optarg = d->__nextchar;
810
/* If we end this ARGV-element by taking the rest as an arg,
811
we must advance to the next element now. */
814
else if (d->optind == argc)
818
/* 1003.2 specifies the format of this message. */
819
#if defined _LIBC && defined USE_IN_LIBIO
822
if (__asprintf (&buf,
823
_("%s: option requires an argument -- %c\n"),
826
_IO_flockfile (stderr);
828
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
829
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
831
__fxprintf (NULL, "%s", buf);
833
((_IO_FILE *) stderr)->_flags2 = old_flags2;
834
_IO_funlockfile (stderr);
839
fprintf (stderr, _("%s: option requires an argument -- %c\n"),
844
if (optstring[0] == ':')
851
/* We already incremented `d->optind' once;
852
increment it again when taking next ARGV-elt as argument. */
853
d->optarg = argv[d->optind++];
855
/* optarg is now the argument, see if it's in the
856
table of longopts. */
858
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
862
/* Test all long options for either exact match
863
or abbreviated matches. */
864
for (p = longopts, option_index = 0; p->name; p++, option_index++)
865
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
867
if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
869
/* Exact match found. */
871
indfound = option_index;
875
else if (pfound == NULL)
877
/* First nonexact match found. */
879
indfound = option_index;
882
/* Second or later nonexact match found. */
889
#if defined _LIBC && defined USE_IN_LIBIO
892
if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
893
argv[0], argv[d->optind]) >= 0)
895
_IO_flockfile (stderr);
897
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
898
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
900
__fxprintf (NULL, "%s", buf);
902
((_IO_FILE *) stderr)->_flags2 = old_flags2;
903
_IO_funlockfile (stderr);
908
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
909
argv[0], argv[d->optind]);
912
d->__nextchar += strlen (d->__nextchar);
918
option_index = indfound;
921
/* Don't test has_arg with >, because some C compilers don't
922
allow it to be used on enums. */
924
d->optarg = nameend + 1;
929
#if defined _LIBC && defined USE_IN_LIBIO
932
if (__asprintf (&buf, _("\
933
%s: option `-W %s' doesn't allow an argument\n"),
934
argv[0], pfound->name) >= 0)
936
_IO_flockfile (stderr);
938
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
939
((_IO_FILE *) stderr)->_flags2
940
|= _IO_FLAGS2_NOTCANCEL;
942
__fxprintf (NULL, "%s", buf);
944
((_IO_FILE *) stderr)->_flags2 = old_flags2;
945
_IO_funlockfile (stderr);
950
fprintf (stderr, _("\
951
%s: option `-W %s' doesn't allow an argument\n"),
952
argv[0], pfound->name);
956
d->__nextchar += strlen (d->__nextchar);
960
else if (pfound->has_arg == 1)
962
if (d->optind < argc)
963
d->optarg = argv[d->optind++];
968
#if defined _LIBC && defined USE_IN_LIBIO
971
if (__asprintf (&buf, _("\
972
%s: option `%s' requires an argument\n"),
973
argv[0], argv[d->optind - 1]) >= 0)
975
_IO_flockfile (stderr);
977
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
978
((_IO_FILE *) stderr)->_flags2
979
|= _IO_FLAGS2_NOTCANCEL;
981
__fxprintf (NULL, "%s", buf);
983
((_IO_FILE *) stderr)->_flags2 = old_flags2;
984
_IO_funlockfile (stderr);
990
_("%s: option `%s' requires an argument\n"),
991
argv[0], argv[d->optind - 1]);
994
d->__nextchar += strlen (d->__nextchar);
995
return optstring[0] == ':' ? ':' : '?';
998
d->__nextchar += strlen (d->__nextchar);
1000
*longind = option_index;
1003
*(pfound->flag) = pfound->val;
1008
d->__nextchar = NULL;
1009
return 'W'; /* Let the application handle it. */
835
const struct option *p;
836
const struct option *pfound = NULL;
842
if (longopts == NULL)
845
/* This is an option that requires an argument. */
846
if (*d->__nextchar != '\0')
848
d->optarg = d->__nextchar;
849
/* If we end this ARGV-element by taking the rest as an arg,
850
we must advance to the next element now. */
853
else if (d->optind == argc)
857
#if defined _LIBC && defined USE_IN_LIBIO
860
if (__asprintf (&buf,
861
_("%s: option requires an argument -- '%c'\n"),
864
_IO_flockfile (stderr);
866
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
867
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
869
__fxprintf (NULL, "%s", buf);
871
((_IO_FILE *) stderr)->_flags2 = old_flags2;
872
_IO_funlockfile (stderr);
878
_("%s: option requires an argument -- '%c'\n"),
883
if (optstring[0] == ':')
890
/* We already incremented `d->optind' once;
891
increment it again when taking next ARGV-elt as argument. */
892
d->optarg = argv[d->optind++];
894
/* optarg is now the argument, see if it's in the
895
table of longopts. */
897
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
901
/* Test all long options for either exact match
902
or abbreviated matches. */
903
for (p = longopts, option_index = 0; p->name; p++, option_index++)
904
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
906
if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
908
/* Exact match found. */
910
indfound = option_index;
914
else if (pfound == NULL)
916
/* First nonexact match found. */
918
indfound = option_index;
921
|| pfound->has_arg != p->has_arg
922
|| pfound->flag != p->flag
923
|| pfound->val != p->val)
924
/* Second or later nonexact match found. */
931
#if defined _LIBC && defined USE_IN_LIBIO
934
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
935
argv[0], d->optarg) >= 0)
937
_IO_flockfile (stderr);
939
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
940
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
942
__fxprintf (NULL, "%s", buf);
944
((_IO_FILE *) stderr)->_flags2 = old_flags2;
945
_IO_funlockfile (stderr);
950
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
954
d->__nextchar += strlen (d->__nextchar);
960
option_index = indfound;
963
/* Don't test has_arg with >, because some C compilers don't
964
allow it to be used on enums. */
966
d->optarg = nameend + 1;
971
#if defined _LIBC && defined USE_IN_LIBIO
974
if (__asprintf (&buf, _("\
975
%s: option '-W %s' doesn't allow an argument\n"),
976
argv[0], pfound->name) >= 0)
978
_IO_flockfile (stderr);
980
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
981
((_IO_FILE *) stderr)->_flags2
982
|= _IO_FLAGS2_NOTCANCEL;
984
__fxprintf (NULL, "%s", buf);
986
((_IO_FILE *) stderr)->_flags2 = old_flags2;
987
_IO_funlockfile (stderr);
992
fprintf (stderr, _("\
993
%s: option '-W %s' doesn't allow an argument\n"),
994
argv[0], pfound->name);
998
d->__nextchar += strlen (d->__nextchar);
1002
else if (pfound->has_arg == 1)
1004
if (d->optind < argc)
1005
d->optarg = argv[d->optind++];
1010
#if defined _LIBC && defined USE_IN_LIBIO
1013
if (__asprintf (&buf, _("\
1014
%s: option '-W %s' requires an argument\n"),
1015
argv[0], pfound->name) >= 0)
1017
_IO_flockfile (stderr);
1019
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1020
((_IO_FILE *) stderr)->_flags2
1021
|= _IO_FLAGS2_NOTCANCEL;
1023
__fxprintf (NULL, "%s", buf);
1025
((_IO_FILE *) stderr)->_flags2 = old_flags2;
1026
_IO_funlockfile (stderr);
1031
fprintf (stderr, _("\
1032
%s: option '-W %s' requires an argument\n"),
1033
argv[0], pfound->name);
1036
d->__nextchar += strlen (d->__nextchar);
1037
return optstring[0] == ':' ? ':' : '?';
1042
d->__nextchar += strlen (d->__nextchar);
1043
if (longind != NULL)
1044
*longind = option_index;
1047
*(pfound->flag) = pfound->val;
1054
d->__nextchar = NULL;
1055
return 'W'; /* Let the application handle it. */
1011
1057
if (temp[1] == ':')
1015
/* This is an option that accepts an argument optionally. */
1016
if (*d->__nextchar != '\0')
1018
d->optarg = d->__nextchar;
1023
d->__nextchar = NULL;
1027
/* This is an option that requires an argument. */
1028
if (*d->__nextchar != '\0')
1030
d->optarg = d->__nextchar;
1031
/* If we end this ARGV-element by taking the rest as an arg,
1032
we must advance to the next element now. */
1035
else if (d->optind == argc)
1039
/* 1003.2 specifies the format of this message. */
1061
/* This is an option that accepts an argument optionally. */
1062
if (*d->__nextchar != '\0')
1064
d->optarg = d->__nextchar;
1069
d->__nextchar = NULL;
1073
/* This is an option that requires an argument. */
1074
if (*d->__nextchar != '\0')
1076
d->optarg = d->__nextchar;
1077
/* If we end this ARGV-element by taking the rest as an arg,
1078
we must advance to the next element now. */
1081
else if (d->optind == argc)
1040
1085
#if defined _LIBC && defined USE_IN_LIBIO
1043
if (__asprintf (&buf, _("\
1044
%s: option requires an argument -- %c\n"),
1047
_IO_flockfile (stderr);
1049
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1050
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1052
__fxprintf (NULL, "%s", buf);
1054
((_IO_FILE *) stderr)->_flags2 = old_flags2;
1055
_IO_funlockfile (stderr);
1088
if (__asprintf (&buf, _("\
1089
%s: option requires an argument -- '%c'\n"),
1092
_IO_flockfile (stderr);
1094
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1095
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1097
__fxprintf (NULL, "%s", buf);
1099
((_IO_FILE *) stderr)->_flags2 = old_flags2;
1100
_IO_funlockfile (stderr);
1061
_("%s: option requires an argument -- %c\n"),
1106
_("%s: option requires an argument -- '%c'\n"),
1066
if (optstring[0] == ':')
1072
/* We already incremented `optind' once;
1073
increment it again when taking next ARGV-elt as argument. */
1074
d->optarg = argv[d->optind++];
1075
d->__nextchar = NULL;
1111
if (optstring[0] == ':')
1117
/* We already incremented `optind' once;
1118
increment it again when taking next ARGV-elt as argument. */
1119
d->optarg = argv[d->optind++];
1120
d->__nextchar = NULL;