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

Commit60ff2fd

Browse files
committed
Centralize getopt-related declarations in a new header file pg_getopt.h.
We used to have externs for getopt() and its API variables scatteredall over the place. Now that we find we're going to need to tweak thevariable declarations for Cygwin, it seems like a good idea to havejust one place to tweak.In this commit, the variables are declared "#ifndef HAVE_GETOPT_H".That may or may not work everywhere, but we'll soon find out.Andres Freund
1 parent32be1c8 commit60ff2fd

File tree

19 files changed

+57
-130
lines changed

19 files changed

+57
-130
lines changed

‎contrib/oid2name/oid2name.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@
99
*/
1010
#include"postgres_fe.h"
1111

12-
#include<unistd.h>
13-
#ifdefHAVE_GETOPT_H
14-
#include<getopt.h>
15-
#endif
16-
17-
externchar*optarg;
18-
1912
#include"libpq-fe.h"
13+
#include"pg_getopt.h"
2014

2115
/* an extensible array to keep track of elements to show */
2216
typedefstruct

‎contrib/pg_archivecleanup/pg_archivecleanup.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,9 @@
1717
#include<sys/stat.h>
1818
#include<fcntl.h>
1919
#include<signal.h>
20-
21-
#ifndefWIN32
2220
#include<sys/time.h>
23-
#include<unistd.h>
24-
25-
#ifdefHAVE_GETOPT_H
26-
#include<getopt.h>
27-
#endif
28-
#else/* WIN32 */
29-
externintgetopt(intargc,char*constargv[],constchar*optstring);
30-
#endif/* ! WIN32 */
3121

32-
externchar*optarg;
33-
externintoptind;
22+
#include"pg_getopt.h"
3423

3524
constchar*progname;
3625

‎contrib/pg_standby/pg_standby.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,9 @@
2828
#include<sys/stat.h>
2929
#include<fcntl.h>
3030
#include<signal.h>
31-
32-
#ifdefWIN32
33-
intgetopt(intargc,char*constargv[],constchar*optstring);
34-
#else
3531
#include<sys/time.h>
36-
#include<unistd.h>
37-
38-
#ifdefHAVE_GETOPT_H
39-
#include<getopt.h>
40-
#endif
41-
#endif/* ! WIN32 */
4232

43-
externchar*optarg;
44-
externintoptind;
33+
#include"pg_getopt.h"
4534

4635
constchar*progname;
4736

‎contrib/pg_upgrade/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#include"postgres_fe.h"
1111

1212
#include"miscadmin.h"
13+
#include"getopt_long.h"
1314

1415
#include"pg_upgrade.h"
1516

16-
#include<getopt_long.h>
1717
#include<time.h>
1818
#include<sys/types.h>
1919
#include<sys/stat.h>

‎contrib/pgbench/pgbench.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@
4040
#include<ctype.h>
4141
#include<math.h>
4242
#include<signal.h>
43-
44-
#ifndefWIN32
4543
#include<sys/time.h>
46-
#include<unistd.h>
47-
#endif/* ! WIN32 */
48-
4944
#ifdefHAVE_SYS_SELECT_H
5045
#include<sys/select.h>
5146
#endif
@@ -89,9 +84,6 @@ static intpthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start
8984
staticintpthread_join(pthread_tth,void**thread_return);
9085
#endif
9186

92-
externchar*optarg;
93-
externintoptind;
94-
9587

9688
/********************************************************************
9789
* some configurable parameters */

‎contrib/vacuumlo/vacuumlo.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@
2222
#endif
2323

2424
#include"libpq-fe.h"
25+
#include"pg_getopt.h"
2526

2627
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
2728

2829
#defineBUFSIZE1024
2930

