Header And Logo

PostgreSQL
| The world's most advanced open source database.

mingwcompat.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * mingwcompat.c
00004  *    MinGW compatibility functions
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  *
00008  * IDENTIFICATION
00009  *    src/backend/port/win32/mingwcompat.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #include "postgres.h"
00015 
00016 #ifndef WIN32_ONLY_COMPILER
00017 /*
00018  * MingW defines an extern to this struct, but the actual struct isn't present
00019  * in any library. It's trivial enough that we can safely define it
00020  * ourselves.
00021  */
00022 const struct in6_addr in6addr_any = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}};
00023 
00024 
00025 /*
00026  * This file contains loaders for functions that are missing in the MinGW
00027  * import libraries. It's only for actual Win32 API functions, so they are
00028  * all present in proper Win32 compilers.
00029  */
00030 static HMODULE kernel32 = NULL;
00031 
00032 /*
00033  * Load DLL file just once regardless of how many functions
00034  * we load/call in it.
00035  */
00036 static void
00037 LoadKernel32()
00038 {
00039     if (kernel32 != NULL)
00040         return;
00041 
00042     kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0);
00043     if (kernel32 == NULL)
00044         ereport(FATAL,
00045               (errmsg_internal("could not load kernel32.dll: error code %lu",
00046                                GetLastError())));
00047 }
00048 
00049 
00050 /*
00051  * Replacement for RegisterWaitForSingleObject(), which lives in
00052  * kernel32.dll
00053  */
00054 typedef
00055 BOOL        (WINAPI * __RegisterWaitForSingleObject)
00056             (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG);
00057 static __RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL;
00058 
00059 BOOL        WINAPI
00060 RegisterWaitForSingleObject(PHANDLE phNewWaitObject,
00061                             HANDLE hObject,
00062                             WAITORTIMERCALLBACK Callback,
00063                             PVOID Context,
00064                             ULONG dwMilliseconds,
00065                             ULONG dwFlags)
00066 {
00067     if (_RegisterWaitForSingleObject == NULL)
00068     {
00069         LoadKernel32();
00070 
00071         _RegisterWaitForSingleObject = (__RegisterWaitForSingleObject)
00072             GetProcAddress(kernel32, "RegisterWaitForSingleObject");
00073 
00074         if (_RegisterWaitForSingleObject == NULL)
00075             ereport(FATAL,
00076                     (errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: error code %lu",
00077                                      GetLastError())));
00078     }
00079 
00080     return (_RegisterWaitForSingleObject)
00081         (phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags);
00082 }
00083 
00084 #endif