|
| 1 | +/*------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * mingwcompat.c |
| 4 | + * MinGW compatibility functions |
| 5 | + * |
| 6 | + * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group |
| 7 | + * |
| 8 | + * IDENTIFICATION |
| 9 | + * $PostgreSQL: pgsql/src/backend/port/win32/mingwcompat.c,v 1.1 2007/10/29 12:35:41 mha Exp $ |
| 10 | + * |
| 11 | + *------------------------------------------------------------------------- |
| 12 | + */ |
| 13 | + |
| 14 | +#include "postgres.h" |
| 15 | + |
| 16 | +/* |
| 17 | + * This file contains loaders for functions that are missing in the MinGW |
| 18 | + * import libraries. It's only for actual Win32 API functions, so they are |
| 19 | + * all present in proper Win32 compilers. |
| 20 | + */ |
| 21 | +#ifndef WIN32_ONLY_COMPILER |
| 22 | + |
| 23 | +static HMODULE kernel32 = NULL; |
| 24 | + |
| 25 | +/* |
| 26 | + * Load DLL file just once regardless of how many functions |
| 27 | + * we load/call in it. |
| 28 | + */ |
| 29 | +static void |
| 30 | +LoadKernel32() |
| 31 | +{ |
| 32 | + if (kernel32 != NULL) |
| 33 | + return; |
| 34 | + |
| 35 | + kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0); |
| 36 | + if (kernel32 == NULL) |
| 37 | + ereport(FATAL, |
| 38 | + (errmsg_internal("could not load kernel32.dll: %d", |
| 39 | + (int)GetLastError()))); |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +/* |
| 44 | + * Replacement for RegisterWaitForSingleObject(), which lives in |
| 45 | + * kernel32.dll· |
| 46 | + */ |
| 47 | +typedef BOOL (WINAPI * __RegisterWaitForSingleObject) |
| 48 | + (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG); |
| 49 | +__RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL; |
| 50 | + |
| 51 | +BOOL WINAPI |
| 52 | +RegisterWaitForSingleObject(PHANDLE phNewWaitObject, |
| 53 | + HANDLE hObject, |
| 54 | + WAITORTIMERCALLBACK Callback, |
| 55 | + PVOID Context, |
| 56 | + ULONG dwMilliseconds, |
| 57 | + ULONG dwFlags) |
| 58 | +{ |
| 59 | + if (_RegisterWaitForSingleObject == NULL) |
| 60 | + { |
| 61 | + LoadKernel32(); |
| 62 | + |
| 63 | + _RegisterWaitForSingleObject = (__RegisterWaitForSingleObject) |
| 64 | + GetProcAddress(kernel32, "RegisterWaitForSingleObject"); |
| 65 | + |
| 66 | + if (_RegisterWaitForSingleObject == NULL) |
| 67 | + ereport(FATAL, |
| 68 | + (errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: %d", |
| 69 | + (int)GetLastError()))); |
| 70 | + } |
| 71 | + |
| 72 | + return (_RegisterWaitForSingleObject) |
| 73 | + (phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags); |
| 74 | +} |
| 75 | + |
| 76 | +#endif |
| 77 | + |
0 commit comments