includes: Add more of the POSIX time interfaces
authorAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 18:05:35 +0000 (18:05 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 18:05:35 +0000 (18:05 +0000)
Library/include/sys/time.h
Library/include/time.h
Library/include/unistd.h

index 76b0d39..948d42a 100644 (file)
@@ -1 +1,48 @@
-#include <time.h>
\ No newline at end of file
+#ifndef _SYS_TIME_H
+#define _SYS_TIME_H
+
+#include <time.h>
+
+#ifdef _BSD_SOURCE
+
+typedef unsigned long suseconds_t;
+
+struct timeval {
+  time_t tv_sec;
+  suseconds_t tv_usec;
+};
+
+extern int gettimeofday(struct timeval *tv, struct timezone *tz);
+extern int settimeofday(struct timeval *tv, const struct timezone *tz);
+
+/* These are courtesy of Linux. Complete with the usual bugs. The only
+   change here is to use L for the long types. */
+# define timerisset(tvp)       ((tvp)->tv_sec || (tvp)->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 >= 1000000L)                                       \
+      {                                                                              \
+       ++(result)->tv_sec;                                                   \
+       (result)->tv_usec -= 1000000L;                                        \
+      }                                                                              \
+  } 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 += 1000000L;                                         \
+    }                                                                        \
+  } while (0)
+
+#endif /* Berkleyisms */
+
+#endif
index 0c9a24e..2c8a579 100644 (file)
@@ -23,6 +23,11 @@ struct timezone {
        int tz_dsttime;         /* type of dst correction */
 };
 
+struct timespec {
+       time_t tv_sec;
+       long tv_nsec;
+};
+
 #define __isleap(year) \
        ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
 
@@ -46,5 +51,21 @@ extern struct tm *gmtime __P ((time_t *__tp));
 extern struct tm *localtime __P ((time_t * __tp));
 extern unsigned long convtime __P ((time_t *time_field));
 
+typedef int clockid_t;
+
 #define CLOCKS_PER_SEC 100             /* FIXME: sysconf */
+
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+
+extern int clock_getres(clockid_t clk_id,  struct timespec *res);
+extern int clock_gettime(clockid_t clk_id,  struct timespec *tp);
+extern int clock_nanosleep(clockid_t clk_id, int flags,
+       const struct timespec *request, struct timespec *remain);
+extern int clock_settime(clockid_t clk_id,  const struct timespec *tp);
+
+#define TIMER_ABSTIME  1
+
+extern int nanosleep(const struct timespec *request, struct timespec *remain);
+
 #endif
index 65cb316..7f40c41 100644 (file)
@@ -93,6 +93,10 @@ extern long _pathconf __P((int name));
 #define _POSIX_CHOWN_RESTRICTED _pathconf(_PC_CHOWN_RESTRICTED)
 #define _POSIX_NO_TRUNC                _pathconf(_PC_NO_TRUNC)
 
+/* POSIX: show that the clock_ API is present */
+#define _POSIX_TIMERS
+#define _POSIX_MONTONIC_CLOCK
+
 extern int gethostname(char *name, size_t len);
 extern int sethostname(const char *name, size_t len);