aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gettime.c
diff options
context:
space:
mode:
authorPaul Eggert2012-06-22 14:26:37 -0700
committerPaul Eggert2012-06-22 14:26:37 -0700
commitc8fff8630133fea7c4e279458d10d825e5028c62 (patch)
treef8b8261fdf3596e1306a3d072e13ec572c9e3e65 /lib/gettime.c
parent36cec983d4e680e28e7066fda505910cd549f509 (diff)
downloademacs-c8fff8630133fea7c4e279458d10d825e5028c62.tar.gz
emacs-c8fff8630133fea7c4e279458d10d825e5028c62.zip
Add gnulib files to support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'lib/gettime.c')
-rw-r--r--lib/gettime.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gettime.c b/lib/gettime.c
new file mode 100644
index 00000000000..8075bfaf999
--- /dev/null
+++ b/lib/gettime.c
@@ -0,0 +1,48 @@
1/* gettime -- get the system clock
2
3 Copyright (C) 2002, 2004-2007, 2009-2012 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#include <config.h>
21
22#include "timespec.h"
23
24#include <sys/time.h>
25
26/* Get the system time into *TS. */
27
28void
29gettime (struct timespec *ts)
30{
31#if HAVE_NANOTIME
32 nanotime (ts);
33#else
34
35# if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
36 if (clock_gettime (CLOCK_REALTIME, ts) == 0)
37 return;
38# endif
39
40 {
41 struct timeval tv;
42 gettimeofday (&tv, NULL);
43 ts->tv_sec = tv.tv_sec;
44 ts->tv_nsec = tv.tv_usec * 1000;
45 }
46
47#endif
48}