Blame src/gl/gettime.c

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