add CMake config (#20)
[usb-relay-hid.git] / lib / usb_relay_lib.c
index c7aadc2f2d34e13aa72e5cb605a9e23cbfc38331..87584606f907b0d9065313b81d5db14d4872d903 100644 (file)
@@ -24,7 +24,9 @@
 #define USBRL_CALL __cdecl
 #define USBRL_API __declspec(dllexport) USBRL_CALL
 
+#if _MSC_VER < 1900 /* before VS2015 */
 #define snprintf   _snprintf
+#endif /* VS2015 */
 #endif // _MSC_VER
 #endif //WIN32
 
@@ -67,7 +69,7 @@ struct enumctx_s {
 
 // Globals
 
-const char *g_dummyPath = "NOTHING"; // passing dev.path to client not implemented, I return this as path.
+static const char *g_dummyPath = "NOTHING"; // passing dev.path to client not implemented, I return this as path.
 
 static const char *usbErrorMessage(int errCode)
 {
@@ -201,7 +203,7 @@ int enumfunc(USBDEVHANDLE usbh, void *context)
     int err;
     char buffer[128*sizeof(short)]; // max USB string is 128 UTF-16 chars
     int num = 0;
-    int i;
+    size_t i;
     struct usbrelay_internal_s *q;
     struct enumctx_s *ectx = (struct enumctx_s *)context;
 
@@ -213,7 +215,7 @@ int enumfunc(USBDEVHANDLE usbh, void *context)
         goto next;
     }
 
-    i = (int)strlen(buffer);
+    i = strlen(buffer);
     if ( i != strlen(productName) + 1 )
     {
         goto next;
@@ -278,6 +280,7 @@ int enumfunc(USBDEVHANDLE usbh, void *context)
         ectx->tail =q;
     } else {
         ectx->tail->urdi.next = (pusb_relay_device_info_t)q;
+        ectx->tail = q;
     }
 
     ++ectx->numdevs;
@@ -298,7 +301,7 @@ int enumOpenfunc(USBDEVHANDLE usbh, void *context)
     int err;
     char buffer[128*sizeof(short)]; // max USB string is 128 UTF-16 chars
     int num = 0;
-    int i;
+    size_t i;
     struct enumctx_s *ectx = (struct enumctx_s *)context;
     struct usbrelay_internal_s *q = ectx->head;