+2004-05-13 Paul Eggert <eggert@cs.ucla.edu>
+
+ * gettime.c (gettime): Fall back on `time' if `gettimeofday'
+ doesn't work.
+ * 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.
+
2004-05-11 Jim Meyering <jim@meyering.net>
Prior to this change, the save_cwd caller required read access to the
/* 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
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;
}
/* 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
#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;
}
+2004-05-13 Paul Eggert <eggert@cs.ucla.edu>
+
+ * gettime.m4 (gl_GETTIME): Require gl_TIMESPEC. Check for gettimeofday.
+ * settime.m4 (gl_SETTIME): Require gl_TIMESPEC. Check for settimeofday,
+ stime.
+
2004-04-20 Paul Eggert <eggert@twinsun.com>
* host-os.m4: Add a copyright notice.
-# 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
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)
])
-# 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
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)
])