usb 1.7.2-prebuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/prebuild.yml +62 -0
- package/.gitmodules +3 -0
- package/LICENSE +7 -0
- package/Readme.md +339 -0
- package/binding.gyp +90 -0
- package/libusb/.gitattributes +11 -0
- package/libusb/.private/README.txt +5 -0
- package/libusb/.private/bd.cmd +89 -0
- package/libusb/.private/bm.sh +54 -0
- package/libusb/.private/bwince.cmd +57 -0
- package/libusb/.private/post-rewrite.sh +28 -0
- package/libusb/.private/pre-commit.sh +42 -0
- package/libusb/.private/wbs.txt +61 -0
- package/libusb/.private/wbs_wince.txt +42 -0
- package/libusb/AUTHORS +78 -0
- package/libusb/COPYING +504 -0
- package/libusb/ChangeLog +211 -0
- package/libusb/INSTALL +234 -0
- package/libusb/INSTALL_WIN.txt +73 -0
- package/libusb/Makefile.am +28 -0
- package/libusb/NEWS +2 -0
- package/libusb/PORTING +94 -0
- package/libusb/README +28 -0
- package/libusb/README.git +41 -0
- package/libusb/TODO +2 -0
- package/libusb/Xcode/common.xcconfig +49 -0
- package/libusb/Xcode/debug.xcconfig +29 -0
- package/libusb/Xcode/libusb.xcconfig +21 -0
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
- package/libusb/Xcode/libusb_debug.xcconfig +21 -0
- package/libusb/Xcode/libusb_release.xcconfig +21 -0
- package/libusb/Xcode/release.xcconfig +30 -0
- package/libusb/android/README +114 -0
- package/libusb/android/jni/Android.mk +23 -0
- package/libusb/android/jni/Application.mk +24 -0
- package/libusb/android/jni/examples.mk +134 -0
- package/libusb/android/jni/libusb.mk +54 -0
- package/libusb/android/jni/tests.mk +56 -0
- package/libusb/autogen.sh +8 -0
- package/libusb/bootstrap.sh +19 -0
- package/libusb/configure.ac +304 -0
- package/libusb/doc/Makefile.am +9 -0
- package/libusb/doc/doxygen.cfg.in +1288 -0
- package/libusb/doc/libusb.png +0 -0
- package/libusb/examples/Makefile.am +19 -0
- package/libusb/examples/dpfp.c +506 -0
- package/libusb/examples/dpfp_threaded.c +544 -0
- package/libusb/examples/ezusb.c +831 -0
- package/libusb/examples/ezusb.h +120 -0
- package/libusb/examples/fxload.c +287 -0
- package/libusb/examples/getopt/getopt.c +1060 -0
- package/libusb/examples/getopt/getopt.h +180 -0
- package/libusb/examples/getopt/getopt1.c +188 -0
- package/libusb/examples/hotplugtest.c +104 -0
- package/libusb/examples/listdevs.c +71 -0
- package/libusb/examples/sam3u_benchmark.c +193 -0
- package/libusb/examples/xusb.c +1129 -0
- package/libusb/libusb/Makefile.am +75 -0
- package/libusb/libusb/core.c +2342 -0
- package/libusb/libusb/descriptor.c +1199 -0
- package/libusb/libusb/hotplug.c +327 -0
- package/libusb/libusb/hotplug.h +82 -0
- package/libusb/libusb/io.c +2631 -0
- package/libusb/libusb/libusb-1.0.def +166 -0
- package/libusb/libusb/libusb-1.0.rc +61 -0
- package/libusb/libusb/libusb.h +1998 -0
- package/libusb/libusb/libusbi.h +1040 -0
- package/libusb/libusb/os/darwin_usb.c +2009 -0
- package/libusb/libusb/os/darwin_usb.h +162 -0
- package/libusb/libusb/os/linux_netlink.c +369 -0
- package/libusb/libusb/os/linux_udev.c +307 -0
- package/libusb/libusb/os/linux_usbfs.c +2695 -0
- package/libusb/libusb/os/linux_usbfs.h +192 -0
- package/libusb/libusb/os/netbsd_usb.c +738 -0
- package/libusb/libusb/os/openbsd_usb.c +832 -0
- package/libusb/libusb/os/poll_posix.c +51 -0
- package/libusb/libusb/os/poll_posix.h +11 -0
- package/libusb/libusb/os/poll_windows.c +796 -0
- package/libusb/libusb/os/poll_windows.h +131 -0
- package/libusb/libusb/os/threads_posix.c +82 -0
- package/libusb/libusb/os/threads_posix.h +50 -0
- package/libusb/libusb/os/threads_windows.c +212 -0
- package/libusb/libusb/os/threads_windows.h +87 -0
- package/libusb/libusb/os/wince_usb.c +1032 -0
- package/libusb/libusb/os/wince_usb.h +131 -0
- package/libusb/libusb/os/windows_common.h +108 -0
- package/libusb/libusb/os/windows_usb.c +5347 -0
- package/libusb/libusb/os/windows_usb.h +971 -0
- package/libusb/libusb/strerror.c +199 -0
- package/libusb/libusb/sync.c +307 -0
- package/libusb/libusb/version.h +18 -0
- package/libusb/libusb/version_nano.h +1 -0
- package/libusb/libusb-1.0.pc.in +11 -0
- package/libusb/msvc/config.h +50 -0
- package/libusb/msvc/ddk_build.cmd +175 -0
- package/libusb/msvc/errno.h +102 -0
- package/libusb/msvc/fxload_2010.vcxproj +170 -0
- package/libusb/msvc/fxload_2010.vcxproj.filters +25 -0
- package/libusb/msvc/fxload_2012.vcxproj +174 -0
- package/libusb/msvc/fxload_2012.vcxproj.filters +25 -0
- package/libusb/msvc/fxload_2013.vcxproj +174 -0
- package/libusb/msvc/fxload_sources +23 -0
- package/libusb/msvc/getopt_2005.vcproj +288 -0
- package/libusb/msvc/getopt_2010.vcxproj +131 -0
- package/libusb/msvc/getopt_2010.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2012.vcxproj +136 -0
- package/libusb/msvc/getopt_2012.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2013.vcxproj +136 -0
- package/libusb/msvc/getopt_sources +20 -0
- package/libusb/msvc/hotplugtest_2010.vcxproj +163 -0
- package/libusb/msvc/hotplugtest_2010.vcxproj.filters +14 -0
- package/libusb/msvc/hotplugtest_2012.vcxproj +167 -0
- package/libusb/msvc/hotplugtest_2012.vcxproj.filters +14 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +167 -0
- package/libusb/msvc/hotplugtest_sources +20 -0
- package/libusb/msvc/inttypes.h +295 -0
- package/libusb/msvc/libusb.dsw +71 -0
- package/libusb/msvc/libusb_2005.sln +95 -0
- package/libusb/msvc/libusb_2010.sln +94 -0
- package/libusb/msvc/libusb_2012.sln +94 -0
- package/libusb/msvc/libusb_2013.sln +100 -0
- package/libusb/msvc/libusb_2015.sln +100 -0
- package/libusb/msvc/libusb_dll.dsp +194 -0
- package/libusb/msvc/libusb_dll_2005.vcproj +436 -0
- package/libusb/msvc/libusb_dll_2010.vcxproj +170 -0
- package/libusb/msvc/libusb_dll_2010.vcxproj.filters +81 -0
- package/libusb/msvc/libusb_dll_2012.vcxproj +175 -0
- package/libusb/msvc/libusb_dll_2012.vcxproj.filters +84 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +175 -0
- package/libusb/msvc/libusb_dll_wince.vcproj +1243 -0
- package/libusb/msvc/libusb_sources +38 -0
- package/libusb/msvc/libusb_static.dsp +174 -0
- package/libusb/msvc/libusb_static_2005.vcproj +362 -0
- package/libusb/msvc/libusb_static_2010.vcxproj +156 -0
- package/libusb/msvc/libusb_static_2010.vcxproj.filters +74 -0
- package/libusb/msvc/libusb_static_2012.vcxproj +160 -0
- package/libusb/msvc/libusb_static_2012.vcxproj.filters +74 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +160 -0
- package/libusb/msvc/libusb_static_wince.vcproj +1185 -0
- package/libusb/msvc/libusb_wince.sln +246 -0
- package/libusb/msvc/listdevs.dsp +103 -0
- package/libusb/msvc/listdevs_2005.vcproj +360 -0
- package/libusb/msvc/listdevs_2010.vcxproj +165 -0
- package/libusb/msvc/listdevs_2010.vcxproj.filters +14 -0
- package/libusb/msvc/listdevs_2012.vcxproj +169 -0
- package/libusb/msvc/listdevs_2012.vcxproj.filters +14 -0
- package/libusb/msvc/listdevs_2013.vcxproj +169 -0
- package/libusb/msvc/listdevs_sources +19 -0
- package/libusb/msvc/listdevs_wince.vcproj +1120 -0
- package/libusb/msvc/missing.c +80 -0
- package/libusb/msvc/missing.h +32 -0
- package/libusb/msvc/stdint.h +256 -0
- package/libusb/msvc/stress_2005.vcproj +390 -0
- package/libusb/msvc/stress_2010.vcxproj +167 -0
- package/libusb/msvc/stress_2010.vcxproj.filters +25 -0
- package/libusb/msvc/stress_2012.vcxproj +171 -0
- package/libusb/msvc/stress_2012.vcxproj.filters +25 -0
- package/libusb/msvc/stress_2013.vcxproj +171 -0
- package/libusb/msvc/stress_wince.vcproj +1128 -0
- package/libusb/msvc/xusb.dsp +102 -0
- package/libusb/msvc/xusb_2005.vcproj +344 -0
- package/libusb/msvc/xusb_2010.vcxproj +163 -0
- package/libusb/msvc/xusb_2010.vcxproj.filters +14 -0
- package/libusb/msvc/xusb_2012.vcxproj +167 -0
- package/libusb/msvc/xusb_2012.vcxproj.filters +14 -0
- package/libusb/msvc/xusb_2013.vcxproj +167 -0
- package/libusb/msvc/xusb_sources +20 -0
- package/libusb/msvc/xusb_wince.vcproj +1120 -0
- package/libusb/tests/Makefile.am +6 -0
- package/libusb/tests/libusb_testlib.h +107 -0
- package/libusb/tests/stress.c +160 -0
- package/libusb/tests/testlib.c +281 -0
- package/libusb.gypi +136 -0
- package/libusb_config/config.h +1 -0
- package/package.json +69 -0
- package/src/device.cc +412 -0
- package/src/helpers.h +64 -0
- package/src/node_usb.cc +319 -0
- package/src/node_usb.h +120 -0
- package/src/transfer.cc +148 -0
- package/src/uv_async_queue.h +33 -0
- package/test/usb.coffee +191 -0
- package/usb.js +524 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Windows CE backend for libusb 1.0
|
|
3
|
+
* Copyright © 2011-2013 RealVNC Ltd.
|
|
4
|
+
* Portions taken from Windows backend, which is
|
|
5
|
+
* Copyright © 2009-2010 Pete Batard <pbatard@gmail.com>
|
|
6
|
+
* With contributions from Michael Plante, Orin Eman et al.
|
|
7
|
+
* Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
|
|
8
|
+
* Major code testing contribution by Xiaofan Chen
|
|
9
|
+
*
|
|
10
|
+
* This library is free software; you can redistribute it and/or
|
|
11
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
12
|
+
* License as published by the Free Software Foundation; either
|
|
13
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This library is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18
|
+
* Lesser General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
21
|
+
* License along with this library; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23
|
+
*/
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include "windows_common.h"
|
|
27
|
+
|
|
28
|
+
#include <windows.h>
|
|
29
|
+
#include "poll_windows.h"
|
|
30
|
+
|
|
31
|
+
#define MAX_DEVICE_COUNT 256
|
|
32
|
+
|
|
33
|
+
// This is a modified dump of the types in the ceusbkwrapper.h library header
|
|
34
|
+
// with functions transformed into extern pointers.
|
|
35
|
+
//
|
|
36
|
+
// This backend dynamically loads ceusbkwrapper.dll and doesn't include
|
|
37
|
+
// ceusbkwrapper.h directly to simplify the build process. The kernel
|
|
38
|
+
// side wrapper driver is built using the platform image build tools,
|
|
39
|
+
// which makes it difficult to reference directly from the libusb build
|
|
40
|
+
// system.
|
|
41
|
+
struct UKW_DEVICE_PRIV;
|
|
42
|
+
typedef struct UKW_DEVICE_PRIV *UKW_DEVICE;
|
|
43
|
+
typedef UKW_DEVICE *PUKW_DEVICE, *LPUKW_DEVICE;
|
|
44
|
+
|
|
45
|
+
typedef struct {
|
|
46
|
+
UINT8 bLength;
|
|
47
|
+
UINT8 bDescriptorType;
|
|
48
|
+
UINT16 bcdUSB;
|
|
49
|
+
UINT8 bDeviceClass;
|
|
50
|
+
UINT8 bDeviceSubClass;
|
|
51
|
+
UINT8 bDeviceProtocol;
|
|
52
|
+
UINT8 bMaxPacketSize0;
|
|
53
|
+
UINT16 idVendor;
|
|
54
|
+
UINT16 idProduct;
|
|
55
|
+
UINT16 bcdDevice;
|
|
56
|
+
UINT8 iManufacturer;
|
|
57
|
+
UINT8 iProduct;
|
|
58
|
+
UINT8 iSerialNumber;
|
|
59
|
+
UINT8 bNumConfigurations;
|
|
60
|
+
} UKW_DEVICE_DESCRIPTOR, *PUKW_DEVICE_DESCRIPTOR, *LPUKW_DEVICE_DESCRIPTOR;
|
|
61
|
+
|
|
62
|
+
typedef struct {
|
|
63
|
+
UINT8 bmRequestType;
|
|
64
|
+
UINT8 bRequest;
|
|
65
|
+
UINT16 wValue;
|
|
66
|
+
UINT16 wIndex;
|
|
67
|
+
UINT16 wLength;
|
|
68
|
+
} UKW_CONTROL_HEADER, *PUKW_CONTROL_HEADER, *LPUKW_CONTROL_HEADER;
|
|
69
|
+
|
|
70
|
+
// Collection of flags which can be used when issuing transfer requests
|
|
71
|
+
/* Indicates that the transfer direction is 'in' */
|
|
72
|
+
#define UKW_TF_IN_TRANSFER 0x00000001
|
|
73
|
+
/* Indicates that the transfer direction is 'out' */
|
|
74
|
+
#define UKW_TF_OUT_TRANSFER 0x00000000
|
|
75
|
+
/* Specifies that the transfer should complete as soon as possible,
|
|
76
|
+
* even if no OVERLAPPED structure has been provided. */
|
|
77
|
+
#define UKW_TF_NO_WAIT 0x00000100
|
|
78
|
+
/* Indicates that transfers shorter than the buffer are ok */
|
|
79
|
+
#define UKW_TF_SHORT_TRANSFER_OK 0x00000200
|
|
80
|
+
#define UKW_TF_SEND_TO_DEVICE 0x00010000
|
|
81
|
+
#define UKW_TF_SEND_TO_INTERFACE 0x00020000
|
|
82
|
+
#define UKW_TF_SEND_TO_ENDPOINT 0x00040000
|
|
83
|
+
/* Don't block when waiting for memory allocations */
|
|
84
|
+
#define UKW_TF_DONT_BLOCK_FOR_MEM 0x00080000
|
|
85
|
+
|
|
86
|
+
/* Value to use when dealing with configuration values, such as UkwGetConfigDescriptor,
|
|
87
|
+
* to specify the currently active configuration for the device. */
|
|
88
|
+
#define UKW_ACTIVE_CONFIGURATION -1
|
|
89
|
+
|
|
90
|
+
DLL_DECLARE(WINAPI, HANDLE, UkwOpenDriver, ());
|
|
91
|
+
DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceList, (HANDLE, LPUKW_DEVICE, DWORD, LPDWORD));
|
|
92
|
+
DLL_DECLARE(WINAPI, void, UkwReleaseDeviceList, (HANDLE, LPUKW_DEVICE, DWORD));
|
|
93
|
+
DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceAddress, (UKW_DEVICE, unsigned char*, unsigned char*, unsigned long*));
|
|
94
|
+
DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceDescriptor, (UKW_DEVICE, LPUKW_DEVICE_DESCRIPTOR));
|
|
95
|
+
DLL_DECLARE(WINAPI, BOOL, UkwGetConfigDescriptor, (UKW_DEVICE, DWORD, LPVOID, DWORD, LPDWORD));
|
|
96
|
+
DLL_DECLARE(WINAPI, void, UkwCloseDriver, (HANDLE));
|
|
97
|
+
DLL_DECLARE(WINAPI, BOOL, UkwCancelTransfer, (UKW_DEVICE, LPOVERLAPPED, DWORD));
|
|
98
|
+
DLL_DECLARE(WINAPI, BOOL, UkwIssueControlTransfer, (UKW_DEVICE, DWORD, LPUKW_CONTROL_HEADER, LPVOID, DWORD, LPDWORD, LPOVERLAPPED));
|
|
99
|
+
DLL_DECLARE(WINAPI, BOOL, UkwClaimInterface, (UKW_DEVICE, DWORD));
|
|
100
|
+
DLL_DECLARE(WINAPI, BOOL, UkwReleaseInterface, (UKW_DEVICE, DWORD));
|
|
101
|
+
DLL_DECLARE(WINAPI, BOOL, UkwSetInterfaceAlternateSetting, (UKW_DEVICE, DWORD, DWORD));
|
|
102
|
+
DLL_DECLARE(WINAPI, BOOL, UkwClearHaltHost, (UKW_DEVICE, UCHAR));
|
|
103
|
+
DLL_DECLARE(WINAPI, BOOL, UkwClearHaltDevice, (UKW_DEVICE, UCHAR));
|
|
104
|
+
DLL_DECLARE(WINAPI, BOOL, UkwGetConfig, (UKW_DEVICE, PUCHAR));
|
|
105
|
+
DLL_DECLARE(WINAPI, BOOL, UkwSetConfig, (UKW_DEVICE, UCHAR));
|
|
106
|
+
DLL_DECLARE(WINAPI, BOOL, UkwResetDevice, (UKW_DEVICE));
|
|
107
|
+
DLL_DECLARE(WINAPI, BOOL, UkwKernelDriverActive, (UKW_DEVICE, DWORD, PBOOL));
|
|
108
|
+
DLL_DECLARE(WINAPI, BOOL, UkwAttachKernelDriver, (UKW_DEVICE, DWORD));
|
|
109
|
+
DLL_DECLARE(WINAPI, BOOL, UkwDetachKernelDriver, (UKW_DEVICE, DWORD));
|
|
110
|
+
DLL_DECLARE(WINAPI, BOOL, UkwIssueBulkTransfer, (UKW_DEVICE, DWORD, UCHAR, LPVOID, DWORD, LPDWORD, LPOVERLAPPED));
|
|
111
|
+
DLL_DECLARE(WINAPI, BOOL, UkwIsPipeHalted, (UKW_DEVICE, UCHAR, LPBOOL));
|
|
112
|
+
|
|
113
|
+
// Used to determine if an endpoint status really is halted on a failed transfer.
|
|
114
|
+
#define STATUS_HALT_FLAG 0x1
|
|
115
|
+
|
|
116
|
+
struct wince_device_priv {
|
|
117
|
+
UKW_DEVICE dev;
|
|
118
|
+
UKW_DEVICE_DESCRIPTOR desc;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
struct wince_device_handle_priv {
|
|
122
|
+
// This member isn't used, but only exists to avoid an empty structure
|
|
123
|
+
// for private data for the device handle.
|
|
124
|
+
int reserved;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
struct wince_transfer_priv {
|
|
128
|
+
struct winfd pollable_fd;
|
|
129
|
+
uint8_t interface_number;
|
|
130
|
+
};
|
|
131
|
+
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Windows backend common header for libusb 1.0
|
|
3
|
+
*
|
|
4
|
+
* This file brings together header code common between
|
|
5
|
+
* the desktop Windows and Windows CE backends.
|
|
6
|
+
* Copyright © 2012-2013 RealVNC Ltd.
|
|
7
|
+
* Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
|
|
8
|
+
* With contributions from Michael Plante, Orin Eman et al.
|
|
9
|
+
* Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
|
|
10
|
+
* Major code testing contribution by Xiaofan Chen
|
|
11
|
+
*
|
|
12
|
+
* This library is free software; you can redistribute it and/or
|
|
13
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
14
|
+
* License as published by the Free Software Foundation; either
|
|
15
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* This library is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20
|
+
* Lesser General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
23
|
+
* License along with this library; if not, write to the Free Software
|
|
24
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#pragma once
|
|
28
|
+
|
|
29
|
+
// Windows API default is uppercase - ugh!
|
|
30
|
+
#if !defined(bool)
|
|
31
|
+
#define bool BOOL
|
|
32
|
+
#endif
|
|
33
|
+
#if !defined(true)
|
|
34
|
+
#define true TRUE
|
|
35
|
+
#endif
|
|
36
|
+
#if !defined(false)
|
|
37
|
+
#define false FALSE
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#define safe_free(p) do {if (p != NULL) {free(p); p = NULL;}} while(0)
|
|
41
|
+
#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
|
|
42
|
+
#define safe_min(a, b) min((size_t)(a), (size_t)(b))
|
|
43
|
+
#define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \
|
|
44
|
+
((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0)
|
|
45
|
+
#define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1)
|
|
46
|
+
#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1))
|
|
47
|
+
#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1)
|
|
48
|
+
#define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
|
|
49
|
+
#define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
|
|
50
|
+
#define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count)
|
|
51
|
+
#define safe_strlen(str) ((str==NULL)?0:strlen(str))
|
|
52
|
+
#define safe_sprintf(dst, count, ...) do {_snprintf(dst, count, __VA_ARGS__); (dst)[(count)-1] = 0; } while(0)
|
|
53
|
+
#define safe_stprintf _sntprintf
|
|
54
|
+
#define safe_tcslen(str) ((str==NULL)?0:_tcslen(str))
|
|
55
|
+
#define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0)
|
|
56
|
+
#define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL)
|
|
57
|
+
#ifndef ARRAYSIZE
|
|
58
|
+
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#define ERR_BUFFER_SIZE 256
|
|
62
|
+
#define TIMER_REQUEST_RETRY_MS 100
|
|
63
|
+
#define MAX_TIMER_SEMAPHORES 128
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* API macros - from libusb-win32 1.x
|
|
68
|
+
*/
|
|
69
|
+
#define DLL_DECLARE_PREFIXNAME(api, ret, prefixname, name, args) \
|
|
70
|
+
typedef ret (api * __dll_##name##_t)args; \
|
|
71
|
+
static __dll_##name##_t prefixname = NULL
|
|
72
|
+
|
|
73
|
+
#ifndef _WIN32_WCE
|
|
74
|
+
#define DLL_STRINGIFY(dll) #dll
|
|
75
|
+
#define DLL_GET_MODULE_HANDLE(dll) GetModuleHandleA(DLL_STRINGIFY(dll))
|
|
76
|
+
#define DLL_LOAD_LIBRARY(dll) LoadLibraryA(DLL_STRINGIFY(dll))
|
|
77
|
+
#else
|
|
78
|
+
#define DLL_STRINGIFY(dll) L#dll
|
|
79
|
+
#define DLL_GET_MODULE_HANDLE(dll) GetModuleHandle(DLL_STRINGIFY(dll))
|
|
80
|
+
#define DLL_LOAD_LIBRARY(dll) LoadLibrary(DLL_STRINGIFY(dll))
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
#define DLL_LOAD_PREFIXNAME(dll, prefixname, name, ret_on_failure) \
|
|
84
|
+
do { \
|
|
85
|
+
HMODULE h = DLL_GET_MODULE_HANDLE(dll); \
|
|
86
|
+
if (!h) \
|
|
87
|
+
h = DLL_LOAD_LIBRARY(dll); \
|
|
88
|
+
if (!h) { \
|
|
89
|
+
if (ret_on_failure) { return LIBUSB_ERROR_NOT_FOUND; } \
|
|
90
|
+
else { break; } \
|
|
91
|
+
} \
|
|
92
|
+
prefixname = (__dll_##name##_t)GetProcAddress(h, \
|
|
93
|
+
DLL_STRINGIFY(name)); \
|
|
94
|
+
if (prefixname) break; \
|
|
95
|
+
prefixname = (__dll_##name##_t)GetProcAddress(h, \
|
|
96
|
+
DLL_STRINGIFY(name) DLL_STRINGIFY(A)); \
|
|
97
|
+
if (prefixname) break; \
|
|
98
|
+
prefixname = (__dll_##name##_t)GetProcAddress(h, \
|
|
99
|
+
DLL_STRINGIFY(name) DLL_STRINGIFY(W)); \
|
|
100
|
+
if (prefixname) break; \
|
|
101
|
+
if(ret_on_failure) \
|
|
102
|
+
return LIBUSB_ERROR_NOT_FOUND; \
|
|
103
|
+
} while(0)
|
|
104
|
+
|
|
105
|
+
#define DLL_DECLARE(api, ret, name, args) DLL_DECLARE_PREFIXNAME(api, ret, name, name, args)
|
|
106
|
+
#define DLL_LOAD(dll, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, name, name, ret_on_failure)
|
|
107
|
+
#define DLL_DECLARE_PREFIXED(api, ret, prefix, name, args) DLL_DECLARE_PREFIXNAME(api, ret, prefix##name, name, args)
|
|
108
|
+
#define DLL_LOAD_PREFIXED(dll, prefix, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, prefix##name, name, ret_on_failure)
|