From: Alan Cox Date: Fri, 2 Jan 2015 18:05:35 +0000 (+0000) Subject: includes: Add more of the POSIX time interfaces X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ebcdf2d249a3bb9b7a45d5d2759f33a557197420;p=FUZIX.git includes: Add more of the POSIX time interfaces --- diff --git a/Library/include/sys/time.h b/Library/include/sys/time.h index 76b0d39a..948d42a9 100644 --- a/Library/include/sys/time.h +++ b/Library/include/sys/time.h @@ -1 +1,48 @@ -#include \ No newline at end of file +#ifndef _SYS_TIME_H +#define _SYS_TIME_H + +#include + +#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 diff --git a/Library/include/time.h b/Library/include/time.h index 0c9a24e0..2c8a5798 100644 --- a/Library/include/time.h +++ b/Library/include/time.h @@ -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 diff --git a/Library/include/unistd.h b/Library/include/unistd.h index 65cb3169..7f40c41d 100644 --- a/Library/include/unistd.h +++ b/Library/include/unistd.h @@ -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);