Wed Apr 24 17:35:30 Ulrich Drepper <drepper@cygnus.com>
[kopensolaris-gnu/glibc.git] / time / sys / time.h
index c7b0830..c075333 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -13,7 +13,7 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
 #ifndef _SYS_TIME_H
@@ -29,16 +29,27 @@ __BEGIN_DECLS
    microsecond but also has a range of years.  */
 struct timeval
   {
-    int tv_sec;                /* Seconds.  */
-    int tv_usec;       /* Microseconds.  */
+    int tv_sec;                        /* Seconds.  */
+    int tv_usec;               /* Microseconds.  */
   };
 
+/* Macros for converting between `struct timeval' and `struct timespec'.  */
+#define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
+        (ts)->ts_sec = (tv)->tv_sec;                                    \
+        (ts)->ts_nsec = (tv)->tv_usec * 1000;                           \
+}
+#define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
+        (tv)->tv_sec = (ts)->ts_sec;                                    \
+        (tv)->tv_usec = (ts)->ts_nsec / 1000;                           \
+}
+
+
 /* Structure crudely representing a timezone.
    This is obsolete and should never be used.  */
 struct timezone
   {
-    int tz_minuteswest;        /* Minutes west of GMT.  */
-    int tz_dsttime;    /* Nonzero if DST is ever in effect.  */
+    int tz_minuteswest;                /* Minutes west of GMT.  */
+    int tz_dsttime;            /* Nonzero if DST is ever in effect.  */
   };
 
 /* Get the current time of day and timezone information,
@@ -116,11 +127,30 @@ extern int utimes __P ((__const char *__file, struct timeval __tvp[2]));
 /* Convenience macros for operations on timevals.
    NOTE: `timercmp' does not work for >= or <=.  */
 #define        timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
-#define        timercmp(tvp, uvp, CMP) \
-  ((tvp)->tv_sec CMP (uvp)->tv_sec || \
-   (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec CMP (uvp)->tv_usec)
 #define        timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
-
+#define        timercmp(a, b, CMP)                                                   \
+  (((a)->tv_sec == (b)->tv_sec) ?                                            \
+   ((a)->tv_usec CMP (b)->tv_usec) :                                         \
+   ((a)->tv_sec CMP (b)->tv_sec))
+#define        timeradd(a, b, result)                                                \
+  do {                                                                       \
+    (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;                            \
+    (result)->tv_usec = (a)->tv_usec + (b)->tv_usec;                         \
+    if ((result)->tv_usec >= 1000000)                                        \
+      {                                                                              \
+       ++(result)->tv_sec;                                                   \
+       (result)->tv_usec -= 1000000;                                         \
+      }                                                                              \
+  } while (0)
+#define        timersub(a, b, result)                                                \
+  do {                                                                       \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                            \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                         \
+    if ((result)->tv_usec < 0) {                                             \
+      --(result)->tv_sec;                                                    \
+      (result)->tv_usec += 1000000;                                          \
+    }                                                                        \
+  } while (0)
 
 
 __END_DECLS