From ff11c8ac872e8dc2accfe352180daaa54d967f97 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 8 Mar 2013 23:30:21 +0100 Subject: [PATCH] Fix cppcheck warning "Obsolete function 'usleep' called" --- libnfc/drivers/pn532_spi.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libnfc/drivers/pn532_spi.c b/libnfc/drivers/pn532_spi.c index cef5a38..05cb000 100644 --- a/libnfc/drivers/pn532_spi.c +++ b/libnfc/drivers/pn532_spi.c @@ -34,8 +34,6 @@ #include #include #include -#include - #include #include "drivers.h" @@ -51,6 +49,22 @@ #define LOG_CATEGORY "libnfc.driver.pn532_spi" #define LOG_GROUP NFC_LOG_GROUP_DRIVER +#ifndef _WIN32 +// Needed by sleep() under Unix +# include +# include +# define msleep(x) do { \ + struct timespec xsleep; \ + xsleep.tv_sec = x / 1000; \ + xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \ + nanosleep(&xsleep, NULL); \ + } while (0) +#else +// Needed by Sleep() under Windows +# include +# define msleep Sleep +#endif + // Internal data structs const struct pn53x_io pn532_spi_io; struct pn532_spi_data { @@ -336,7 +350,7 @@ pn532_spi_wait_for_data(nfc_device *pnd, int timeout) return NFC_ETIMEOUT; } - usleep(pn532_spi_poll_interval * 1000); + msleep(pn532_spi_poll_interval); } }