Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit311da16

Browse files
committed
Add support for optional_argument to our own getopt_long() implementation.
07c8651 currently causes compilation errors on mscv (andprobably some other) compilers because our getopt_long()implementation doesn't have support for optional_argument.Thus implement optional_argument in our fallback implemenation. It'squite possibly also useful in other cases.Arguably this needs a configure check for optional_argument, but ithas existed pretty much since getopt_long() was introduced and thusdoesn't seem worth the configure runtime.Normally I'd would not push a patch this fast, but this allows msvc tobuild again and has low risk as only optional_argument behaviour haschanged.Author: Michael Paquier and Andres FreundDiscussion: CAB7nPqS5VeedSCxrK=QouokbawgGKLpyc1Q++RRFCa_sjcSVrg@mail.gmail.com
1 parentb4c28d1 commit311da16

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

‎src/include/getopt_long.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct option
2323

2424
#defineno_argument 0
2525
#definerequired_argument 1
26+
#defineoptional_argument 2
2627
#endif
2728

2829
#ifndefHAVE_GETOPT_LONG

‎src/port/getopt_long.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ getopt_long(int argc, char *const argv[],
100100
if (strlen(longopts[i].name)==namelen
101101
&&strncmp(place,longopts[i].name,namelen)==0)
102102
{
103-
if (longopts[i].has_arg)
103+
inthas_arg=longopts[i].has_arg;
104+
105+
if (has_arg!=no_argument)
104106
{
105107
if (place[namelen]=='=')
106108
optarg=place+namelen+1;
107-
elseif (optind<argc-1)
109+
elseif (optind<argc-1&&
110+
has_arg==required_argument)
108111
{
109112
optind++;
110113
optarg=argv[optind];
@@ -113,13 +116,18 @@ getopt_long(int argc, char *const argv[],
113116
{
114117
if (optstring[0]==':')
115118
returnBADARG;
116-
if (opterr)
119+
120+
if (opterr&&has_arg==required_argument)
117121
fprintf(stderr,
118122
"%s: option requires an argument -- %s\n",
119123
argv[0],place);
124+
120125
place=EMSG;
121126
optind++;
122-
returnBADCH;
127+
128+
if (has_arg==required_argument)
129+
returnBADCH;
130+
optarg=NULL;
123131
}
124132
}
125133
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp