Skip to content

Commit 60ff2fd

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 scattered all over the place. Now that we find we're going to need to tweak the variable declarations for Cygwin, it seems like a good idea to have just 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 parent 32be1c8 commit 60ff2fd

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-
#ifdef HAVE_GETOPT_H
14-
#include <getopt.h>
15-
#endif
16-
17-
extern char *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
typedef struct

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-
#ifndef WIN32
2220
#include <sys/time.h>
23-
#include <unistd.h>
24-
25-
#ifdef HAVE_GETOPT_H
26-
#include <getopt.h>
27-
#endif
28-
#else /* WIN32 */
29-
extern int getopt(int argc, char *const argv[], const char *optstring);
30-
#endif /* ! WIN32 */
3121

32-
extern char *optarg;
33-
extern int optind;
22+
#include "pg_getopt.h"
3423

3524
const char *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-
#ifdef WIN32
33-
int getopt(int argc, char *const argv[], const char *optstring);
34-
#else
3531
#include <sys/time.h>
36-
#include <unistd.h>
37-
38-
#ifdef HAVE_GETOPT_H
39-
#include <getopt.h>
40-
#endif
41-
#endif /* ! WIN32 */
4232

43-
extern char *optarg;
44-
extern int optind;
33+
#include "pg_getopt.h"
4534

4635
const char *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-
#ifndef WIN32
4543
#include <sys/time.h>
46-
#include <unistd.h>
47-
#endif /* ! WIN32 */
48-
4944
#ifdef HAVE_SYS_SELECT_H
5045
#include <sys/select.h>
5146
#endif
@@ -89,9 +84,6 @@ static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start
8984
static int pthread_join(pthread_t th, void **thread_return);
9085
#endif
9186

92-
extern char *optarg;
93-
extern int optind;
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
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
2728

2829
#define BUFSIZE 1024
2930

30-
extern char *optarg;
31-
extern int optind,
32-
opterr;
33-
3431
enum trivalue
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-
#ifdef HAVE_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-
extern int optind;
50-
extern char *optarg;
51-
5247
uint32 bootstrap_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-
#ifdef HAVE_GETOPT_H
87-
#include <getopt.h>
88-
#endif
89-
9086
#ifdef USE_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
static unsigned int random_seed = 0;
353350
static struct timeval random_start_time;
354351

355-
extern char *optarg;
356-
extern int optind,
357-
opterr;
358-
359-
#ifdef HAVE_INT_OPTRESET
360-
extern int optreset; /* might not be declared by system headers */
361-
#endif
362-
363352
#ifdef USE_BONJOUR
364353
static DNSServiceRef bonjour_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-
#ifdef HAVE_GETOPT_H
36-
#include <getopt.h>
37-
#endif
3835

3936
#ifndef HAVE_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-
extern char *optarg;
81-
extern int optind;
82-
83-
#ifdef HAVE_INT_OPTRESET
84-
extern int optreset; /* 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-
extern char *optarg;
67-
extern int optind,
68-
opterr;
69-
7066

7167
typedef struct
7268
{

0 commit comments

Comments
 (0)