Commit ed9b3606 authored by Tom Lane's avatar Tom Lane

Further refactoring of c.h and nearby files.

This continues the work of commit 91aec93e by getting rid of a lot of
Windows-specific funny business in "section 0".  Instead of including
pg_config_os.h in different places depending on platform, let's
standardize on putting it before the system headers, and in consequence
reduce win32.h to just what has to appear before the system headers or
the body of c.h (the latter category seems to include only PGDLLIMPORT
and PGDLLEXPORT).  The rest of what was in win32.h is moved to a new
sub-include of port.h, win32_port.h.  Some of what was in port.h seems
to better belong there too.

It's possible that I missed some declaration ordering dependency that
needs to be preserved, but hopefully the buildfarm will find that
out in short order.

Unlike the previous commit, no back-patch, since this is just cleanup
not a prerequisite for a bug fix.

Discussion: https://postgr.es/m/29650.1510761080@sss.pgh.pa.us
parent 642bafa0
......@@ -9,14 +9,6 @@
*-------------------------------------------------------------------------
*/
#ifdef WIN32
/*
* Need this to get defines for restricted tokens and jobs. And it
* has to be set before any header from the Win32 API is loaded.
*/
#define _WIN32_WINNT 0x0501
#endif
#include "postgres_fe.h"
#include <fcntl.h>
......
......@@ -52,32 +52,9 @@
#include "pg_config.h"
#include "pg_config_manual.h" /* must be after pg_config.h */
/*
* We always rely on the WIN32 macro being set by our build system,
* but _WIN32 is the compiler pre-defined macro. So make sure we define
* WIN32 whenever _WIN32 is set, to facilitate standalone building.
*/
#if defined(_WIN32) && !defined(WIN32)
#define WIN32
#endif
#if !defined(WIN32) && !defined(__CYGWIN__) /* win32 includes further down */
#include "pg_config_os.h" /* must be before any system header files */
#endif
#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H)
#define errcode __msvc_errcode
#include <crtdefs.h>
#undef errcode
#endif
/*
* We have to include stdlib.h here because it defines many of these macros
* on some platforms, and we only want our definitions used if stdlib.h doesn't
* have its own. The same goes for stddef and stdarg if present.
*/
/* System header files that should be available everywhere in Postgres */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -99,11 +76,6 @@
#include <libintl.h>
#endif
#if defined(WIN32) || defined(__CYGWIN__)
/* We have to redefine some system functions after they are included above. */
#include "pg_config_os.h"
#endif
/* ----------------------------------------------------------------
* Section 1: compiler characteristics
......
......@@ -17,6 +17,15 @@
#include <netdb.h>
#include <pwd.h>
/*
* Windows has enough specialized port stuff that we push most of it off
* into another file.
* Note: Some CYGWIN includes might #define WIN32.
*/
#if defined(WIN32) && !defined(__CYGWIN__)
#include "port/win32_port.h"
#endif
/* socket has a different definition on WIN32 */
#ifndef WIN32
typedef int pgsocket;
......@@ -101,11 +110,6 @@ extern int find_other_exec(const char *argv0, const char *target,
/* Doesn't belong here, but this is used with find_other_exec(), so... */
#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
/* Windows security token manipulation (in exec.c) */
#ifdef WIN32
extern BOOL AddUserToTokenDacl(HANDLE hToken);
#endif
#if defined(WIN32) || defined(__CYGWIN__)
#define EXE ".exe"
......@@ -185,36 +189,10 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
#endif
#endif /* USE_REPL_SNPRINTF */
#if defined(WIN32)
/*
* Versions of libintl >= 0.18? try to replace setlocale() with a macro
* to their own versions. Remove the macro, if it exists, because it
* ends up calling the wrong version when the backend and libintl use
* different versions of msvcrt.
*/
#if defined(setlocale)
#undef setlocale
#endif
/*
* Define our own wrapper macro around setlocale() to work around bugs in
* Windows' native setlocale() function.
*/
extern char *pgwin32_setlocale(int category, const char *locale);
#define setlocale(a,b) pgwin32_setlocale(a,b)
#endif /* WIN32 */
/* Portable prompt handling */
extern void simple_prompt(const char *prompt, char *destination, size_t destlen,
bool echo);
#ifdef WIN32
#define PG_SIGNAL_COUNT 32
#define kill(pid,sig) pgkill(pid,sig)
extern int pgkill(int pid, int sig);
#endif
extern int pclose_check(FILE *stream);
/* Global variable holding time zone information. */
......@@ -262,23 +240,6 @@ extern bool pgwin32_is_junction(const char *path);
extern bool rmtree(const char *path, bool rmtopdir);
/*
* stat() is not guaranteed to set the st_size field on win32, so we
* redefine it to our own implementation that is.
*
* We must pull in sys/stat.h here so the system header definition
* goes in first, and we redefine that, and not the other way around.
*
* Some frontends don't need the size from stat, so if UNSAFE_STAT_OK
* is defined we don't bother with this.
*/
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK)
#include <sys/stat.h>
extern int pgwin32_safestat(const char *path, struct stat *buf);
#define stat(a,b) pgwin32_safestat(a,b)
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
/*
......@@ -353,7 +314,7 @@ extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
extern char *crypt(const char *key, const char *setting);
#endif
/* WIN32 handled in port/win32.h */
/* WIN32 handled in port/win32_port.h */
#ifndef WIN32
#define pgoff_t off_t
#ifdef __NetBSD__
......
This diff is collapsed.
This diff is collapsed.
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