Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 69 lines (55 sloc) 1.844 kb
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
1 /* gethrxtime -- get high resolution real time
2
d60f3b0 maint: update almost all copyright ranges to include 2011
Jim Meyering authored
3 Copyright (C) 2005-2007, 2009-2011 Free Software Foundation, Inc.
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
4
57fdfd3 @bhaible Change copyright notice from GPLv2+ to GPLv3+.
bhaible authored
5 This program is free software: you can redistribute it and/or modify
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
6 it under the terms of the GNU General Public License as published by
57fdfd3 @bhaible Change copyright notice from GPLv2+ to GPLv3+.
bhaible authored
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
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
57fdfd3 @bhaible Change copyright notice from GPLv2+ to GPLv3+.
bhaible authored
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
17
18 /* Written by Paul Eggert. */
19
0632e11 @eggert * _fpending.c: Include <config.h> unconditionally, since we no
eggert authored
20 #include <config.h>
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
21
22 #include "gethrxtime.h"
23
5661ab9 @eggert * MODULES.html.sh (Support for systems lacking POSIX:2001): New
eggert authored
24 #include <sys/time.h>
6512f0a @eggert * modules/gethrxtime (Depends-on): Add gettime.
eggert authored
25 #include "timespec.h"
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
26
6512f0a @eggert * modules/gethrxtime (Depends-on): Add gettime.
eggert authored
27 /* Get the current time, as a count of the number of nanoseconds since
28 an arbitrary epoch (e.g., the system boot time). Prefer a
29 high-resolution clock that is not subject to resetting or
30 drifting. */
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
31
32 xtime_t
33 gethrxtime (void)
34 {
35 #if HAVE_NANOUPTIME
36 {
37 struct timespec ts;
38 nanouptime (&ts);
39 return xtime_make (ts.tv_sec, ts.tv_nsec);
40 }
41 #else
42
43 # if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
44 {
45 struct timespec ts;
46 if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
47 return xtime_make (ts.tv_sec, ts.tv_nsec);
48 }
49 # endif
50
6ef9a07 @eggert Sync from coreutils.
eggert authored
51 # if HAVE_MICROUPTIME
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
52 {
53 struct timeval tv;
54 microuptime (&tv);
55 return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
56 }
57
6512f0a @eggert * modules/gethrxtime (Depends-on): Add gettime.
eggert authored
58 # else
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
59 /* No monotonically increasing clocks are available; fall back on a
60 clock that might jump backwards, since it's the best we can do. */
61 {
6512f0a @eggert * modules/gethrxtime (Depends-on): Add gettime.
eggert authored
62 struct timespec ts;
63 gettime (&ts);
64 return xtime_make (ts.tv_sec, ts.tv_nsec);
10ce26c @eggert * modules/gethrxtime: New file.
eggert authored
65 }
66 # endif
67 #endif
68 }
Something went wrong with that request. Please try again.