|
| 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 | +#ifndefWIN32_ONLY_COMPILER |
| 22 | + |
| 23 | +staticHMODULEkernel32=NULL; |
| 24 | + |
| 25 | +/* |
| 26 | + * Load DLL file just once regardless of how many functions |
| 27 | + * we load/call in it. |
| 28 | + */ |
| 29 | +staticvoid |
| 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 | +typedefBOOL (WINAPI*__RegisterWaitForSingleObject) |
| 48 | +(PHANDLE,HANDLE,WAITORTIMERCALLBACK,PVOID,ULONG,ULONG); |
| 49 | +__RegisterWaitForSingleObject_RegisterWaitForSingleObject=NULL; |
| 50 | + |
| 51 | +BOOLWINAPI |
| 52 | +RegisterWaitForSingleObject(PHANDLEphNewWaitObject, |
| 53 | +HANDLEhObject, |
| 54 | +WAITORTIMERCALLBACKCallback, |
| 55 | +PVOIDContext, |
| 56 | +ULONGdwMilliseconds, |
| 57 | +ULONGdwFlags) |
| 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 | + |