break;
case 'b':
if (j+1 < argc) {
- strncpy(binary_name, argv[j+1], 64);
+ // WDK's OACR doesn't like strncpy...
+ for (i=0; (i<(sizeof(binary_name)-1)) && (argv[j+1][i] != 0); i++)
+ binary_name[i] = argv[j+1][i];
+ binary_name[i] = 0;
j++;
}
binary_dump = true;
*/
int API_EXPORTED libusb_init(libusb_context **context)
{
- char *dbg = getenv("LIBUSB_DEBUG");
+ char *dbg;
struct libusb_context *ctx;
int r = 0;
ctx->debug = LOG_LEVEL_DEBUG;
#endif
+ dbg = getenv("LIBUSB_DEBUG");
if (dbg) {
ctx->debug = atoi(dbg);
if (ctx->debug)
#define _W32_FT_OFFSET (116444736000000000)
int usbi_gettimeofday(struct timeval *tp, void *tzp)
- {
- union {
- unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */
- FILETIME ft;
- } _now;
-
- if(tp)
- {
- GetSystemTimeAsFileTime (&_now.ft);
- tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 );
- tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000);
- }
- /* Always return 0 as per Open Group Base Specifications Issue 6.
- Do not set errno on error. */
- return 0;
+{
+ union {
+ unsigned __int64 ns100; /* Time since 1 Jan 1601, in 100ns units */
+ FILETIME ft;
+ } _now;
+ UNUSED(tzp);
+
+ if(tp) {
+ GetSystemTimeAsFileTime (&_now.ft);
+ tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 );
+ tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000);
+ }
+ /* Always return 0 as per Open Group Base Specifications Issue 6.
+ Do not set errno on error. */
+ return 0;
}
#endif
#define USB_MAXINTERFACES 32
#define USB_MAXCONFIG 8
+/* The following is used to silence warnings for unused variables */
+#define UNUSED(var) (void)sizeof(var)
+
struct list_head {
struct list_head *prev, *next;
};
}
is_polling_set = TRUE;
}
- compat_spinlock = 0;
+ InterlockedExchange((LONG *)&compat_spinlock, 0);
}
// Internal function to retrieve the table index (and lock the fd mutex)
DeleteCriticalSection(&_poll_fd[i].mutex);
}
}
- compat_spinlock = 0;
+ InterlockedExchange((LONG *)&compat_spinlock, 0);
}
/*
ssize_t usbi_write(int fd, const void *buf, size_t count)
{
int _index;
+ UNUSED(buf);
CHECK_INIT_POLLING;
{
int _index;
ssize_t r = -1;
+ UNUSED(buf);
CHECK_INIT_POLLING;
int usbi_mutex_init(usbi_mutex_t *mutex,
const usbi_mutexattr_t *attr) {
+ UNUSED(attr);
if(! mutex) return ((errno=EINVAL));
*mutex = CreateMutex(NULL, FALSE, NULL);
if(!*mutex) return ((errno=ENOMEM));
int usbi_cond_init(usbi_cond_t *cond,
const usbi_condattr_t *attr) {
+ UNUSED(attr);
if(!cond) return ((errno=EINVAL));
list_init(&cond->waiters );
list_init(&cond->not_waiting);
#include "poll_windows.h"
#include "windows_usb.h"
-// The following prevents "banned API" errors when using the MS's WDK OACR/Prefast
-#if defined(_PREFAST_)
-#pragma warning(disable:28719)
-#endif
-
// The 2 macros below are used in conjunction with safe loops.
#define LOOP_CHECK(fcall) { r=fcall; if (r != LIBUSB_SUCCESS) continue; }
#define LOOP_BREAK(err) { r=err; continue; }
char* sz = str;
// Compute main hash value (algorithm suggested by Nokia)
- while ((c = *sz++))
+ while ((c = *sz++) != 0)
r = ((r << 5) + r) + c;
if (r == 0)
++r;
priv->usb_interface[interface_number].apib = &usb_api_backend[api];
if ((api == USB_API_HID) && (priv->hid == NULL)) {
priv->hid = calloc(1, sizeof(struct hid_device_priv));
+ if (priv->hid == NULL)
+ return LIBUSB_ERROR_NO_MEM;
}
priv->composite_api_flags |= 1<<api;
struct discovered_devs *discdevs;
HDEVINFO dev_info = { 0 };
char* usb_class[2] = {"USB", "NUSB3"};
- SP_DEVINFO_DATA dev_info_data;
+ SP_DEVINFO_DATA dev_info_data = { 0 };
SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL;
GUID hid_guid;
#define MAX_ENUM_GUIDS 64
char* dev_id_path = NULL;
unsigned long session_id;
DWORD size, reg_type, port_nr, install_state;
- BOOL b = FALSE;
HKEY key;
WCHAR guid_string_w[MAX_GUID_STRING_LENGTH];
GUID* if_guid;
} else {
// Workaround for a Nec/Renesas USB 3.0 driver bug where root hubs are
// being listed under the "NUSB3" PnP Symbolic Name rather than "USB"
- while ( (class_index < 2) &&
- (!(b = get_devinfo_data(ctx, &dev_info, &dev_info_data, usb_class[class_index], i))) ) {
- class_index++;
- i = 0;
+ for (; class_index < 2; class_index++) {
+ if (get_devinfo_data(ctx, &dev_info, &dev_info_data, usb_class[class_index], i))
+ break;
+ i = 0;
}
- if (!b) break;
+ if (class_index >= 2)
+ break;
}
// Read the Device ID path. This is what we'll use as UID
-#define LIBUSB_NANO 10534
+#define LIBUSB_NANO 10535
#error "Please make sure the msvc/ directory is removed from your build path."
#endif
+/* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */
+#pragma warning(disable:4200)
+#if defined(_PREFAST_)
+/* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */
+#pragma warning(disable:28719)
+/* Disable "The function 'InitializeCriticalSection' must be called from within a try/except block" */
+#pragma warning(disable:28125)
+#endif
+
/* Default visibility */
#define DEFAULT_VISIBILITY /**/
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
</ClCompile>
<Link>
<OutputFile>$(OutDir)libusb-1.0.dll</OutputFile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_WIN64;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
</ClCompile>
<Link>
<OutputFile>$(OutDir)libusb-1.0.dll</OutputFile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_WIN64;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)libusb-1.0.lib</OutputFile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_WIN64;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)libusb-1.0.lib</OutputFile>