~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to lib/gettime.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gettime -- get the system clock
 
2
 
 
3
   Copyright (C) 2002, 2004-2007, 2009-2010 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
 
 
28
void
 
29
gettime (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
}