Fix typo
[khatus.git] / x5 / khatus_lib_time.c
CommitLineData
17a27e48
SK
1#include <errno.h>
2#include <math.h>
3#include <stdio.h>
c7262f37 4#include <stdlib.h>
17a27e48
SK
5#include <string.h>
6#include <time.h>
7
8#include "khatus_lib_log.h"
9#include "khatus_lib_time.h"
10
8345f2b3
SK
11struct timespec
12timespec_of_float(double n)
13{
14 double integral;
15 double fractional;
16 struct timespec t;
17
18 fractional = modf(n, &integral);
19 t.tv_sec = (int) integral;
20 t.tv_nsec = (int) (1E9 * fractional);
21
22 return t;
23}
24
17a27e48
SK
25void
26snooze(struct timespec *t)
27{
28 struct timespec remainder;
29 int result;
30
31 result = nanosleep(t, &remainder);
32
33 if (result < 0) {
34 if (errno == EINTR) {
35 warn(
36 "nanosleep interrupted. Remainder: "
37 "{ tv_sec = %ld, tv_nsec = %ld }",
38 remainder.tv_sec, remainder.tv_nsec);
39 /* No big deal if we occasionally sleep less,
40 * so not attempting to correct after an interruption.
41 */
42 } else {
43 fatal("nanosleep: %s\n", strerror(errno));
44 }
45 }
46}
This page took 0.022759 seconds and 4 git commands to generate.