summaryrefslogtreecommitdiff
path: root/dlib/dlib.c
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-07-29 20:17:36 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-08-07 16:50:49 +0200
commit59c9094781cbf340f11929d497c1465cf45cf90a (patch)
tree81be2e2c83e1724bed9c5d31a6c573673a5c8bf1 /dlib/dlib.c
parenta00e68d5486a9382988a1ca25c52a305c8a020bf (diff)
Add portable usleep() replacement
Reviewed-by: dogma
Diffstat (limited to 'dlib/dlib.c')
-rw-r--r--dlib/dlib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/dlib/dlib.c b/dlib/dlib.c
index f4c8db2d..2cbd083e 100644
--- a/dlib/dlib.c
+++ b/dlib/dlib.c
@@ -2,6 +2,7 @@
* File: dlib.c
*
* Copyright (C) 2006-2007 Jorge Arellano Cid <jcid@dillo.org>
+ * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +25,7 @@
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
+#include <time.h>
#include "dlib.h"
@@ -955,3 +957,24 @@ int dClose(int fd)
while (st == -1 && errno == EINTR);
return st;
}
+
+/**
+ * Portable usleep() function.
+ *
+ * The usleep() function is deprecated in POSIX.1-2001 and removed in
+ * POSIX.1-2008, see usleep(3).
+ */
+int dUsleep(unsigned long usec)
+{
+ struct timespec ts;
+ int res;
+
+ ts.tv_sec = usec / 1000000UL;
+ ts.tv_nsec = (usec % 1000000UL) * 1000UL;
+
+ do {
+ res = nanosleep(&ts, &ts);
+ } while (res && errno == EINTR);
+
+ return res;
+}