Blame src/gl/gettime.c

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