30-
externchar*optarg;
31-
externintoptind,
32-
opterr;
33-
3431
enumtrivalue
3532
{
3633
TRI_DEFAULT,

‎src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include<time.h>
1818
#include<unistd.h>
1919
#include<signal.h>
20-
#ifdefHAVE_GETOPT_H
21-
#include<getopt.h>
22-
#endif
2320

2421
#include"access/htup_details.h"
2522
#include"bootstrap/bootstrap.h"
@@ -29,6 +26,7 @@
2926
#include"libpq/pqsignal.h"
3027
#include"miscadmin.h"
3128
#include"nodes/makefuncs.h"
29+
#include"pg_getopt.h"
3230
#include"postmaster/bgwriter.h"
3331
#include"postmaster/startup.h"
3432
#include"postmaster/walwriter.h"
@@ -46,9 +44,6 @@
4644
#include"utils/relmapper.h"
4745
#include"utils/tqual.h"
4846

49-
externintoptind;
50-
externchar*optarg;
51-
5247
uint32bootstrap_data_checksum_version=0;/* No checksum */
5348

5449

‎src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@
8383
#include<sys/select.h>
8484
#endif
8585

86-
#ifdefHAVE_GETOPT_H
87-
#include<getopt.h>
88-
#endif
89-
9086
#ifdefUSE_BONJOUR
9187
#include<dns_sd.h>
9288
#endif
@@ -101,6 +97,7 @@
10197
#include"libpq/libpq.h"
10298
#include"libpq/pqsignal.h"
10399
#include"miscadmin.h"
100+
#include"pg_getopt.h"
104101
#include"pgstat.h"
105102
#include"postmaster/autovacuum.h"
106103
#include"postmaster/bgworker_internals.h"
@@ -352,14 +349,6 @@ static volatile bool HaveCrashedWorker = false;
352349
staticunsignedintrandom_seed=0;
353350
staticstructtimevalrandom_start_time;
354351

355-
externchar*optarg;
356-
externintoptind,
357-
opterr;
358-
359-
#ifdefHAVE_INT_OPTRESET
360-
externintoptreset;/* might not be declared by system headers */
361-
#endif
362-
363352
#ifdefUSE_BONJOUR
364353
staticDNSServiceRefbonjour_sdref=NULL;
365354
#endif

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
#include<sys/time.h>
3333
#include<sys/resource.h>
3434
#endif
35-
#ifdefHAVE_GETOPT_H
36-
#include<getopt.h>
37-
#endif
3835

3936
#ifndefHAVE_GETRUSAGE
4037
#include"rusagestub.h"
@@ -55,6 +52,7 @@
5552
#include"pg_trace.h"
5653
#include"parser/analyze.h"
5754
#include"parser/parser.h"
55+
#include"pg_getopt.h"
5856
#include"postmaster/autovacuum.h"
5957
#include"postmaster/postmaster.h"
6058
#include"replication/walsender.h"
@@ -77,14 +75,6 @@
7775
#include"mb/pg_wchar.h"
7876

7977

80-
externchar*optarg;
81-
externintoptind;
82-
83-
#ifdefHAVE_INT_OPTRESET
84-
externintoptreset;/* might not be declared by system headers */
85-
#endif
86-
87-
8878
/* ----------------
8979
*global variables
9080
* ----------------

‎src/bin/pg_dump/pg_dump.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@
6363
#include"dumputils.h"
6464
#include"parallel.h"
6565

66-
externchar*optarg;
67-
externintoptind,
68-
opterr;
69-
7066

7167
typedefstruct
7268
{

‎src/bin/pg_dump/pg_restore.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,14 @@
4343
#include"pg_backup_utils.h"
4444
#include"dumputils.h"
4545
#include"parallel.h"
46+
#include"getopt_long.h"
4647

4748
#include<ctype.h>
4849

4950
#ifdefHAVE_TERMIOS_H
5051
#include<termios.h>
5152
#endif
5253

53-
#include<unistd.h>
54-
55-
#include"getopt_long.h"
56-
57-
externchar*optarg;
58-
externintoptind;
59-
6054
#ifdefENABLE_NLS
6155
#include<locale.h>
6256
#endif

‎src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#include<sys/time.h>
4545
#include<time.h>
4646
#include<unistd.h>
47-
#ifdefHAVE_GETOPT_H
48-
#include<getopt.h>
49-
#endif
5047

5148
#include"access/transam.h"
5249
#include"access/tuptoaster.h"
@@ -55,9 +52,7 @@
5552
#include"catalog/catversion.h"
5653
#include"catalog/pg_control.h"
5754
#include"common/fe_memutils.h"
58-
59-
externintoptind;
60-
externchar*optarg;
55+
#include"pg_getopt.h"
6156

6257

6358
staticControlFileDataControlFile;/* pg_control values */

‎src/bin/psql/startup.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
386386
};
387387

