Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/gethrxtime.c @ 7897:b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
module sys_time.
* lib/gethrxtime.c: Include <sys/time.h>, since we can no longer
assume timespec.h defines struct timeval.
* lib/settime.c: Likewise.
* lib/utimens.c: Likewise.
* lib/gettime.c (gettime): Remove test against HAVE_GETTIMEOFDAY,
since we now assume the gettimeofday module.
* lib/tempname.c (__gen_tempname): Likewise.
* lib/gettimeofday.h: Remove.
* lib/gettimeofday.c: Include <sys/time.h> instead of "gettimeofday.h".
Don't include <sys/types.h> and <stdlib.h>; shouldn't be needed.
Include <time.h>, for 'time()'.
(localtime_buffer_addr): Also use this workaround if
TZSET_CLOBBERS_LOCALTIME. Set to a dummy static variable by default,
to simplify the uses. All uses changed.
(localtime, gmtime, tzset, gettimeofday): Reformat slightly so
that #undef is inside {}, and 'const' follows type name consistently.
(tzset): Define replacement only if TZSET_CLOBBERS_LOCALTIME.
(gettimeofday): Do not use the maximum possible value for
tv->tv_usec, since that might break usages other than ls.c.
Instead, we'll leave ls.c alone. This undoes today's patch
by Bruno. Add a compile-time warning for 1s-clock resolution;
we've never observed the problem but might as well keep the
canary.
* lib/nanosleep.c: Include timespec.h first, for interface check.
* lib/nanosleep.c: Include <sys/time.h> unconditionally, since we
now assume the sys_time module.
* lib/tempname.c: Likewise.
* lib/timespec.h: Likewise.
* lib/nanosleep.c: Don't worry about TIME_WITH_SYS_TIME; no longer
needed.
* lib/strftime.c: Likewise.
* lib/timespec.h: Likewise.
* lib/posixtm.c: Include posixtm.h first, for interface check.
Don't worry about TM_IN_SYS_TIME; that's wayyy obsolete.
* lib/posixtm.h: Include stdbool.h and time.h, for proper interface.
* lib/strftime.c: Don't include <sys/types.h>; shouldn't be needed.
* lib/sys_time_.h: New file.
* lib/timespec.h (struct timespec): Use long int, not long.
* m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY):
(gl_FUNC_GETTIMEOFDAY_CLOBBER, gl_PREREQ_GETTIMEOFDAY):
Remove obsolescent call to AC_HEADER_TIME.
* m4/mktime.m4 (AC_FUNC_MKTIME): Likewise.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Likewise.
* m4/strftime.m4 (gl_FUNC_STRFTIME): Likewise.
* m4/timespec.m4 (gl_TIMESPEC, gl_CHECK_TYPE_STRUCT_TIMESPEC):
Likewise.
* m4/tzset.m4 (gl_FUNC_TZSET_CLOBBER): Likewise.
* m4/utimbuf.m4 (gl_CHECK_TYPE_STRUCT_UTIMBUF): Likewise.
* m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY): Move sys/time.h tests
into the sys_time module. Check for gettimeofday just once.
Prefix our variables with gl_, not with ac_ or jm_. Tighten test
for gettimeofday signature to just check the signature. Merely
compile it, since linking doesn't test signature. Improve test for
whether gettimeofday.o is actually needed.
(gl_FUNC_GETTIMEOFDAY_CLOBBER): Renamed from
AC_FUNC_GETTIMEOFDAY_CLOBBER. All uses changed. Use
AC_RUN_IFELSE rather than AC_TRY_RUN. If clobbering, set
and define GETTIMEOFDAY_CLOBBERS_LOCALTIME.
(gl_GETTIMEOFDAY_REPLACE_LOCALTIME): Don't define
GETTIMEOFDAY_CLOBBERS_LOCALTIME; that's gl_FUNC_GETTIMEOFDAY_CLOBBER's
job. Don't define tzset; that's gl_FUNC_TZSET_CLOBBER's job.
* m4/mktime.m4 (AC_FUNC_MKTIME): Just include <time.h> rather
than worrying about sys/time.h.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP):
Don't bother worrying about TIME_WITH_SYS_TIME.
* m4/stat-time.m4 (gl_STAT_TIME): Likewise.
* m4/posixtm.m4 (gl_POSIXTM): Remove obsolescent call to AC_STRUCT_TM.
* m4/sys_time_h.m4: New file.
* m4/tzset.m4 (gl_FUNC_TZSET_CLOBBER): Require gl_HEADER_SYS_TIME_H.
Don't include sys/time.h. Return from main rather than exiting.
Define TZSET_CLOBBERS_LOCALTIME, for consistency with other names;
all uses changed.
* modules/gethrxtime (Depends-on): Add sys_time.
* modules/gettime (Depends-on): Likewise.
* modules/gettimeofday (Depends-on): Likewise.
* modules/nanosleep (Depends-on): Likewise.
* modules/settime (Depends-on): Likewise.
* modules/tempname (Depends-on): Likewise.
* modules/utimens (Depends-on): Likewise.
* modules/gettimeofday (Files): Remove lib/gettimeofday.h.
(Include:) Change back to <sys/time.h>.
(Maintainer:) Add self.
* modules/sys_time: New file.
* modules/tempname (Depends-on): Add gettimeofday.
* tests/test-gettimeofday.c: Include <sys/time.h>
rather than gettimeofday.h.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 18 Jan 2007 08:33:34 +0000 |
parents | 8a1a9361108c |
children | bbbbbf4cd1c5 |
rev | line source |
---|---|
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
1 /* gethrxtime -- get high resolution real time |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
2 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
3 Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
4 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 2, or (at your option) |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
8 any later version. |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
9 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
14 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
16 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5662
diff
changeset
|
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
18 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
19 /* Written by Paul Eggert. */ |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
20 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6449
diff
changeset
|
21 #include <config.h> |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
22 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
23 #include "gethrxtime.h" |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
24 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
25 #include <sys/time.h> |
6449
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
26 #include "timespec.h" |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
27 |
6449
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
28 /* Get the current time, as a count of the number of nanoseconds since |
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
29 an arbitrary epoch (e.g., the system boot time). Prefer a |
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
30 high-resolution clock that is not subject to resetting or |
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
31 drifting. */ |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
32 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
33 xtime_t |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
34 gethrxtime (void) |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
35 { |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
36 #if HAVE_NANOUPTIME |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
37 { |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
38 struct timespec ts; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
39 nanouptime (&ts); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
40 return xtime_make (ts.tv_sec, ts.tv_nsec); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
41 } |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
42 #else |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
43 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
44 # if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
45 { |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
46 struct timespec ts; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
47 if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
48 return xtime_make (ts.tv_sec, ts.tv_nsec); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
49 } |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
50 # endif |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
51 |
5851 | 52 # if HAVE_MICROUPTIME |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
53 { |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
54 struct timeval tv; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
55 microuptime (&tv); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
56 return xtime_make (tv.tv_sec, 1000 * tv.tv_usec); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
57 } |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
58 |
6449
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
59 # else |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
60 /* No monotonically increasing clocks are available; fall back on a |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
61 clock that might jump backwards, since it's the best we can do. */ |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
62 { |
6449
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
63 struct timespec ts; |
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
64 gettime (&ts); |
232d8dc8525f
* modules/gethrxtime (Depends-on): Add gettime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
65 return xtime_make (ts.tv_sec, ts.tv_nsec); |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
66 } |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
67 # endif |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
68 #endif |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
69 } |