Mercurial > hg > octave-kai > gnulib-hg
annotate lib/gettime.c @ 9309:bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 07 Oct 2007 19:14:58 +0200 |
parents | b7a83a69ac23 |
children | b5e42ef33b49 |
rev | line source |
---|---|
3768 | 1 /* gettime -- get the system clock |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6527
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) 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
3768 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7897
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
3768 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7897
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7897
diff
changeset
|
8 (at your option) any later version. |
3768 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7897
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3768 | 17 |
18 /* Written by Paul Eggert. */ | |
19 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6527
diff
changeset
|
20 #include <config.h> |
3768 | 21 |
22 #include "timespec.h" | |
23 | |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
24 #include <sys/time.h> |
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
25 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
26 /* Get the system time into *TS. */ |
3768 | 27 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
28 void |
3768 | 29 gettime (struct timespec *ts) |
30 { | |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
31 #if HAVE_NANOTIME |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
32 nanotime (ts); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
33 #else |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
34 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
35 # if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME |
3768 | 36 if (clock_gettime (CLOCK_REALTIME, ts) == 0) |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
37 return; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
38 # endif |
3768 | 39 |
40 { | |
41 struct timeval tv; | |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
42 gettimeofday (&tv, NULL); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
43 ts->tv_sec = tv.tv_sec; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
44 ts->tv_nsec = tv.tv_usec * 1000; |
3768 | 45 } |
5059
eb3efcec6ae2
Don't assume that gettimeofday and settimeofday exist or work.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3774
diff
changeset
|
46 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
47 #endif |
3768 | 48 } |