[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows
From: |
Paul Eggert |
Subject: |
Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows |
Date: |
Thu, 13 May 2004 15:03:49 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Derek Robert Price <address@hidden> writes:
> Are you aware of any function available on Windows that _does_ yield a
> high resolution time? Preferrably one based on some standard, such as
> C89, C99, or POSIX?
I'd rather not spend time worrying about Microsoft-Windows-specific
time functions, but it does seem reasonable to remove the assumption
that gettimeofday always works, as that assumption is also false on
ancient Unix hosts. coreutils/src/ls.c already does this (in a
slightly different context) so this sounds quite safe. Similarly for
settimeofday.
So I installed this patch into gnulib. It also fixes a dependency bug
(gettime and settime depend on gl_TIMESPEC being called).
2004-05-13 Paul Eggert <address@hidden>
* lib/gettime.c (gettime): Fall back on `time' if `gettimeofday'
doesn't work.
* lib/settime.c: Include <unistd.h>, for stime (on Solaris 8, anyway).
(ENOSYS): Define if not defined.
(settime): Fall back on stime if it exists and settimeofday fails.
But don't bother with fallbacks if a method fails with errno == EPERM.
* m4/gettime.m4 (gl_GETTIME): Require gl_TIMESPEC.
Check for gettimeofday.
* m4/settime.m4 (gl_SETTIME): Require gl_TIMESPEC.
Check for settimeofday, stime.
Index: lib/gettime.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gettime.c,v
retrieving revision 1.2
diff -p -u -r1.2 gettime.c
--- lib/gettime.c 1 Mar 2002 23:54:52 -0000 1.2
+++ lib/gettime.c 13 May 2004 21:54:44 -0000
@@ -1,5 +1,5 @@
/* gettime -- get the system clock
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 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
@@ -33,14 +33,27 @@ gettime (struct timespec *ts)
return 0;
#endif
+#if HAVE_GETTIMEOFDAY
{
struct timeval tv;
- int r = gettimeofday (&tv, 0);
- if (r == 0)
+ if (gettimeofday (&tv, 0) == 0)
{
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
+ return 0;
}
- return r;
}
+#endif
+
+ {
+ time_t t = time (0);
+ if (t != (time_t) -1)
+ {
+ ts->tv_sec = t;
+ ts->tv_nsec = 0;
+ return 0;
+ }
+ }
+
+ return -1;
}
Index: lib/settime.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/settime.c,v
retrieving revision 1.1
diff -p -u -r1.1 settime.c
--- lib/settime.c 1 Mar 2002 23:20:20 -0000 1.1
+++ lib/settime.c 13 May 2004 21:54:44 -0000
@@ -1,5 +1,5 @@
/* settime -- set the system clock
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 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
@@ -23,21 +23,52 @@
#include "timespec.h"
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <errno.h>
+
+/* Some systems don't have ENOSYS. */
+#ifndef ENOSYS
+# ifdef ENOTSUP
+# define ENOSYS ENOTSUP
+# else
+/* Some systems don't have ENOTSUP either. */
+# define ENOSYS EINVAL
+# endif
+#endif
+
/* Set the system time. */
int
settime (struct timespec const *ts)
{
#if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
- if (clock_settime (CLOCK_REALTIME, ts) == 0)
- return 0;
+ {
+ int r = clock_settime (CLOCK_REALTIME, ts);
+ if (r == 0 || errno == EPERM)
+ return r;
+ }
#endif
+#if HAVE_SETTIMEOFDAY
{
struct timeval tv;
+ int r;
tv.tv_sec = ts->tv_sec;
tv.tv_usec = ts->tv_nsec / 1000;
- return settimeofday (&tv, 0);
+ r = settimeofday (&tv, 0);
+ if (r == 0 || errno == EPERM)
+ return r;
}
+#endif
+
+#if HAVE_STIME
+ return stime (&ts->tv_sec);
+#endif
+
+ errno = ENOSYS;
+ return -1;
}
Index: m4/gettime.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/gettime.m4,v
retrieving revision 1.1
diff -p -u -r1.1 gettime.m4
--- m4/gettime.m4 31 Dec 2002 13:42:07 -0000 1.1
+++ m4/gettime.m4 13 May 2004 21:54:45 -0000
@@ -1,5 +1,5 @@
-# gettime.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# gettime.m4 serial 2
+dnl Copyright (C) 2002, 2004 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
@@ -9,6 +9,7 @@ dnl the same distribution terms as the r
AC_DEFUN([gl_GETTIME],
[
dnl Prerequisites of lib/gettime.c.
- # Need clock_gettime.
AC_REQUIRE([gl_CLOCK_TIME])
+ AC_REQUIRE([gl_TIMESPEC])
+ AC_CHECK_FUNCS_ONCE(gettimeofday)
])
Index: m4/settime.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/settime.m4,v
retrieving revision 1.1
diff -p -u -r1.1 settime.m4
--- m4/settime.m4 31 Dec 2002 13:42:07 -0000 1.1
+++ m4/settime.m4 13 May 2004 21:54:45 -0000
@@ -1,5 +1,5 @@
-# settime.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# settime.m4 serial 2
+dnl Copyright (C) 2002, 2004 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
@@ -9,6 +9,7 @@ dnl the same distribution terms as the r
AC_DEFUN([gl_SETTIME],
[
dnl Prerequisites of lib/settime.c.
- # Need clock_settime.
AC_REQUIRE([gl_CLOCK_TIME])
+ AC_REQUIRE([gl_TIMESPEC])
+ AC_CHECK_FUNCS_ONCE(settimeofday stime)
])
- [Bug-gnulib] RE: GNULib Module gettime Breaks CVS Build On Windows, Jim.Hyslop, 2004/05/12
- [Bug-gnulib] RE: GNULib Module gettime Breaks CVS Build On Windows, Jim.Hyslop, 2004/05/12
- [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Derek Robert Price, 2004/05/12
- Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows,
Paul Eggert <=
- Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Derek Robert Price, 2004/05/14
- RE: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Conrad T. Pino, 2004/05/14
- Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Paul Eggert, 2004/05/16
- Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Derek Robert Price, 2004/05/16
- Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows, Paul Eggert, 2004/05/16
[Bug-gnulib] RE: GNULib Module gettime Breaks CVS Build On Windows, Jim.Hyslop, 2004/05/12