From f8e9fb72f12990ce5c89de94eeb4effa2757d38b Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 12 Sep 2018 03:27:05 +0300 Subject: serial_ftdi: use Sleep() on Win32 Windows doesn't have nanosleep() unless libwinpthread is used. Since the nanosleep() usage in serial_ftdi_sleep(): - does not break in case of EINTR - has input in milliseconds the WINAPI Sleep() should be a good alternative. Signed-off-by: Lubomir I. Ivanov --- core/serial_ftdi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c index 86d27c9ff..b3f2f2f37 100644 --- a/core/serial_ftdi.c +++ b/core/serial_ftdi.c @@ -26,12 +26,17 @@ #include // strerror #include // errno #include // gettimeofday -#include // nanosleep #include #include #include +#ifdef _WIN32 +#include // Sleep +#else +#include // nanosleep +#endif + #ifndef __ANDROID__ #define INFO(context, fmt, ...) fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__) #define ERROR(context, fmt, ...) fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__) @@ -107,6 +112,9 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout) INFO (device->context, "Sleep: value=%u", timeout); +#ifdef _WIN32 + Sleep((DWORD)timeout); +#else struct timespec ts; ts.tv_sec = (timeout / 1000); ts.tv_nsec = (timeout % 1000) * 1000000; @@ -117,6 +125,7 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout) return DC_STATUS_IO; } } +#endif return DC_STATUS_SUCCESS; } -- cgit v1.2.3-70-g09d2