From 6bfcd135065332735c0620cc08b9c65a9f4a1884 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 23 Feb 2014 23:24:48 -0500 Subject: [PATCH] Windows: add usleep() to roken Add a version of usleep() which is capable of sleeping in one millisecond increments instead of microseconds. Change-Id: I173f7e6f91a947cdb66f7cc6df5520e1c03f10b7 --- lib/roken/roken.h.in | 3 +++ lib/roken/sleep.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 2cf596c4f..6e76b3f63 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -969,6 +969,9 @@ gai_strerror(int); ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL sleep(unsigned int seconds); +ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL +usleep(unsigned int useconds); + #endif ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL diff --git a/lib/roken/sleep.c b/lib/roken/sleep.c index 4773f7c02..a2599b90e 100644 --- a/lib/roken/sleep.c +++ b/lib/roken/sleep.c @@ -1,5 +1,5 @@ /*********************************************************************** - * Copyright (c) 2009, Secure Endpoints Inc. + * Copyright (c) 2009, 2014, Secure Endpoints Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,16 @@ ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL sleep(unsigned int seconds) { - SleepEx(1000 * (DWORD) seconds, FALSE); + if (SleepEx(1000 * (DWORD) seconds, FALSE) != 0) + return -1; + return 0; +} + +/* We can only sleep in millisecond increments */ +ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL +usleep(unsigned int useconds) +{ + if (SleepEx((DWORD)(useconds / 1000), FALSE) != 0) + return -1; return 0; }