postgresql/src/include/port/win32.h
Tom Lane e04a8059a7 Simplify declaring variables exported from libpgcommon and libpgport.
This reverts commits c2d1eea9e and 11b500072, as well as similar hacks
elsewhere, in favor of setting up the PGDLLIMPORT macro so that it can
just be used unconditionally.  That can work because in frontend code,
we need no marking in either the defining or consuming files for a
variable exported from these libraries; and frontend code has no need
to access variables exported from the core backend, either.

While at it, write some actual documentation about the PGDLLIMPORT
and PGDLLEXPORT macros.

Patch by me, based on a suggestion from Robert Haas.

Discussion: https://postgr.es/m/1160385.1638165449@sss.pgh.pa.us
2021-11-29 11:00:00 -05:00

79 lines
2 KiB
C

/* src/include/port/win32.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
/*
* Make sure _WIN32_WINNT has the minimum required value.
* Leave a higher value in place. When building with at least Visual
* Studio 2015 the minimum requirement is Windows Vista (0x0600) to
* get support for GetLocaleInfoEx() with locales. For everything else
* the minimum version is Windows XP (0x0501).
*/
#if defined(_MSC_VER) && _MSC_VER >= 1900
#define MIN_WINNT 0x0600
#else
#define MIN_WINNT 0x0501
#endif
#if defined(_WIN32_WINNT) && _WIN32_WINNT < MIN_WINNT
#undef _WIN32_WINNT
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT MIN_WINNT
#endif
/*
* We need to prevent <crtdefs.h> from defining a symbol conflicting with
* our errcode() function. Since it's likely to get included by standard
* system headers, pre-emptively include it now.
*/
#if defined(_MSC_VER) || defined(HAVE_CRTDEFS_H)
#define errcode __msvc_errcode
#include <crtdefs.h>
#undef errcode
#endif
/*
* defines for dynamic linking on Win32 platform
*/
/*
* Variables declared in the core backend and referenced by loadable
* modules need to be marked "dllimport" in the core build, but
* "dllexport" when the declaration is read in a loadable module.
* No special markings should be used when compiling frontend code.
*/
#ifndef FRONTEND
#ifdef BUILDING_DLL
#define PGDLLIMPORT __declspec (dllexport)
#else
#define PGDLLIMPORT __declspec (dllimport)
#endif
#endif
/*
* Under MSVC, functions exported by a loadable module must be marked
* "dllexport". Other compilers don't need that.
*/
#ifdef _MSC_VER
#define PGDLLEXPORT __declspec (dllexport)
#endif
/*
* Windows headers don't define this structure, but you can define it yourself
* to use the functionality.
*/
struct sockaddr_un
{
unsigned short sun_family;
char sun_path[108];
};
#define HAVE_STRUCT_SOCKADDR_UN 1