Commit 60ff2fdd authored by Tom Lane's avatar Tom Lane

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
parent 32be1c8e
...@@ -9,14 +9,8 @@ ...@@ -9,14 +9,8 @@
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
extern char *optarg;
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pg_getopt.h"
/* an extensible array to keep track of elements to show */ /* an extensible array to keep track of elements to show */
typedef struct typedef struct
......
...@@ -17,20 +17,9 @@ ...@@ -17,20 +17,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#ifndef WIN32
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#else /* WIN32 */
extern int getopt(int argc, char *const argv[], const char *optstring);
#endif /* ! WIN32 */
extern char *optarg; #include "pg_getopt.h"
extern int optind;
const char *progname; const char *progname;
......
...@@ -28,20 +28,9 @@ ...@@ -28,20 +28,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#ifdef WIN32
int getopt(int argc, char *const argv[], const char *optstring);
#else
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#endif /* ! WIN32 */
extern char *optarg; #include "pg_getopt.h"
extern int optind;
const char *progname; const char *progname;
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "getopt_long.h"
#include "pg_upgrade.h" #include "pg_upgrade.h"
#include <getopt_long.h>
#include <time.h> #include <time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
......
...@@ -40,12 +40,7 @@ ...@@ -40,12 +40,7 @@
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include <signal.h> #include <signal.h>
#ifndef WIN32
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#endif /* ! WIN32 */
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif #endif
...@@ -89,9 +84,6 @@ static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start ...@@ -89,9 +84,6 @@ static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start
static int pthread_join(pthread_t th, void **thread_return); static int pthread_join(pthread_t th, void **thread_return);
#endif #endif
extern char *optarg;
extern int optind;
/******************************************************************** /********************************************************************
* some configurable parameters */ * some configurable parameters */
......
...@@ -22,15 +22,12 @@ ...@@ -22,15 +22,12 @@
#endif #endif
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pg_getopt.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10)) #define atooid(x) ((Oid) strtoul((x), NULL, 10))
#define BUFSIZE 1024 #define BUFSIZE 1024
extern char *optarg;
extern int optind,
opterr;
enum trivalue enum trivalue
{ {
TRI_DEFAULT, TRI_DEFAULT,
......
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "access/htup_details.h" #include "access/htup_details.h"
#include "bootstrap/bootstrap.h" #include "bootstrap/bootstrap.h"
...@@ -29,6 +26,7 @@ ...@@ -29,6 +26,7 @@
#include "libpq/pqsignal.h" #include "libpq/pqsignal.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "pg_getopt.h"
#include "postmaster/bgwriter.h" #include "postmaster/bgwriter.h"
#include "postmaster/startup.h" #include "postmaster/startup.h"
#include "postmaster/walwriter.h" #include "postmaster/walwriter.h"
...@@ -46,9 +44,6 @@ ...@@ -46,9 +44,6 @@
#include "utils/relmapper.h" #include "utils/relmapper.h"
#include "utils/tqual.h" #include "utils/tqual.h"
extern int optind;
extern char *optarg;
uint32 bootstrap_data_checksum_version = 0; /* No checksum */ uint32 bootstrap_data_checksum_version = 0; /* No checksum */
......
...@@ -83,10 +83,6 @@ ...@@ -83,10 +83,6 @@
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef USE_BONJOUR #ifdef USE_BONJOUR
#include <dns_sd.h> #include <dns_sd.h>
#endif #endif
...@@ -101,6 +97,7 @@ ...@@ -101,6 +97,7 @@
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "libpq/pqsignal.h" #include "libpq/pqsignal.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "pg_getopt.h"
#include "pgstat.h" #include "pgstat.h"
#include "postmaster/autovacuum.h" #include "postmaster/autovacuum.h"
#include "postmaster/bgworker_internals.h" #include "postmaster/bgworker_internals.h"
...@@ -352,14 +349,6 @@ static volatile bool HaveCrashedWorker = false; ...@@ -352,14 +349,6 @@ static volatile bool HaveCrashedWorker = false;
static unsigned int random_seed = 0; static unsigned int random_seed = 0;
static struct timeval random_start_time; static struct timeval random_start_time;
extern char *optarg;
extern int optind,
opterr;
#ifdef HAVE_INT_OPTRESET
extern int optreset; /* might not be declared by system headers */
#endif
#ifdef USE_BONJOUR #ifdef USE_BONJOUR
static DNSServiceRef bonjour_sdref = NULL; static DNSServiceRef bonjour_sdref = NULL;
#endif #endif
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifndef HAVE_GETRUSAGE #ifndef HAVE_GETRUSAGE
#include "rusagestub.h" #include "rusagestub.h"
...@@ -55,6 +52,7 @@ ...@@ -55,6 +52,7 @@
#include "pg_trace.h" #include "pg_trace.h"
#include "parser/analyze.h" #include "parser/analyze.h"
#include "parser/parser.h" #include "parser/parser.h"
#include "pg_getopt.h"
#include "postmaster/autovacuum.h" #include "postmaster/autovacuum.h"
#include "postmaster/postmaster.h" #include "postmaster/postmaster.h"
#include "replication/walsender.h" #include "replication/walsender.h"
...@@ -77,14 +75,6 @@ ...@@ -77,14 +75,6 @@
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
extern char *optarg;
extern int optind;
#ifdef HAVE_INT_OPTRESET
extern int optreset; /* might not be declared by system headers */
#endif
/* ---------------- /* ----------------
* global variables * global variables
* ---------------- * ----------------
......
...@@ -63,10 +63,6 @@ ...@@ -63,10 +63,6 @@
#include "dumputils.h" #include "dumputils.h"
#include "parallel.h" #include "parallel.h"
extern char *optarg;
extern int optind,
opterr;
typedef struct typedef struct
{ {
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "dumputils.h" #include "dumputils.h"
#include "parallel.h" #include "parallel.h"
#include "getopt_long.h"
#include <ctype.h> #include <ctype.h>
...@@ -50,13 +51,6 @@ ...@@ -50,13 +51,6 @@
#include <termios.h> #include <termios.h>
#endif #endif
#include <unistd.h>
#include "getopt_long.h"
extern char *optarg;
extern int optind;
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
#include <locale.h> #include <locale.h>
#endif #endif
......
...@@ -44,9 +44,6 @@ ...@@ -44,9 +44,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "access/transam.h" #include "access/transam.h"
#include "access/tuptoaster.h" #include "access/tuptoaster.h"
...@@ -55,9 +52,7 @@ ...@@ -55,9 +52,7 @@
#include "catalog/catversion.h" #include "catalog/catversion.h"
#include "catalog/pg_control.h" #include "catalog/pg_control.h"
#include "common/fe_memutils.h" #include "common/fe_memutils.h"
#include "pg_getopt.h"
extern int optind;
extern char *optarg;
static ControlFileData ControlFile; /* pg_control values */ static ControlFileData ControlFile; /* pg_control values */
......
...@@ -386,8 +386,6 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) ...@@ -386,8 +386,6 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
}; };
int optindex; int optindex;
extern char *optarg;
extern int optind;
int c; int c;
memset(options, 0, sizeof *options); memset(options, 0, sizeof *options);
......
...@@ -9,15 +9,7 @@ ...@@ -9,15 +9,7 @@
#ifndef GETOPT_LONG_H #ifndef GETOPT_LONG_H
#define GETOPT_LONG_H #define GETOPT_LONG_H
#ifdef HAVE_GETOPT_H #include "pg_getopt.h"
#include <getopt.h>
#endif
/* These are picked up from the system's getopt() facility. */
extern int opterr;
extern int optind;
extern int optopt;
extern char *optarg;
#ifndef HAVE_STRUCT_OPTION #ifndef HAVE_STRUCT_OPTION
......
/*
* Portions Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Portions Copyright (c) 2003-2014, PostgreSQL Global Development Group
*
* src/include/pg_getopt.h
*/
#ifndef PG_GETOPT_H
#define PG_GETOPT_H
/* POSIX says getopt() is provided by unistd.h */
#include <unistd.h>
/* rely on the system's getopt.h if present */
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
/*
* If we have <getopt.h>, assume it declares these variables, else do that
* ourselves. (We used to just declare them unconditionally, but Cygwin
* doesn't like that.)
*/
#ifndef HAVE_GETOPT_H
extern char *optarg;
extern int optind;
extern int opterr;
extern int optopt;
#ifdef HAVE_INT_OPTRESET
extern int optreset;
#endif
#endif /* HAVE_GETOPT_H */
#ifndef HAVE_GETOPT
extern int getopt(int nargc, char *const * nargv, const char *ostr);
#endif
#endif /* PG_GETOPT_H */
...@@ -382,10 +382,6 @@ extern int fls(int mask); ...@@ -382,10 +382,6 @@ extern int fls(int mask);
#define ftello(a) ftell(a) #define ftello(a) ftell(a)
#endif #endif
#ifndef HAVE_GETOPT
extern int getopt(int nargc, char *const * nargv, const char *ostr);
#endif
#if !defined(HAVE_GETPEEREID) && !defined(WIN32) #if !defined(HAVE_GETPEEREID) && !defined(WIN32)
extern int getpeereid(int sock, uid_t *uid, gid_t *gid); extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
#endif #endif
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "c.h" #include "c.h"
#include "pg_getopt.h"
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
...@@ -49,20 +51,13 @@ int opterr = 1, /* if error message should be printed */ ...@@ -49,20 +51,13 @@ int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */ optind = 1, /* index into parent argv vector */
optopt; /* character checked for validity */ optopt; /* character checked for validity */
char *optarg; /* argument associated with option */ char *optarg; /* argument associated with option */
#else
extern int opterr;
extern int optind;
extern int optopt;
extern char *optarg;
#endif #endif
#define BADCH (int)'?' #define BADCH (int)'?'
#define BADARG (int)':' #define BADARG (int)':'
#define EMSG "" #define EMSG ""
int getopt(int nargc, char *const * nargv, const char *ostr);
/* /*
* getopt * getopt
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
......
...@@ -10,29 +10,17 @@ ...@@ -10,29 +10,17 @@
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#endif #endif
#ifndef WIN32
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#else
int getopt(int argc, char *const argv[], const char *optstring);
#endif /* ! WIN32 */
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "pg_getopt.h"
#include "isolationtester.h" #include "isolationtester.h"
extern int optind;
#define PREP_WAITING "isolationtester_waiting" #define PREP_WAITING "isolationtester_waiting"
/* /*
......
...@@ -8,15 +8,11 @@ ...@@ -8,15 +8,11 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <time.h> #include <time.h>
extern int optind; #include "pg_getopt.h"
extern char *optarg;
#include "private.h" #include "private.h"
#include "pgtz.h" #include "pgtz.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment