Fix cppcheck warning "Obsolete function 'usleep' called"

It is recommended to use the 'nanosleep' or 'setitimer' function instead.
This commit is contained in:
Philippe Teuwen 2013-03-06 21:43:36 +01:00
parent fdd5bd3523
commit 048ed88e16

View file

@ -48,15 +48,16 @@
#include <time.h> #include <time.h>
#ifndef _WIN32 #ifndef _WIN32
// Needed by sleep() under Unix # include <time.h>
# include <unistd.h> # define msleep(x) do { \
# define sleep usleep struct timespec xsleep; \
# define SUSP_TIME 1000 // usecs. xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else #else
// Needed by Sleep() under Windows
# include <winbase.h> # include <winbase.h>
# define sleep Sleep # define msleep Sleep
# define SUSP_TIME 1 // msecs.
#endif #endif
@ -154,15 +155,15 @@ int main(int argc, const char *argv[])
break; break;
} }
if (cmd[0] == 'p') { if (cmd[0] == 'p') {
int s = 0; int ms = 0;
offset++; offset++;
while (isspace(cmd[offset])) { while (isspace(cmd[offset])) {
offset++; offset++;
} }
sscanf(cmd + offset, "%10d", &s); sscanf(cmd + offset, "%10d", &ms);
printf("Pause for %i msecs\n", s); printf("Pause for %i msecs\n", ms);
if (s > 0) { if (ms > 0) {
sleep(s * SUSP_TIME); msleep(ms);
} }
free(cmd); free(cmd);
continue; continue;