From f950233dbcd8d5d2e696a76f4c13facd5f5a2e05 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 24 Aug 2022 19:30:20 -0400 Subject: [PATCH] Add UtilSleepMillis() function. --- src/Util.c | 14 ++++++++++++++ src/include/Util.h | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Util.c b/src/Util.c index ca45e93..6220f9d 100644 --- a/src/Util.c +++ b/src/Util.c @@ -105,3 +105,17 @@ UtilStringDuplicate(char *inStr) return outStr; } + +int +UtilSleepMillis(long ms) +{ + struct timespec ts; + int res; + + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + + res = nanosleep(&ts, &ts); + + return res; +} diff --git a/src/include/Util.h b/src/include/Util.h index d00eda5..8023e6b 100644 --- a/src/include/Util.h +++ b/src/include/Util.h @@ -84,4 +84,16 @@ extern char * extern char * UtilStringDuplicate(char *); +/* + * Sleep for the given number of milliseconds. This is a simple wrapper + * for nanosleep() that makes its usage much easier. + * + * Params: + * (long) The number of milliseconds to sleep for. + * + * Return: The result of nanosleep(). + */ +extern int + UtilSleepMillis(long); + #endif /* TELODENDRIA_UTIL_H */