]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/win32-cfgmgr32.c
libpci: Do not build physmem-posix.c when not needed
[pciutils.git] / lib / win32-cfgmgr32.c
index 4acac2eef525868c042caba5add59e785fd24ce1..a001187901486ec88fe559d63d93d94739f22d9b 100644 (file)
@@ -17,6 +17,7 @@
 #include <wchar.h> /* for wcslen(), wcscpy() */
 
 #include "internal.h"
+#include "win32-helpers.h"
 
 /* Unfortunately MinGW32 toolchain does not provide these cfgmgr32 constants. */
 
@@ -213,32 +214,6 @@ cr_strerror(CONFIGRET cr_error_id)
   return cr_errors[cr_error_id];
 }
 
-static const char *
-win32_strerror(DWORD win32_error_id)
-{
-  /*
-   * Use static buffer which is large enough.
-   * Hopefully no Win32 API error message string is longer than 4 kB.
-   */
-  static char buffer[4096];
-  DWORD len;
-
-  len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, win32_error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL);
-
-  /* FormatMessage() automatically appends ".\r\n" to the error message. */
-  if (len && buffer[len-1] == '\n')
-    buffer[--len] = '\0';
-  if (len && buffer[len-1] == '\r')
-    buffer[--len] = '\0';
-  if (len && buffer[len-1] == '.')
-    buffer[--len] = '\0';
-
-  if (!len)
-    sprintf(buffer, "Unknown Win32 error %lu", win32_error_id);
-
-  return buffer;
-}
-
 static int
 fmt_validate(const char *s, int len, const char *fmt)
 {
@@ -267,56 +242,6 @@ seq_xdigit_validate(const char *s, int mult, int min)
   return 1;
 }
 
-static BOOL
-is_non_nt_system(void)
-{
-  OSVERSIONINFOA version;
-  version.dwOSVersionInfoSize = sizeof(version);
-  return GetVersionExA(&version) && version.dwPlatformId < VER_PLATFORM_WIN32_NT;
-}
-
-static BOOL
-is_32bit_on_win8_64bit_system(void)
-{
-#ifdef _WIN64
-  return FALSE;
-#else
-  BOOL (WINAPI *MyIsWow64Process)(HANDLE, PBOOL);
-  OSVERSIONINFOA version;
-  HMODULE kernel32;
-  BOOL is_wow64;
-
-  /* Check for Windows 8 (NT 6.2). */
-  version.dwOSVersionInfoSize = sizeof(version);
-  if (!GetVersionExA(&version) ||
-      version.dwPlatformId != VER_PLATFORM_WIN32_NT ||
-      version.dwMajorVersion < 6 ||
-      (version.dwMajorVersion == 6 && version.dwMinorVersion < 2))
-    return FALSE;
-
-  /*
-   * Check for 64-bit system via IsWow64Process() function exported
-   * from 32-bit kernel32.dll library available on the 64-bit systems.
-   * Resolve pointer to this function at runtime as this code path is
-   * primary running on 32-bit systems where are not available 64-bit
-   * functions.
-   */
-
-  kernel32 = GetModuleHandleA("kernel32.dll");
-  if (!kernel32)
-    return FALSE;
-
-  MyIsWow64Process = (void *)GetProcAddress(kernel32, "IsWow64Process");
-  if (!MyIsWow64Process)
-    return FALSE;
-
-  if (!MyIsWow64Process(GetCurrentProcess(), &is_wow64))
-    return FALSE;
-
-  return is_wow64;
-#endif
-}
-
 static LPWSTR
 get_device_service_name(struct pci_access *a, DEVINST devinst, DEVINSTID_A devinst_id, BOOL *supported)
 {
@@ -995,7 +920,7 @@ fill_resources(struct pci_dev *d, DEVINST devinst, DEVINSTID_A devinst_id)
        * application using the hardware resource APIs. For example: An AMD64
        * application for AMD64 systems.
        */
-      if (cr == CR_CALL_NOT_IMPLEMENTED && is_32bit_on_win8_64bit_system())
+      if (cr == CR_CALL_NOT_IMPLEMENTED && win32_is_32bit_on_win8_64bit_system())
         {
           static BOOL warn_once = FALSE;
           if (!warn_once)
@@ -1010,7 +935,7 @@ fill_resources(struct pci_dev *d, DEVINST devinst, DEVINSTID_A devinst_id)
     }
 
   bar_res_count = 0;
-  non_nt_system = is_non_nt_system();
+  non_nt_system = win32_is_non_nt_system();
 
   is_bar_res = TRUE;
   if (non_nt_system)