aboutsummaryrefslogtreecommitdiffstats
path: root/src/libposixplz
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-04-04 09:30:22 +0000
committerLaurent Bercot <ska@appnovation.com>2025-04-04 09:30:22 +0000
commit84b1c5f50749523d940a449d8f684a38a5d157f5 (patch)
treed8bd3c0fd5499b138a5c130373b22f5bedd5973b /src/libposixplz
parentc8c1cab2b6a2754acbe7ee130c356383d0289f09 (diff)
downloadskalibs-84b1c5f50749523d940a449d8f684a38a5d157f5.tar.gz
Add tain_addmsec, millisleep
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libposixplz')
-rw-r--r--src/libposixplz/millisleep.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libposixplz/millisleep.c b/src/libposixplz/millisleep.c
new file mode 100644
index 0000000..e781f58
--- /dev/null
+++ b/src/libposixplz/millisleep.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <time.h>
+
+#include <skalibs/posixplz.h>
+
+unsigned int millisleep (unsigned int msec)
+{
+ struct timespec ts = { .tv_sec = msec / 1000, .tv_nsec = (long)(msec % 1000) * 1000000U } ;
+ struct timespec tr ;
+ return nanosleep(&ts, &tr) == -1 ? 1000 * tr.tv_sec + tr.tv_nsec / 1000000U : 0 ;
+}