388388
intoptindex;
389-
externchar*optarg;
390-
externintoptind;
391389
intc;
392390

393391
memset(options,0,sizeof*options);

‎src/include/getopt_long.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99
#ifndefGETOPT_LONG_H
1010
#defineGETOPT_LONG_H
1111

12-
#ifdefHAVE_GETOPT_H
13-
#include<getopt.h>
14-
#endif
15-
16-
/* These are picked up from the system's getopt() facility. */
17-
externintopterr;
18-
externintoptind;
19-
externintoptopt;
20-
externchar*optarg;
12+
#include"pg_getopt.h"
2113

2214
#ifndefHAVE_STRUCT_OPTION
2315

‎src/include/pg_getopt.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Portions Copyright (c) 1987, 1993, 1994
3+
* The Regents of the University of California. All rights reserved.
4+
*
5+
* Portions Copyright (c) 2003-2014, PostgreSQL Global Development Group
6+
*
7+
* src/include/pg_getopt.h
8+
*/
9+
#ifndefPG_GETOPT_H
10+
#definePG_GETOPT_H
11+
12+
/* POSIX says getopt() is provided by unistd.h */
13+
#include<unistd.h>
14+
15+
/* rely on the system's getopt.h if present */
16+
#ifdefHAVE_GETOPT_H
17+
#include<getopt.h>
18+
#endif
19+
20+
/*
21+
* If we have <getopt.h>, assume it declares these variables, else do that
22+
* ourselves. (We used to just declare them unconditionally, but Cygwin
23+
* doesn't like that.)
24+
*/
25+
#ifndefHAVE_GETOPT_H
26+
27+
externchar*optarg;
28+
externintoptind;
29+
externintopterr;
30+
externintoptopt;
31+
32+
#ifdefHAVE_INT_OPTRESET
33+
externintoptreset;
34+
#endif
35+
36+
#endif/* HAVE_GETOPT_H */
37+
38+
#ifndefHAVE_GETOPT
39+
externintgetopt(intnargc,char*const*nargv,constchar*ostr);
40+
#endif
41+
42+
#endif/* PG_GETOPT_H */

‎src/include/port.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,6 @@ extern intfls(int mask);
382382
#defineftello(a)ftell(a)
383383
#endif
384384

385-
#ifndefHAVE_GETOPT
386-
externintgetopt(intnargc,char*const*nargv,constchar*ostr);
387-
#endif
388-
389385
#if !defined(HAVE_GETPEEREID)&& !defined(WIN32)
390386
externintgetpeereid(intsock,uid_t*uid,gid_t*gid);
391387
#endif

‎src/port/getopt.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include"c.h"
3434

35+
#include"pg_getopt.h"
36+
3537
#if defined(LIBC_SCCS)&& !defined(lint)
3638
staticcharsccsid[]="@(#)getopt.c8.3 (Berkeley) 4/27/95";
3739
#endif/* LIBC_SCCS and not lint */
@@ -49,20 +51,13 @@ intopterr = 1,/* if error message should be printed */
4951
optind=1,/* index into parent argv vector */
5052
optopt;/* character checked for validity */
5153
char*optarg;/* argument associated with option */
52-
#else
5354

54-
externintopterr;
55-
externintoptind;
56-
externintoptopt;
57-
externchar*optarg;
5855
#endif
5956

6057
#defineBADCH(int)'?'
6158
#defineBADARG(int)':'
6259
#defineEMSG""
6360

64-
intgetopt(intnargc,char*const*nargv,constchar*ostr);
65-
6661
/*
6762
* getopt
6863
*Parse argc/argv argument vector.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp