/*
* ion/libmainloop/signal.c
*
- * Copyright (c) Tuomo Valkonen 1999-2007.
+ * Copyright (c) Tuomo Valkonen 1999-2008.
*
* See the included file LICENSE for details.
*/
#include <signal.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <libtu/objp.h>
#include <libtu/types.h>
int mainloop_gettime(struct timeval *val)
{
-#ifdef _POSIX_MONOTONIC_CLOCK
+#if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK>=0)
struct timespec spec;
int ret;
+ static int checked=0;
- ret=clock_gettime(CLOCK_MONOTONIC, &spec);
+ if(checked>=0){
+ ret=clock_gettime(CLOCK_MONOTONIC, &spec);
- val->tv_sec=spec.tv_sec;
- val->tv_usec=spec.tv_nsec/1000;
-
- return ret;
+ if(ret==-1 && errno==EINVAL && checked==0){
+ checked=-1;
+ }else{
+ checked=1;
+
+ val->tv_sec=spec.tv_sec;
+ val->tv_usec=spec.tv_nsec/1000;
+
+ return ret;
+ }
+ }
#else
- return gettimeofday(&val, NULL);
+ #warning "Monotonic clock unavailable; please fix your operating system."
#endif
+ return gettimeofday(val, NULL);
}