diff options
author | Robert Swiecki <robert@swiecki.net> | 2019-04-01 15:35:28 +0200 |
---|---|---|
committer | Robert Swiecki <robert@swiecki.net> | 2019-04-01 15:35:28 +0200 |
commit | e3d734f3442031fd8fe187226ffc4cb06873a1e2 (patch) | |
tree | 7ee600dc3f53d207fb30323e28c2da7c413966d3 /libhfcommon | |
parent | 89a4c2f344c8857a1b90eb591721b45d76923c1e (diff) | |
download | honggfuzz-e3d734f3442031fd8fe187226ffc4cb06873a1e2.tar.gz |
hfcommin/util: implement sleep resistant to interrupts
Diffstat (limited to 'libhfcommon')
-rw-r--r-- | libhfcommon/util.c | 13 | ||||
-rw-r--r-- | libhfcommon/util.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/libhfcommon/util.c b/libhfcommon/util.c index ac54167e..c8616676 100644 --- a/libhfcommon/util.c +++ b/libhfcommon/util.c @@ -24,6 +24,8 @@ #include "libhfcommon/util.h" #include <ctype.h> +#include <errno.h> +#include <error.h> #include <fcntl.h> #include <inttypes.h> #include <math.h> @@ -242,6 +244,17 @@ int64_t util_timeNowMillis(void) { return (((int64_t)tv.tv_sec * 1000LL) + ((int64_t)tv.tv_usec / 1000LL)); } +void util_sleepForMSec(uint64_t msec) { + if (msec == 0) { + return; + } + struct timespec ts = { + .tv_sec = msec / 1000U, + .tv_nsec = msec % 1000U, + }; + TEMP_FAILURE_RETRY(nanosleep(&ts, &ts)); +} + uint64_t util_getUINT32(const uint8_t* buf) { uint32_t r; memcpy(&r, buf, sizeof(r)); diff --git a/libhfcommon/util.h b/libhfcommon/util.h index c92d4707..d71b3a70 100644 --- a/libhfcommon/util.h +++ b/libhfcommon/util.h @@ -109,6 +109,7 @@ extern void util_closeStdio(bool close_stdin, bool close_stdout, bool close_stde extern uint64_t util_hash(const char* buf, size_t len); extern int64_t util_timeNowMillis(void); +extern void util_sleepForMSec(uint64_t msec); extern uint64_t util_getUINT32(const uint8_t* buf); extern uint64_t util_getUINT64(const uint8_t* buf); |