LWKT message ports contain a number of function pointers which abstract
[dragonfly/vkernel-mp.git] / contrib / cvs-1.12 / lib / gettime.c
blob0f94297da880cf3ac736bf539e0ab28a5b972cc8
1 /* gettime -- get the system clock
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Paul Eggert. */
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include "timespec.h"
26 /* Get the system time into *TS. */
28 void
29 gettime (struct timespec *ts)
31 #if HAVE_NANOTIME
32 nanotime (ts);
33 #else
35 # if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
36 if (clock_gettime (CLOCK_REALTIME, ts) == 0)
37 return;
38 # endif
40 # if HAVE_GETTIMEOFDAY
42 struct timeval tv;
43 gettimeofday (&tv, NULL);
44 ts->tv_sec = tv.tv_sec;
45 ts->tv_nsec = tv.tv_usec * 1000;
47 # else
48 ts->tv_sec = time (NULL);
49 ts->tv_nsec = 0;
50 # endif
52 #endif