-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* gettime -- get the system clock | ||
Copyright (C) 2002, 2004-2007, 2009-2010 Free Software Foundation, Inc. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
|
||
/* Written by Paul Eggert. */ | ||
|
||
#include <config.h> | ||
|
||
#include "timespec.h" | ||
|
||
#include <sys/time.h> | ||
|
||
/* Get the system time into *TS. */ | ||
|
||
void | ||
gettime (struct timespec *ts) | ||
{ | ||
#if HAVE_NANOTIME | ||
nanotime (ts); | ||
#else | ||
|
||
# if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME | ||
if (clock_gettime (CLOCK_REALTIME, ts) == 0) | ||
return; | ||
# endif | ||
|
||
{ | ||
struct timeval tv; | ||
gettimeofday (&tv, NULL); | ||
ts->tv_sec = tv.tv_sec; | ||
ts->tv_nsec = tv.tv_usec * 1000; | ||
} | ||
|
||
#endif | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# clock_time.m4 serial 10 | ||
dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc. | ||
dnl This file is free software; the Free Software Foundation | ||
dnl gives unlimited permission to copy and/or distribute it, | ||
dnl with or without modifications, as long as this notice is preserved. | ||
|
||
# Check for clock_gettime and clock_settime, and set LIB_CLOCK_GETTIME. | ||
# For a program named, say foo, you should add a line like the following | ||
# in the corresponding Makefile.am file: | ||
# foo_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) | ||
|
||
AC_DEFUN([gl_CLOCK_TIME], | ||
[ | ||
dnl Persuade glibc and Solaris <time.h> to declare these functions. | ||
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
# Solaris 2.5.1 needs -lposix4 to get the clock_gettime function. | ||
# Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4. | ||
# Save and restore LIBS so e.g., -lrt, isn't added to it. Otherwise, *all* | ||
# programs in the package would end up linked with that potentially-shared | ||
# library, inducing unnecessary run-time overhead. | ||
LIB_CLOCK_GETTIME= | ||
AC_SUBST([LIB_CLOCK_GETTIME]) | ||
gl_saved_libs=$LIBS | ||
AC_SEARCH_LIBS([clock_gettime], [rt posix4], | ||
[test "$ac_cv_search_clock_gettime" = "none required" || | ||
LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime]) | ||
AC_CHECK_FUNCS([clock_gettime clock_settime]) | ||
LIBS=$gl_saved_libs | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# gettime.m4 serial 7 | ||
dnl Copyright (C) 2002, 2004-2006, 2009-2010 Free Software Foundation, Inc. | ||
dnl This file is free software; the Free Software Foundation | ||
dnl gives unlimited permission to copy and/or distribute it, | ||
dnl with or without modifications, as long as this notice is preserved. | ||
|
||
AC_DEFUN([gl_GETTIME], | ||
[ | ||
AC_LIBOBJ([gettime]) | ||
dnl Prerequisites of lib/gettime.c. | ||
AC_REQUIRE([gl_CLOCK_TIME]) | ||
AC_REQUIRE([gl_TIMESPEC]) | ||
AC_CHECK_FUNCS_ONCE([gettimeofday nanotime]) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#serial 14 | ||
|
||
# Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc. | ||
|
||
# This file is free software; the Free Software Foundation | ||
# gives unlimited permission to copy and/or distribute it, | ||
# with or without modifications, as long as this notice is preserved. | ||
|
||
dnl From Jim Meyering | ||
|
||
AC_DEFUN([gl_TIMESPEC], | ||
[ | ||
dnl Prerequisites of lib/timespec.h. | ||
AC_REQUIRE([AC_C_INLINE]) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* timespec -- System time interface | ||
Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2010 Free Software | ||
Foundation, Inc. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
|
||
#if ! defined TIMESPEC_H | ||
# define TIMESPEC_H | ||
|
||
# include <time.h> | ||
|
||
/* Return negative, zero, positive if A < B, A == B, A > B, respectively. | ||
Assume the nanosecond components are in range, or close to it. */ | ||
static inline int | ||
timespec_cmp (struct timespec a, struct timespec b) | ||
{ | ||
return (a.tv_sec < b.tv_sec ? -1 | ||
: a.tv_sec > b.tv_sec ? 1 | ||
: a.tv_nsec < b.tv_nsec ? -1 | ||
: a.tv_nsec > b.tv_nsec ? 1 | ||
: 0); | ||
} | ||
|
||
void gettime (struct timespec *); | ||
int settime (struct timespec const *); | ||
|
||
#endif |