introduce-pg-getopt-header.patch

text/x-patch

Filename: introduce-pg-getopt-header.patch
Type: text/x-patch
Part: 0
Message: Re: narwhal and PGDLLIMPORT

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
contrib/oid2name/oid2name.c 1 5
contrib/pg_archivecleanup/pg_archivecleanup.c 1 10
contrib/pgbench/pgbench.c 0 3
contrib/pg_standby/pg_standby.c 1 10
contrib/vacuumlo/vacuumlo.c 1 4
src/backend/bootstrap/bootstrap.c 1 6
src/backend/postmaster/postmaster.c 1 12
src/backend/tcop/postgres.c 1 11
src/bin/pg_dump/pg_dump.c 0 4
src/bin/pg_dump/pg_restore.c 0 3
src/bin/pg_resetxlog/pg_resetxlog.c 1 7
src/bin/psql/startup.c 0 2
src/include/getopt_long.h 1 9
src/include/pg_getopt.h 33 0
src/include/port.h 0 4
src/port/getopt.c 2 8
src/test/isolation/isolationtester.c 1 10
src/timezone/zic.c 1 5
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 67d7934..7fc9f42 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -10,13 +10,9 @@
 #include "postgres_fe.h"
 
 #include <unistd.h>
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-
-extern char *optarg;
 
 #include "libpq-fe.h"
+#include "pg_getopt.h"
 
 /* an extensible array to keep track of elements to show */
 typedef struct
diff --git a/contrib/pg_archivecleanup/pg_archivecleanup.c b/contrib/pg_archivecleanup/pg_archivecleanup.c
index f12331a..07b27b7 100644
--- a/contrib/pg_archivecleanup/pg_archivecleanup.c
+++ b/contrib/pg_archivecleanup/pg_archivecleanup.c
@@ -18,19 +18,10 @@
 #include <fcntl.h>
 #include <signal.h>
 
-#ifndef WIN32
 #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;
-extern int	optind;
+#include "pg_getopt.h"
 
 const char *progname;
 
diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c
index 059c820..9e4a1da 100644
--- a/contrib/pg_standby/pg_standby.c
+++ b/contrib/pg_standby/pg_standby.c
@@ -29,19 +29,10 @@
 #include <fcntl.h>
 #include <signal.h>
 
-#ifdef WIN32
-int			getopt(int argc, char *const argv[], const char *optstring);
-#else
 #include <sys/time.h>
 #include <unistd.h>
 
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-#endif   /* ! WIN32 */
-
-extern char *optarg;
-extern int	optind;
+#include "pg_getopt.h"
 
 const char *progname;
 
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 16b7ab5..0cba8ef 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -89,9 +89,6 @@ static int	pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start
 static int	pthread_join(pthread_t th, void **thread_return);
 #endif
 
-extern char *optarg;
-extern int	optind;
-
 
 /********************************************************************
  * some configurable parameters */
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 3981dd6..c2e5bad 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -22,15 +22,12 @@
 #endif
 
 #include "libpq-fe.h"
+#include "pg_getopt.h"
 
 #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
 
 #define BUFSIZE			1024
 
