PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
mingwcompat.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * mingwcompat.c
4  * MinGW compatibility functions
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/backend/port/win32/mingwcompat.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #include "postgres.h"
15 
16 #ifndef _MSC_VER
17 /*
18  * MingW defines an extern to this struct, but the actual struct isn't present
19  * in any library. It's trivial enough that we can safely define it
20  * ourselves.
21  */
22 const struct in6_addr in6addr_any = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}};
23 
24 
25 /*
26  * This file contains loaders for functions that are missing in the MinGW
27  * import libraries. It's only for actual Win32 API functions, so they are
28  * all present in proper Win32 compilers.
29  */
30 static HMODULE kernel32 = NULL;
31 
32 /*
33  * Load DLL file just once regardless of how many functions
34  * we load/call in it.
35  */
36 static void
38 {
39  if (kernel32 != NULL)
40  return;
41 
42  kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0);
43  if (kernel32 == NULL)
44  ereport(FATAL,
45  (errmsg_internal("could not load kernel32.dll: error code %lu",
46  GetLastError())));
47 }
48 
49 
50 /*
51  * Replacement for RegisterWaitForSingleObject(), which lives in
52  * kernel32.dll
53  */
54 typedef
55 BOOL (WINAPI * __RegisterWaitForSingleObject)
56  (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG);
57 static __RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL;
58 
59 BOOL WINAPI
60 RegisterWaitForSingleObject(PHANDLE phNewWaitObject,
61  HANDLE hObject,
62  WAITORTIMERCALLBACK Callback,
63  PVOID Context,
64  ULONG dwMilliseconds,
65  ULONG dwFlags)
66 {
68  {
69  LoadKernel32();
70 
71  _RegisterWaitForSingleObject = (__RegisterWaitForSingleObject)
72  GetProcAddress(kernel32, "RegisterWaitForSingleObject");
73 
75  ereport(FATAL,
76  (errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: error code %lu",
77  GetLastError())));
78  }
79 
81  (phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags);
82 }
83 
84 #endif
const struct in6_addr in6addr_any
Definition: mingwcompat.c:22
BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject, WAITORTIMERCALLBACK Callback, PVOID Context, ULONG dwMilliseconds, ULONG dwFlags)
Definition: mingwcompat.c:60
static void LoadKernel32()
Definition: mingwcompat.c:37
static __RegisterWaitForSingleObject _RegisterWaitForSingleObject
Definition: mingwcompat.c:57
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
static HMODULE kernel32
Definition: mingwcompat.c:30
typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess