Blame lib/gettime.c

Packit Service a2489d
/* gettime -- get the system clock
Packit Service a2489d
Packit Service a2489d
   Copyright (C) 2002, 2004-2007, 2009-2018 Free Software Foundation, Inc.
Packit Service a2489d
Packit Service a2489d
   This program is free software: you can redistribute it and/or modify
Packit Service a2489d
   it under the terms of the GNU General Public License as published by
Packit Service a2489d
   the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
   (at your option) any later version.
Packit Service a2489d
Packit Service a2489d
   This program is distributed in the hope that it will be useful,
Packit Service a2489d
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
   GNU General Public License for more details.
Packit Service a2489d
Packit Service a2489d
   You should have received a copy of the GNU General Public License
Packit Service a2489d
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service a2489d
Packit Service a2489d
/* Written by Paul Eggert.  */
Packit Service a2489d
Packit Service a2489d
#include <config.h>
Packit Service a2489d
Packit Service a2489d
#include "timespec.h"
Packit Service a2489d
Packit Service a2489d
#include <sys/time.h>
Packit Service a2489d
Packit Service a2489d
/* Get the system time into *TS.  */
Packit Service a2489d
Packit Service a2489d
void
Packit Service a2489d
gettime (struct timespec *ts)
Packit Service a2489d
{
Packit Service a2489d
#if HAVE_NANOTIME
Packit Service a2489d
  nanotime (ts);
Packit Service a2489d
#else
Packit Service a2489d
Packit Service a2489d
# if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
Packit Service a2489d
  if (clock_gettime (CLOCK_REALTIME, ts) == 0)
Packit Service a2489d
    return;
Packit Service a2489d
# endif
Packit Service a2489d
Packit Service a2489d
  {
Packit Service a2489d
    struct timeval tv;
Packit Service a2489d
    gettimeofday (&tv, NULL);
Packit Service a2489d
    ts->tv_sec = tv.tv_sec;
Packit Service a2489d
    ts->tv_nsec = tv.tv_usec * 1000;
Packit Service a2489d
  }
Packit Service a2489d
Packit Service a2489d
#endif
Packit Service a2489d
}