aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index cd7ff93..031f5ae 100644
--- a/src/util.c
+++ b/src/util.c
@@ -16,11 +16,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE
+
#include <ctype.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <util.h>
+int
+msleep(long msec)
+{
+ struct timespec ts;
+ int res;
+
+ if (msec < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ ts.tv_sec = msec / 1000;
+ ts.tv_nsec = (msec % 1000) * 1000000;
+
+ do {
+ res = nanosleep(&ts, &ts);
+ } while (res && errno == EINTR);
+
+ return res;
+}
+
char *
ltrim(char *s)
{