Windows: Cleanup header includes and definiions
authorChris Dickens <christopher.a.dickens@gmail.com>
Sat, 19 Dec 2020 21:30:23 +0000 (13:30 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Sat, 19 Dec 2020 21:30:23 +0000 (13:30 -0800)
Now that a sufficiently recent toolchain is required to build, we can
drop a bunch of redundant definitions and get the definitions from the
Windows headers instead. We can also remove a number of '#ifndef'
guards because no header included by the source would have defined the
symbols being protected.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/windows_common.c
libusb/os/windows_common.h
libusb/os/windows_usbdk.c
libusb/os/windows_winusb.c
libusb/os/windows_winusb.h
libusb/version_nano.h

index 119ed49..efb746b 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <config.h>
 
-#include <process.h>
 #include <stdio.h>
 
 #include "libusbi.h"
index 0c4b94c..d9958c6 100644 (file)
@@ -52,6 +52,8 @@
 #define _strdup strdup
 // _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread
 #define _beginthreadex(a, b, c, d, e, f) CreateThread(a, b, (LPTHREAD_START_ROUTINE)c, d, e, (LPDWORD)f)
+#else
+#include <process.h>
 #endif
 
 #define safe_free(p) do {if (p != NULL) {free((void *)p); p = NULL;}} while (0)
index c9ebfcf..76aba16 100644 (file)
@@ -27,7 +27,6 @@
 #include <stdio.h>
 
 #include "libusbi.h"
-#include "windows_common.h"
 #include "windows_usbdk.h"
 
 #if !defined(STATUS_SUCCESS)
index f291b8e..d38788e 100644 (file)
 #include <windows.h>
 #include <setupapi.h>
 #include <ctype.h>
-#include <fcntl.h>
-#include <process.h>
 #include <stdio.h>
-#include <objbase.h>
-#include <winioctl.h>
 
 #include "libusbi.h"
-#include "windows_common.h"
 #include "windows_winusb.h"
 
 #define HANDLE_VALID(h) (((h) != NULL) && ((h) != INVALID_HANDLE_VALUE))
index 49355d4..439042f 100644 (file)
 #ifndef LIBUSB_WINDOWS_WINUSB_H
 #define LIBUSB_WINDOWS_WINUSB_H
 
-#include "windows_common.h"
-
-#if defined(_MSC_VER)
-// disable /W4 MSVC warnings that are benign
-#pragma warning(disable:4214)  // bit field types other than int
-#endif
+#include <devioctl.h>
+#include <guiddef.h>
 
-// Missing from MSVC6 setupapi.h
-#ifndef SPDRP_ADDRESS
-#define SPDRP_ADDRESS          28
-#endif
-#ifndef SPDRP_INSTALL_STATE
-#define SPDRP_INSTALL_STATE    34
-#endif
+#include "windows_common.h"
 
 #define MAX_CTRL_BUFFER_LENGTH 4096
 #define MAX_USB_STRING_LENGTH  128
 // http://msdn.microsoft.com/en-us/library/ff545978.aspx
 // http://msdn.microsoft.com/en-us/library/ff545972.aspx
 // http://msdn.microsoft.com/en-us/library/ff545982.aspx
-#ifndef GUID_DEVINTERFACE_USB_HOST_CONTROLLER
-const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = {0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27}};
-#endif
-#ifndef GUID_DEVINTERFACE_USB_DEVICE
-const GUID GUID_DEVINTERFACE_USB_DEVICE = {0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
-#endif
-#ifndef GUID_DEVINTERFACE_USB_HUB
-const GUID GUID_DEVINTERFACE_USB_HUB = {0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15, 0x00, 0xA0, 0xC9, 0x06, 0xBE, 0xD8}};
-#endif
-#ifndef GUID_DEVINTERFACE_LIBUSB0_FILTER
-const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = {0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9}};
-#endif
+static const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = {0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27}};
+static const GUID GUID_DEVINTERFACE_USB_HUB = {0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15, 0x00, 0xA0, 0xC9, 0x06, 0xBE, 0xD8}};
+static const GUID GUID_DEVINTERFACE_USB_DEVICE = {0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
+static const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = {0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9}};
 
 // The following define MUST be == sizeof(USB_DESCRIPTOR_REQUEST)
 #define USB_DESCRIPTOR_REQUEST_SIZE    12U
@@ -152,11 +134,6 @@ struct libusb_hid_descriptor {
 #define LIBUSB_REQ_IN(request_type)            ((request_type) & LIBUSB_ENDPOINT_IN)
 #define LIBUSB_REQ_OUT(request_type)           (!LIBUSB_REQ_IN(request_type))
 
-#ifndef CTL_CODE
-#define CTL_CODE(DeviceType, Function, Method, Access) \
-       (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
-#endif
-
 // The following are used for HID reports IOCTLs
 #define HID_IN_CTL_CODE(id) \
        CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_IN_DIRECT, FILE_ANY_ACCESS)
@@ -282,23 +259,12 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, BOOL, p, SetupDiDestroyDeviceInfoList, (HDEVIN
 DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDevRegKey, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM));
 DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, DWORD, DWORD));
 
+#define FILE_DEVICE_USB        FILE_DEVICE_UNKNOWN
 
-#ifndef USB_GET_NODE_INFORMATION
 #define USB_GET_NODE_INFORMATION                       258
-#endif
-#ifndef USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
 #define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION                260
-#endif
-#ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX
 #define USB_GET_NODE_CONNECTION_INFORMATION_EX         274
-#endif
-#ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX_V2
 #define USB_GET_NODE_CONNECTION_INFORMATION_EX_V2      279
-#endif
-
-#ifndef FILE_DEVICE_USB
-#define FILE_DEVICE_USB                FILE_DEVICE_UNKNOWN
-#endif
 
 #define USB_CTL_CODE(id) \
        CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
@@ -342,6 +308,12 @@ typedef enum _USB_HUB_NODE {
        UsbMIParent
 } USB_HUB_NODE;
 
+#if defined(_MSC_VER)
+// disable /W4 MSVC warnings that are benign
+#pragma warning(push)
+#pragma warning(disable:4214)  // bit field types other than int
+#endif
+
 // Most of the structures below need to be packed
 #include <pshpack1.h>
 
@@ -439,6 +411,11 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
 
 #include <poppack.h>
 
+#if defined(_MSC_VER)
+// Restore original warnings
+#pragma warning(pop)
+#endif
+
 /* winusb.dll interface */
 
 /* pipe policies */
index e93a2fe..e0cb374 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11589
+#define LIBUSB_NANO 11590