--- /dev/null
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+int clock_getres(clockid_t clk_id, struct timespec *res)
+{
+ res->tv_nsec = 0;
+ res->tv_sec = 1;
+ switch(clk_id) {
+ case CLOCK_REALTIME:
+ case CLOCK_MONOTONIC:
+ return 0;
+ default:
+ errno = EINVAL;
+ }
+ return -1;
+}
\ No newline at end of file
--- /dev/null
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+int clock_gettime(clockid_t clk_id, struct timespec *res)
+{
+ res->tv_nsec = 0;
+ switch(clk_id) {
+ case CLOCK_REALTIME:
+ _time(&res->tv_sec, 0);
+ return 0;
+ case CLOCK_MONOTONIC:
+ _time(&res->tv_sec, 1);
+ return 0;
+ default:
+ errno = EINVAL;
+ }
+ return -1;
+}
\ No newline at end of file
--- /dev/null
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+int clock_settime(clockid_t clk_id, const struct timespec *tp)
+{
+ switch(clk_id) {
+ case CLOCK_REALTIME:
+ _stime(&tp->tv_sec, 0);
+ return 0;
+ case CLOCK_MONOTONIC:
+ return -EPERM;
+ default:
+ errno = EINVAL;
+ }
+ return -1;
+}
\ No newline at end of file
--- /dev/null
+#define _BSD_SOURCE
+
+#include <sys/time.h>
+#include <unistd.h>
+
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ if (tv) {
+ _time(&tv->tv_sec, 0);
+ tv->tv_usec = 0;
+ }
+ if (tz) {
+ /* FIXME: although this is obsolete */
+ tz->tz_minuteswest = 0;
+ /* and this is not used */
+ tz->tz_dsttime = 0;
+ }
+ return 0;
+}
+
+
\ No newline at end of file
--- /dev/null
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* Ok so this doesn't score too highly on accuracy but it'll wrap code using
+ the modern API's for long sleeps just fine */
+
+int clock_nanosleep(clockid_t clock, int flags, const struct timespec *req, struct timespec *rem)
+{
+ time_t tbase;
+ time_t tend;
+ uint16_t t = req->tv_sec * 10;
+ long nsec = req->tv_nsec;
+
+ if (clock != CLOCK_REALTIME && clock != CLOCK_MONOTONIC) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* Will be 0-9 range so avoid costly divides */
+ while(nsec > 50000000UL) {
+ nsec -= 50000000UL;
+ t++;
+ }
+
+ if (_time(&tbase, clock) == -1)
+ return -1;
+
+ if (flags & TIMER_ABSTIME) {
+ if (tbase < req->tv_sec)
+ return 0;
+ t += (tbase - req->tv_sec) * 10;
+ }
+ if (_pause(t) == 0)
+ return 0;
+ _time(&tend, clock);
+ if (rem) {
+ rem->tv_sec = tbase + t/10 - tend;
+ rem->tv_nsec = 0;
+ }
+ return -1;
+}
+
+
+int nanosleep(const struct timespec *req, struct timespec *rem)
+{
+ return clock_nanosleep(CLOCK_REALTIME, 0, req, rem);
+}
+
--- /dev/null
+#define _BSD_SOURCE
+
+#include <sys/time.h>
+#include <unistd.h>
+
+int settimeofday(struct timeval *tv, const struct timezone *tz)
+{
+ int ret = 0;
+ if (tv) {
+ ret = _stime(&tv->tv_sec, 0);
+ }
+ return ret;
+}