summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Mikhailov <mvp@users.noreply.github.com>2017-07-28 11:03:58 -0700
committerVadim Mikhailov <mvp@users.noreply.github.com>2017-07-28 11:19:50 -0700
commitd5cf8f882a378d9c6edae09e6e0979e0c5ce6338 (patch)
tree62e74a3988181837c4a187711623f11413075f8f
parent39d30bdad33f6a2fe8b508bb96baab182cc178b7 (diff)
use C99 and enable pedantic checking
Also simplify ifdef spaghetti. Remove _WIN64 use as _WIN32 is defined on both Win32 and Win64.
-rw-r--r--Makefile2
-rw-r--r--uhubctl.c31
2 files changed, 13 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 311d62c..ce19e70 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ RM := rm -rf
CC ?= gcc
CFLAGS ?= -g -O0
-CFLAGS += -Wall -Wextra
+CFLAGS += -Wall -Wextra -std=c99 -pedantic
ifeq ($(UNAME_S),Linux)
LDFLAGS += -Wl,-z,relro -lusb-1.0
diff --git a/uhubctl.c b/uhubctl.c
index 593613d..05bd6a0 100644
--- a/uhubctl.c
+++ b/uhubctl.c
@@ -17,39 +17,32 @@
#include <getopt.h>
#include <errno.h>
#include <ctype.h>
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_WIN32)
#include <io.h>
#include <process.h>
-#else
-#include <unistd.h>
#endif
-
-#ifdef __FreeBSD__
-#include <libusb.h>
-#elif defined(_WIN32) || defined(_WIN64)
+#if defined(__FreeBSD__) || defined(_WIN32)
#include <libusb.h>
#else
#include <libusb-1.0/libusb.h>
#endif
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_WIN32)
+#include <windows.h>
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
-
-#endif
-
-#if defined(_WIN32) || defined(_WIN64)
-#include <windows.h>
#elif _POSIX_C_SOURCE >= 199309L
-#include <time.h> // for nanosleep
+#include <time.h> /* for nanosleep */
#else
-#include <unistd.h> // for usleep
+#include <unistd.h> /* for usleep */
#endif
-void sleep_ms(int milliseconds) // cross-platform sleep function
+/* cross-platform sleep function */
+
+void sleep_ms(int milliseconds)
{
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_WIN32)
Sleep(milliseconds);
#elif _POSIX_C_SOURCE >= 199309L
struct timespec ts;
@@ -99,12 +92,10 @@ struct usb_hub_descriptor {
* See USB 2.0 spec Table 11-19 and Table 11-20
*/
#pragma pack(push,1)
-
struct usb_port_status {
int16_t wPortStatus;
int16_t wPortChange;
};
-
#pragma pack(push,1)
/*
@@ -214,6 +205,7 @@ int print_usage()
);
return 0;
}
+
/* checks if hub is smart hub
* use min_current above 0 to only consider external hubs
* (external hubs have non-zero bHubContrCurrent)
@@ -303,6 +295,7 @@ static int get_port_status(struct libusb_device_handle *devh, int port)
* portmask is bitmap of ports to display
* if portmask is 0, show all ports
*/
+
static int hub_port_status(struct libusb_device * dev, int nports, int portmask)
{
int port_status;