-extern char *optarg;
-extern int	optind,
-			opterr;
-
 enum trivalue
 {
 	TRI_DEFAULT,
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index ef6311b..c36e71d 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -17,9 +17,6 @@
 #include <time.h>
 #include <unistd.h>
 #include <signal.h>
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
 
 #include "access/htup_details.h"
 #include "bootstrap/bootstrap.h"
@@ -29,6 +26,7 @@
 #include "libpq/pqsignal.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
+#include "pg_getopt.h"
 #include "postmaster/bgwriter.h"
 #include "postmaster/startup.h"
 #include "postmaster/walwriter.h"
@@ -46,9 +44,6 @@
 #include "utils/relmapper.h"
 #include "utils/tqual.h"
 
-extern int	optind;
-extern char *optarg;
-
 uint32		bootstrap_data_checksum_version = 0;		/* No checksum */
 
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7adc410..6bb2a47 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -83,10 +83,6 @@
 #include <sys/select.h>
 #endif
 
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-
 #ifdef USE_BONJOUR
 #include <dns_sd.h>
 #endif
@@ -101,6 +97,7 @@
 #include "libpq/libpq.h"
 #include "libpq/pqsignal.h"
 #include "miscadmin.h"
+#include "pg_getopt.h"
 #include "pgstat.h"
 #include "postmaster/autovacuum.h"
 #include "postmaster/bgworker_internals.h"
@@ -352,14 +349,6 @@ static volatile bool HaveCrashedWorker = false;
 static unsigned int random_seed = 0;
 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
 static DNSServiceRef bonjour_sdref = NULL;
 #endif
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index b7612b9..a230d7e 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -32,9 +32,6 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #endif
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
 
 #ifndef HAVE_GETRUSAGE
 #include "rusagestub.h"
@@ -55,6 +52,7 @@
 #include "pg_trace.h"
 #include "parser/analyze.h"
 #include "parser/parser.h"
+#include "pg_getopt.h"
 #include "postmaster/autovacuum.h"
 #include "postmaster/postmaster.h"
 #include "replication/walsender.h"
@@ -77,14 +75,6 @@
 #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
  * ----------------
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 458a118..2ce8e6d 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -63,10 +63,6 @@
 #include "dumputils.h"
 #include "parallel.h"
 
-extern char *optarg;
-extern int	optind,
-			opterr;
-
 
 typedef struct
 {
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index bb65253..3af1fff 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -54,9 +54,6 @@
 
 #include "getopt_long.h"
 
-extern char *optarg;
-extern int	optind;
-
 #ifdef ENABLE_NLS
 #include <locale.h>
 #endif
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 03f2fad..81cee52 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -44,9 +44,6 @@
 #include <sys/time.h>
 #include <time.h>
 #include <unistd.h>
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
 
 #include "access/transam.h"
 #include "access/tuptoaster.h"
@@ -55,10 +52,7 @@
 #include "catalog/catversion.h"
 #include "catalog/pg_control.h"
 #include "common/fe_memutils.h"
-
-extern int	optind;
-extern char *optarg;
-
+#include "pg_getopt.h"
 
 static ControlFileData ControlFile;		/* pg_control values */
 static XLogSegNo newXlogSegNo;	/* new XLOG segment # */
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 9194801..1061992 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -386,8 +386,6 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
 	};
 
 	int			optindex;
-	extern char *optarg;
-	extern int	optind;
 	int			c;
 
 	memset(options, 0, sizeof *options);
diff --git a/src/include/getopt_long.h b/src/include/getopt_long.h
index 563719b..e23c21f 100644
--- a/src/include/getopt_long.h
+++ b/src/include/getopt_long.h
@@ -9,15 +9,7 @@
 #ifndef GETOPT_LONG_H
 #define GETOPT_LONG_H
 
-#ifdef HAVE_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;
+#include "pg_getopt.h"
 
 #ifndef HAVE_STRUCT_OPTION
 
diff --git a/src/include/pg_getopt.h b/src/include/pg_getopt.h
new file mode 100644
index 0000000..de524a0
--- /dev/null
+++ b/src/include/pg_getopt.h
@@ -0,0 +1,33 @@
+/*
+ * 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
+
+#include <unistd.h>
+
+/* rely on the system's getopt.h if present */
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#ifndef HAVE_GETOPT
+extern int	getopt(int nargc, char *const * nargv, const char *ostr);
+
+extern int	opterr;
+extern int	optind;
+extern int	optopt;
+extern char *optarg;
+
+#ifdef HAVE_INT_OPTRESET
+extern int optreset;
+#endif   /* HAVE_INT_OPTRESET */
+
+#endif   /* HAVE_GETOPT */
+
+#endif   /* PG_GETOPT_H */
diff --git a/src/include/port.h b/src/include/port.h
index f50fbec..aeb7754 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -382,10 +382,6 @@ extern int	fls(int mask);
 #define ftello(a)		ftell(a)
 #endif
 
-#ifndef HAVE_GETOPT
-extern int	getopt(int nargc, char *const * nargv, const char *ostr);
-#endif
-
 #if !defined(HAVE_GETPEEREID) && !defined(WIN32)
 extern int	getpeereid(int sock, uid_t *uid, gid_t *gid);
 #endif
diff --git a/src/port/getopt.c b/src/port/getopt.c
index eb50cba..0d6332f 100644
--- a/src/port/getopt.c
+++ b/src/port/getopt.c
@@ -32,6 +32,8 @@
 
 #include "c.h"
 
+#include "pg_getopt.h"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
 #endif   /* LIBC_SCCS and not lint */
@@ -49,20 +51,12 @@ int			opterr = 1,			/* if error message should be printed */
 			optind = 1,			/* index into parent argv vector */
 			optopt;				/* character checked for validity */
 char	   *optarg;				/* argument associated with option */
-#else
-
-extern int	opterr;
-extern int	optind;
-extern int	optopt;
-extern char *optarg;
 #endif
 
 #define BADCH	(int)'?'
 #define BADARG	(int)':'
 #define EMSG	""
 
-int			getopt(int nargc, char *const * nargv, const char *ostr);
-
 /*
  * getopt
  *	Parse argc/argv argument vector.
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index e936c01..56d5700 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -11,28 +11,19 @@
 #include <windows.h>
 #endif
 
-#ifndef WIN32
 #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
 #include <sys/select.h>
 #endif
 
 #include "libpq-fe.h"
 #include "pqexpbuffer.h"
+#include "pg_getopt.h"
 
 #include "isolationtester.h"
 
-extern int	optind;
-
 #define PREP_WAITING "isolationtester_waiting"
 
 /*
diff --git a/src/timezone/zic.c b/src/timezone/zic.c
index a399d1f..cda7042 100644
--- a/src/timezone/zic.c
+++ b/src/timezone/zic.c
@@ -8,15 +8,11 @@
 
 #include "postgres_fe.h"
 
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
 #include <limits.h>
 #include <locale.h>
 #include <time.h>
 
-extern int	optind;
-extern char *optarg;
+#include "pg_getopt.h"
 
 #include "private.h"
 #include "pgtz.h"