summaryrefslogtreecommitdiff
path: root/lib/gethrxtime.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-11-10 20:20:20 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-11-10 20:20:20 +0000
commit163141255f74334d90f7612d77ec637efd5ae7f7 (patch)
tree0014f6b0ef86e6fddb3d366d05967047024aea52 /lib/gethrxtime.c
parent14f7ef9d17d36fbee034543c9fc57240fb2a6d14 (diff)
downloadcoreutils-163141255f74334d90f7612d77ec637efd5ae7f7.tar.xz
Include "timespec.h" rather than the sys/time / time
business. (gethrxtime) [! (HAVE_NANOUPTIME || (defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME) || HAVE_MICROUPTIME)]: Fall back on gettime rather than rolling our own approximation.
Diffstat (limited to 'lib/gethrxtime.c')
-rw-r--r--lib/gethrxtime.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/gethrxtime.c b/lib/gethrxtime.c
index 2c985789d..6ece8ae18 100644
--- a/lib/gethrxtime.c
+++ b/lib/gethrxtime.c
@@ -24,20 +24,12 @@
#include "gethrxtime.h"
-#include <sys/types.h>
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
+#include "timespec.h"
-/* Get the time of a high-resolution clock, preferably one that is not
- subject to resetting or drifting. */
+/* Get the current time, as a count of the number of nanoseconds since
+ an arbitrary epoch (e.g., the system boot time). Prefer a
+ high-resolution clock that is not subject to resetting or
+ drifting. */
xtime_t
gethrxtime (void)
@@ -65,16 +57,14 @@ gethrxtime (void)
return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
}
+# else
/* No monotonically increasing clocks are available; fall back on a
clock that might jump backwards, since it's the best we can do. */
-# elif HAVE_GETTIMEOFDAY && XTIME_PRECISION != 1
{
- struct timeval tv;
- gettimeofday (&tv, NULL);
- return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
+ struct timespec ts;
+ gettime (&ts);
+ return xtime_make (ts.tv_sec, ts.tv_nsec);
}
-# else
- return xtime_make (time (NULL), 0);
# endif
#endif
}