{
struct deadline_current_time result;
if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0)
- {
- struct timeval current_tv;
- if (__gettimeofday (¤t_tv, NULL) == 0)
- __libc_fatal ("Fatal error: gettimeofday system call failed\n");
- result.current.tv_sec = current_tv.tv_sec;
- result.current.tv_nsec = current_tv.tv_usec * 1000;
- }
+ __clock_gettime (CLOCK_REALTIME, &result.current);
assert (result.current.tv_sec >= 0);
return result;
}
#include <errno.h>
#include <string.h>
#include <utmp.h>
+#include <time.h>
#include <sys/time.h>
int
/* Clear information about who & from where. */
memset (ut->ut_name, '\0', sizeof ut->ut_name);
memset (ut->ut_host, '\0', sizeof ut->ut_host);
- struct timeval tv;
- __gettimeofday (&tv, NULL);
- ut->ut_tv.tv_sec = tv.tv_sec;
- ut->ut_tv.tv_usec = tv.tv_usec;
+
+ struct timespec ts;
+ __clock_gettime (CLOCK_REALTIME, &ts);
+ TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
ut->ut_type = DEAD_PROCESS;
if (pututline (ut) != NULL)
strncpy (ut.ut_name, name, sizeof ut.ut_name);
strncpy (ut.ut_host, host, sizeof ut.ut_host);
- struct timeval tv;
- __gettimeofday (&tv, NULL);
- ut.ut_tv.tv_sec = tv.tv_sec;
- ut.ut_tv.tv_usec = tv.tv_usec;
+ struct timespec ts;
+ __clock_gettime (CLOCK_REALTIME, &ts);
+ TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
updwtmp (_PATH_WTMP, &ut);
}
nis_error status;
directory_obj *obj;
struct timeval now;
+ struct timespec ts;
unsigned int server_used = ~0;
unsigned int current_ep = ~0;
if (*dir != NULL)
return NIS_SUCCESS;
- (void) gettimeofday (&now, NULL);
+ __clock_gettime (CLOCK_REALTIME, &ts);
+ TIMESPEC_TO_TIMEVAL (&now, &ts);
if ((flags & NO_CACHE) == 0)
*dir = nis_server_cache_search (name, search_parent, &server_used,
/* Repeat until thread terminated. */
while ((tid = *tidp) != 0)
{
- struct timeval tv;
struct timespec rt;
/* Get the current time. */
- __gettimeofday (&tv, NULL);
+ __clock_gettime (CLOCK_REALTIME, &rt);
/* Compute relative timeout. */
- rt.tv_sec = abstime->tv_sec - tv.tv_sec;
- rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ rt.tv_sec = abstime->tv_sec - rt.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
if (rt.tv_nsec < 0)
{
rt.tv_nsec += 1000000000;
goto failpp;
}
- struct timeval tv;
struct timespec rt;
/* Get the current time. */
- (void) __gettimeofday (&tv, NULL);
+ __clock_gettime (CLOCK_REALTIME, &rt);
/* Compute relative timeout. */
- rt.tv_sec = abstime->tv_sec - tv.tv_sec;
- rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ rt.tv_sec = abstime->tv_sec - rt.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
if (rt.tv_nsec < 0)
{
rt.tv_nsec += 1000000000;
/* Handle the case where the poll() call is interrupted by a
signal. We cannot just use TEMP_FAILURE_RETRY since it might
lead to infinite loops. */
- struct timeval now;
- (void) __gettimeofday (&now, NULL);
- long int end = now.tv_sec * 1000 + usectmo + (now.tv_usec + 500) / 1000;
+ struct timespec now;
+ __clock_gettime (CLOCK_REALTIME, &now);
+ long int end = (now.tv_sec * 1000 + usectmo
+ + (now.tv_nsec + 500000) / 1000000);
long int timeout = usectmo;
while (1)
{
break;
/* Recompute the timeout time. */
- (void) __gettimeofday (&now, NULL);
- timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000);
+ __clock_gettime (CLOCK_REALTIME, &now);
+ timeout = end - ((now.tv_sec * 1000
+ + (now.tv_nsec + 500000) / 1000000));
}
}
memcpy (reqdata->key, key, keylen);
bool first_try = true;
- struct timeval tvend;
- /* Fake initializing tvend. */
- asm ("" : "=m" (tvend));
+ struct timespec tvend = { 0, 0 };
while (1)
{
#ifndef MSG_NOSIGNAL
/* The daemon is busy wait for it. */
int to;
- struct timeval now;
- (void) __gettimeofday (&now, NULL);
+ struct timespec now;
+ __clock_gettime (CLOCK_REALTIME, &now);
if (first_try)
{
- tvend.tv_usec = now.tv_usec;
+ tvend.tv_nsec = now.tv_nsec;
tvend.tv_sec = now.tv_sec + 5;
to = 5 * 1000;
first_try = false;
}
else
to = ((tvend.tv_sec - now.tv_sec) * 1000
- + (tvend.tv_usec - now.tv_usec) / 1000);
+ + (tvend.tv_nsec - now.tv_nsec) / 1000000);
struct pollfd fds[1];
fds[0].fd = sock;
something to arrive in it. */
if (runp == NULL && optim.gai_idle_time >= 0)
{
- struct timeval now;
+ struct timespec now;
struct timespec wakeup_time;
++idle_thread_count;
- gettimeofday (&now, NULL);
+ __clock_gettime (CLOCK_REALTIME, &now);
wakeup_time.tv_sec = now.tv_sec + optim.gai_idle_time;
- wakeup_time.tv_nsec = now.tv_usec * 1000;
+ wakeup_time.tv_nsec = now.tv_nsec;
if (wakeup_time.tv_nsec >= 1000000000)
{
wakeup_time.tv_nsec -= 1000000000;
{
/* We have to convert the relative timeout value into an
absolute time value with pthread_cond_timedwait expects. */
- struct timeval now;
+ struct timespec now;
struct timespec abstime;
- __gettimeofday (&now, NULL);
- abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
+ __clock_gettime (CLOCK_REALTIME, &now);
+ abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
abstime.tv_sec = timeout->tv_sec + now.tv_sec;
if (abstime.tv_nsec >= 1000000000)
{
static void
evNowTime(struct timespec *res) {
- struct timeval now;
-
- if (gettimeofday(&now, NULL) < 0)
- evConsTime(res, 0, 0);
- else
- TIMEVAL_TO_TIMESPEC (&now, res);
+ __clock_gettime(CLOCK_REALTIME, res);
}
#include <rpc/xdr.h>
#include <netinet/in.h> /* XXX: just to get htonl() and ntohl() */
#include <sys/socket.h>
+#include <time.h>
#include <shlib-compat.h>
#define MILLION 1000000L
int status;
int len;
register int32_t *ixdr;
- struct timeval tval;
+ struct timespec now;
/*
* Figure out the "time", accounting for any time difference
* with the server if necessary.
*/
- __gettimeofday (&tval, (struct timezone *) NULL);
- ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec;
- ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec;
+ __clock_gettime (CLOCK_REALTIME, &now);
+ ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec;
+ ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec;
if (ad->ad_timestamp.tv_usec >= MILLION)
{
ad->ad_timestamp.tv_usec -= MILLION;
static bool_t
synchronize (struct sockaddr *syncaddr, struct rpc_timeval *timep)
{
- struct timeval mytime;
+ struct timespec mytime;
struct rpc_timeval timeout;
+ long int myusec;
timeout.tv_sec = RTIME_TIMEOUT;
timeout.tv_usec = 0;
if (rtime ((struct sockaddr_in *) syncaddr, timep, &timeout) < 0)
return FALSE;
- __gettimeofday (&mytime, (struct timezone *) NULL);
+ __clock_gettime (CLOCK_REALTIME, &mytime);
timep->tv_sec -= mytime.tv_sec;
- if (mytime.tv_usec > timep->tv_usec)
+ myusec = mytime.tv_nsec / 1000;
+ if (myusec > timep->tv_usec)
{
timep->tv_sec -= 1;
timep->tv_usec += MILLION;
}
- timep->tv_usec -= mytime.tv_usec;
+ timep->tv_usec -= myusec;
return TRUE;
}
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <time.h>
#include <libintl.h>
#include <sys/param.h>
#include <wchar.h>
{
struct authunix_parms aup;
char mymem[MAX_AUTH_BYTES];
- struct timeval now;
+ struct timespec now;
XDR xdrs;
AUTH *auth;
struct audata *au;
/*
* fill in param struct from the given params
*/
- (void) __gettimeofday (&now, (struct timezone *) 0);
+ __clock_gettime (CLOCK_REALTIME, &now);
aup.aup_time = now.tv_sec;
aup.aup_machname = machname;
aup.aup_uid = uid;
{
struct audata *au = AUTH_PRIVATE (auth);
struct authunix_parms aup;
- struct timeval now;
+ struct timespec now;
XDR xdrs;
int stat;
goto done;
/* update the time and serialize in place */
- (void) __gettimeofday (&now, (struct timezone *) 0);
+ __clock_gettime (CLOCK_REALTIME, &now);
aup.aup_time = now.tv_sec;
xdrs.x_op = XDR_ENCODE;
XDR_SETPOS (&xdrs, 0);
pid_t pid = getpid ();
if (is_initialized != pid)
{
- struct timeval now;
+ struct timespec now;
- __gettimeofday (&now, (struct timezone *) 0);
- __srand48_r (now.tv_sec ^ now.tv_usec ^ pid,
+ __clock_gettime (CLOCK_REALTIME, &now);
+ __srand48_r (now.tv_sec ^ now.tv_nsec ^ pid,
&__rpc_lrand48_data);
is_initialized = pid;
}
#include <limits.h>
#include <string.h>
#include <stdint.h>
+#include <time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <rpc/rpc.h>
debug ("timestamp before last seen");
return AUTH_REJECTEDVERF; /* replay */
}
- __gettimeofday (¤t, (struct timezone *) NULL);
+ {
+ struct timespec now;
+ __clock_gettime (CLOCK_REALTIME, &now);
+ TIMESPEC_TO_TIMEVAL (¤t, &now);
+ }
current.tv_sec -= window; /* allow for expiration */
if (!BEFORE (¤t, ×tamp))
{
static void (*cleanup_function) (void);
static void
-print_timestamp (const char *what, struct timeval tv)
+print_timestamp (const char *what, struct timespec tv)
{
struct tm tm;
+ /* Casts of tv.tv_nsec below are necessary because the type of
+ tv_nsec is not literally long int on all supported platforms. */
if (gmtime_r (&tv.tv_sec, &tm) == NULL)
- printf ("%s: %lld.%06d\n",
- what, (long long int) tv.tv_sec, (int) tv.tv_usec);
+ printf ("%s: %lld.%09ld\n",
+ what, (long long int) tv.tv_sec, (long int) tv.tv_nsec);
else
- printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
+ printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%09ld\n",
what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
+ tm.tm_hour, tm.tm_min, tm.tm_sec, (long int) tv.tv_nsec);
}
/* Timeout handler. We kill the child and exit with an error. */
/* Do this first to avoid further interference from the
subprocess. */
- struct timeval now;
- bool now_available = gettimeofday (&now, NULL) == 0;
+ struct timespec now;
+ clock_gettime (CLOCK_REALTIME, &now);
struct stat64 st;
bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0;
printf ("Timed out: killed the child process but it exited %d\n",
WEXITSTATUS (status));
- if (now_available)
- print_timestamp ("Termination time", now);
+ print_timestamp ("Termination time", now);
if (st_available)
- print_timestamp ("Last write to standard output",
- (struct timeval) { st.st_mtim.tv_sec,
- st.st_mtim.tv_nsec / 1000 });
+ print_timestamp ("Last write to standard output", st.st_mtim);
/* Exit with an error. */
exit (1);
#endif
#ifndef GETTIME
-# define GETTIME(low,high) \
- { \
- struct timeval tval; \
- uint64_t usecs; \
- gettimeofday (&tval, NULL); \
- usecs = (uint64_t) tval.tv_usec + (uint64_t) tval.tv_usec * 1000000; \
- low = usecs & 0xffffffff; \
- high = usecs >> 32; \
+# define GETTIME(low,high) \
+ { \
+ struct timespec now; \
+ uint64_t usecs; \
+ clock_gettime (CLOCK_REALTIME, &now); \
+ usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
+ low = usecs & 0xffffffff; \
+ high = usecs >> 32; \
}
#endif
#include <errno.h>
#include <sys/time.h>
#include <hurd.h>
+#include <mach.h>
-/* XXX Temporary cheezoid implementation; see __setitmr.c. */
+/* XXX Temporary cheezoid implementation; see setitimer.c. */
/* These are defined in __setitmr.c. */
extern spin_lock_t _hurd_itimer_lock;
}
/* Get the time now. */
- if (__gettimeofday (&elapsed, NULL) < 0)
- return -1;
+ {
+ time_value_t tv;
+ __host_get_time (__mach_host_self (), &tv);
+ elapsed.tv_sec = tv.seconds;
+ elapsed.tv_usec = tv.microseconds;
+ }
/* Extract the current timer setting; and the time it was set, so we can
calculate the time elapsed so far. */
#include <hurd/signal.h>
#include <hurd/sigpreempt.h>
#include <hurd/msg_request.h>
+#include <mach.h>
#include <mach/message.h>
/* XXX Temporary cheezoid implementation of ITIMER_REAL/SIGALRM. */
if ((newval.it_value.tv_sec | newval.it_value.tv_usec) != 0 || old != NULL)
{
/* Calculate how much time is remaining for the pending alarm. */
- if (__gettimeofday (&now, NULL) < 0)
- {
- __spin_unlock (&_hurd_itimer_lock);
- _hurd_critical_section_unlock (crit);
- return -1;
- }
+ {
+ time_value_t tv;
+ __host_get_time (__mach_host_self (), &tv);
+ now.tv_sec = tv.seconds;
+ now.tv_usec = tv.microseconds;
+ }
elapsed = now;
subtract_timeval (&elapsed, &_hurd_itimer_started);
remaining = _hurd_itimerval.it_value;
struct task_basic_info bi;
struct task_thread_times_info tti;
mach_msg_type_number_t count;
- union { time_value_t tvt; struct timeval tv; } now;
+ time_value_t now;
error_t err;
count = TASK_BASIC_INFO_COUNT;
/* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
tms->tms_cutime = tms->tms_cstime = 0;
- if (__gettimeofday (&now.tv, NULL) < 0)
- return -1;
+ __host_get_time (__mach_host_self (), &now);
- return (clock_from_time_value (&now.tvt)
+ return (clock_from_time_value (&now)
- clock_from_time_value (&bi.creation_time));
}
weak_alias (__times, times)
#include <errno.h>
#include <mach.h>
-#include <sys/time.h>
#include <time.h>
#include <unistd.h>
+# define timespec_sub(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
+ if ((result)->tv_nsec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_nsec += 1000000000; \
+ } \
+ } while (0)
+
int
__libc_nanosleep (const struct timespec *requested_time,
- struct timespec *remaining)
+ struct timespec *remaining)
{
mach_port_t recv;
- struct timeval before, after;
+ struct timespec before;
+ error_t err;
if (requested_time->tv_sec < 0
|| ! valid_nanoseconds (requested_time->tv_nsec))
recv = __mach_reply_port ();
- if (remaining && __gettimeofday (&before, NULL) < 0)
- return -1;
- error_t err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
- 0, 0, recv, ms, MACH_PORT_NULL);
+ if (remaining != 0)
+ __clock_gettime (CLOCK_REALTIME, &before);
+
+ err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
+ 0, 0, recv, ms, MACH_PORT_NULL);
__mach_port_destroy (mach_task_self (), recv);
if (err == EMACH_RCV_INTERRUPTED)
{
- if (remaining && __gettimeofday (&after, NULL) >= 0)
+ if (remaining != 0)
{
- struct timeval req_time, elapsed, rem;
- TIMESPEC_TO_TIMEVAL (&req_time, requested_time);
- timersub (&after, &before, &elapsed);
- timersub (&req_time, &elapsed, &rem);
- TIMEVAL_TO_TIMESPEC (&rem, remaining);
+ struct timespec after, elapsed;
+ __clock_gettime (CLOCK_REALTIME, &after);
+ timespec_sub (&after, &before, &elapsed);
+ timespec_sub (requested_time, &elapsed, remaining);
}
errno = EINTR;
usleep (useconds_t useconds)
{
mach_port_t recv;
- struct timeval before, after;
recv = __mach_reply_port ();
- if (__gettimeofday (&before, NULL) < 0)
- return -1;
(void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);
__mach_port_destroy (mach_task_self (), recv);
- if (__gettimeofday (&after, NULL) < 0)
- return -1;
return 0;
}
#include <string.h>
#include <fcntl.h>
-#include <sys/time.h>
+#include <time.h>
#include <stdint.h>
#include <unistd.h>
# define struct_stat64 struct stat
# define __gen_tempname gen_tempname
# define __getpid getpid
-# define __gettimeofday gettimeofday
# define __mkdir mkdir
# define __open open
# define __lxstat64(version, file, buf) lstat (file, buf)
# else
# define RANDOM_BITS(Var) \
{ \
- struct timeval tv; \
- __gettimeofday (&tv, NULL); \
- (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \
+ struct timespec ts; \
+ clock_gettime (CLOCK_REALTIME, &ts); \
+ (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec; \
}
#endif
int
timespec_get (struct timespec *ts, int base)
{
- switch (base)
+ if (base == TIME_UTC)
{
- case TIME_UTC:
- if (__clock_gettime (CLOCK_REALTIME, ts) < 0)
- return 0;
- break;
-
- default:
- return 0;
+ __clock_gettime (CLOCK_REALTIME, ts);
+ return base;
}
-
- return base;
+ return 0;
}
something to arrive in it. */
if (runp == NULL && optim.aio_idle_time >= 0)
{
- struct timeval now;
+ struct timespec now;
struct timespec wakeup_time;
++idle_thread_count;
- __gettimeofday (&now, NULL);
+ __clock_gettime (CLOCK_REALTIME, &now);
wakeup_time.tv_sec = now.tv_sec + optim.aio_idle_time;
- wakeup_time.tv_nsec = now.tv_usec * 1000;
+ wakeup_time.tv_nsec = now.tv_nsec;
if (wakeup_time.tv_nsec >= 1000000000)
{
wakeup_time.tv_nsec -= 1000000000;
{
/* We have to convert the relative timeout value into an
absolute time value with pthread_cond_timedwait expects. */
- struct timeval now;
+ struct timespec now;
struct timespec abstime;
- __gettimeofday (&now, NULL);
- abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000;
+ __clock_gettime (CLOCK_REALTIME, &now);
+ abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
abstime.tv_sec = timeout->tv_sec + now.tv_sec;
if (abstime.tv_nsec >= 1000000000)
{
# n: scalar buffer length (e.g., 3rd arg to read)
# N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
# p: non-NULL pointer to typed object (e.g., any non-void* arg)
-# P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
+# P: optionally-NULL pointer to typed object (e.g., 3rd argument to sigaction)
# s: non-NULL string (e.g., 1st arg to open)
# S: optionally-NULL string (e.g., 1st arg to acct)
# v: vararg scalar (e.g., optional 3rd arg to open)