-*/
-
-#ifdef HAVE_TIMEVAL
-
-#define EMACS_HAS_USECS
-
-#define EMACS_TIME struct timeval
-#define EMACS_SECS(time) ((time).tv_sec + 0)
-#define EMACS_USECS(time) ((time).tv_usec + 0)
-#define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
-#define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
-
-/* On SVR4, the compiler may complain if given this extra BSD arg. */
-#ifdef GETTIMEOFDAY_ONE_ARGUMENT
-#define EMACS_GET_TIME(time) gettimeofday (&(time))
-#else /* not GETTIMEOFDAY_ONE_ARGUMENT */
-/* Presumably the second arg is ignored. */
-#define EMACS_GET_TIME(time) gettimeofday (&(time), NULL)
-#endif /* not GETTIMEOFDAY_ONE_ARGUMENT */
-
-#define EMACS_ADD_TIME(dest, src1, src2) \
- do { \
- (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
- (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
- if ((dest).tv_usec > 1000000) \
- (dest).tv_usec -= 1000000, (dest).tv_sec++; \
- } while (0)
-
-#define EMACS_SUB_TIME(dest, src1, src2) \
- do { \
- (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
- (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
- if ((dest).tv_usec < 0) \
- (dest).tv_usec += 1000000, (dest).tv_sec--; \
- } while (0)
-
-#define EMACS_TIME_NEG_P(time) \
- ((long)(time).tv_sec < 0 \
- || ((time).tv_sec == 0 \
- && (long)(time).tv_usec < 0))
-
-#else /* ! defined (HAVE_TIMEVAL) */
-
-#define EMACS_TIME int
-#define EMACS_SECS(time) (time)
-#define EMACS_USECS(time) 0
-#define EMACS_SET_SECS(time, seconds) ((time) = (seconds))
-#define EMACS_SET_USECS(time, usecs) 0
-
-#define EMACS_GET_TIME(t) ((t) = time ((long *) 0))
-#define EMACS_ADD_TIME(dest, src1, src2) ((dest) = (src1) + (src2))
-#define EMACS_SUB_TIME(dest, src1, src2) ((dest) = (src1) - (src2))
-#define EMACS_TIME_NEG_P(t) ((t) < 0)
-
-#endif /* ! defined (HAVE_TIMEVAL) */
-
-#define EMACS_SET_SECS_USECS(time, secs, usecs) \
- (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
-
-extern int set_file_times (const char *, EMACS_TIME, EMACS_TIME);
+#include <sys/time.h> /* for 'struct timeval' */
+\f
+/* Emacs uses struct timespec to represent nonnegative temporal intervals.
+
+ WARNING: Since tv_sec might be an unsigned value, do not use struct
+ timespec as a general-purpose data type for adding or subtracting
+ arbitrary time values! When computing A + B or A - B, typically A
+ should be an absolute time since the epoch and B a nonnegative offset. */
+
+/* Return an invalid timespec. */
+INLINE struct timespec
+invalid_timespec (void)
+{
+ return make_timespec (0, -1);
+}
+
+/* Return 1 if TIME is a valid timespec. This currently doesn't worry
+ about whether tv_nsec is less than TIMESPEC_RESOLUTION; leap seconds
+ might cause a problem if it did. */
+INLINE int
+timespec_valid_p (struct timespec t)
+{
+ return t.tv_nsec >= 0;
+}
+
+/* Return current system time. */
+INLINE struct timespec
+current_timespec (void)
+{
+ struct timespec r;
+ gettime (&r);
+ return r;
+}
+
+/* defined in sysdep.c */
+extern int set_file_times (int, const char *, struct timespec, struct timespec);
+extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST;