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

Commit61b5369

Browse files
committed
Remove optreset from src/port/ implementations of getopt and getopt_long.
We don't actually need optreset, because we can easily fix the code toensure that it's cleanly restartable after having completed a scan over theargv array; which is the only case we need to restart in. Getting rid ofit avoids a class of interactions with the system libraries and allowsreversion of my change of yesterday in postmaster.c and postgres.c.Back-patch to 8.4. Before that the getopt code was a bit different anyway.
1 parentcd1fefa commit61b5369

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ extern char *optarg;
313313
externintoptind,
314314
opterr;
315315

316-
/* If not HAVE_GETOPT, we are using src/port/getopt.c, which has optreset */
317-
#if defined(HAVE_INT_OPTRESET)|| !defined(HAVE_GETOPT)
316+
#ifdefHAVE_INT_OPTRESET
318317
externintoptreset;/* might not be declared by system headers */
319318
#endif
320319

@@ -752,7 +751,7 @@ PostmasterMain(int argc, char *argv[])
752751
* getopt(3) library so that it will work correctly in subprocesses.
753752
*/
754753
optind=1;
755-
#if defined(HAVE_INT_OPTRESET)|| !defined(HAVE_GETOPT)
754+
#ifdefHAVE_INT_OPTRESET
756755
optreset=1;/* some systems need this too */
757756
#endif
758757

‎src/backend/tcop/postgres.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
externchar*optarg;
7979
externintoptind;
8080

81-
/* If not HAVE_GETOPT, we are using src/port/getopt.c, which has optreset */
82-
#if defined(HAVE_INT_OPTRESET)|| !defined(HAVE_GETOPT)
81+
#ifdefHAVE_INT_OPTRESET
8382
externintoptreset;/* might not be declared by system headers */
8483
#endif
8584

@@ -3443,7 +3442,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
34433442
* or when this function is called a second time with another array.
34443443
*/
34453444
optind=1;
3446-
#if defined(HAVE_INT_OPTRESET)|| !defined(HAVE_GETOPT)
3445+
#ifdefHAVE_INT_OPTRESET
34473446
optreset=1;/* some systems need this too */
34483447
#endif
34493448

‎src/include/getopt_long.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern intopterr;
1818
externintoptind;
1919
externintoptopt;
2020
externchar*optarg;
21-
externintoptreset;
2221

2322
#ifndefHAVE_STRUCT_OPTION
2423

‎src/port/getopt.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static char sccsid[] = "@(#)getopt.c8.3 (Berkeley) 4/27/95";
4141
* On some versions of Solaris, opterr and friends are defined in core libc
4242
* rather than in a separate getopt module. Define these variables only
4343
* if configure found they aren't there by default. (We assume that testing
44-
* opterr is sufficient for all of these except optreset.)
44+
* opterr is sufficient for all of these.)
4545
*/
4646
#ifndefHAVE_INT_OPTERR
4747

@@ -57,19 +57,19 @@ extern intoptopt;
5757
externchar*optarg;
5858
#endif
5959

60-
#ifndefHAVE_INT_OPTRESET
61-
intoptreset;/* reset getopt */
62-
#else
63-
externintoptreset;
64-
#endif
65-
6660
#defineBADCH(int)'?'
6761
#defineBADARG(int)':'
6862
#defineEMSG""
6963

7064
/*
7165
* getopt
7266
*Parse argc/argv argument vector.
67+
*
68+
* This implementation does not use optreset. Instead, we guarantee that
69+
* it can be restarted on a new argv array after a previous call returned -1,
70+
* if the caller resets optind to 1 before the first call of the new series.
71+
* (Internally, this means we must be sure to reset "place" to EMSG before
72+
* returning -1.)
7373
*/
7474
int
7575
getopt(nargc,nargv,ostr)
@@ -80,9 +80,8 @@ const char *ostr;
8080
staticchar*place=EMSG;/* option letter processing */
8181
char*oli;/* option letter list index */
8282

83-
if (optreset||!*place)
83+
if (!*place)
8484
{/* update scanning pointer */
85-
optreset=0;
8685
if (optind >=nargc||*(place=nargv[optind])!='-')
8786
{
8887
place=EMSG;
@@ -102,7 +101,10 @@ const char *ostr;
102101
* if the user didn't specify '-' as an option, assume it means -1.
103102
*/
104103
if (optopt== (int)'-')
104+
{
105+
place=EMSG;
105106
return-1;
107+
}
106108
if (!*place)
107109
++optind;
108110
if (opterr&&*ostr!=':')

‎src/port/getopt_long.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@
3838

3939
#include"getopt_long.h"
4040

41-
#ifndefHAVE_INT_OPTRESET
42-
intoptreset;
43-
44-
/* else the "extern" was provided by getopt_long.h */
45-
#endif
46-
4741
#defineBADCH'?'
4842
#defineBADARG':'
4943
#defineEMSG""
5044

5145

46+
/*
47+
* getopt_long
48+
*Parse argc/argv argument vector, with long options.
49+
*
50+
* This implementation does not use optreset. Instead, we guarantee that
51+
* it can be restarted on a new argv array after a previous call returned -1,
52+
* if the caller resets optind to 1 before the first call of the new series.
53+
* (Internally, this means we must be sure to reset "place" to EMSG before
54+
* returning -1.)
55+
*/
5256
int
5357
getopt_long(intargc,char*constargv[],
5458
constchar*optstring,
@@ -57,10 +61,8 @@ getopt_long(int argc, char *const argv[],
5761
staticchar*place=EMSG;/* option letter processing */
5862
char*oli;/* option letter list index */
5963

60-
if (optreset||!*place)
64+
if (!*place)
6165
{/* update scanning pointer */
62-
optreset=0;
63-
6466
if (optind >=argc)
6567
{
6668
place=EMSG;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp