Unified · Split
| @@ -4,6 +4,7 @@ · 3 unmodified lines | |||
| 4 | #include <npe.h> | 4 | #include <npe.h> |
| 5 | 5 | ||
| 6 | typedef long time_t; | 6 | typedef long time_t; |
| 7 | typedef int clockid_t; | ||
| 7 | 8 | ||
| 8 | struct tm { | 9 | struct tm { |
| 9 | int tm_sec; | 10 | int tm_sec; |
| @@ -18,6 +19,16 @@ struct tm { · 8 unmodified lines | |||
| 18 | char *tm_zone; | 19 | char *tm_zone; |
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 22 | struct timespec { | ||
| 23 | time_t tv_sec; | ||
| 24 | long tv_nsec; | ||
| 25 | }; | ||
| 26 | |||
| 27 | enum { | ||
| 28 | CLOCK_REALTIME, | ||
| 29 | CLOCK_MONOTONIC, | ||
| 30 | }; | ||
| 31 | |||
| 21 | #include <sys/time.h> | 32 | #include <sys/time.h> |
| 22 | 33 | ||
| 23 | #define localtime npe_localtime | 34 | #define localtime npe_localtime |
| @@ -26,5 +37,6 @@ struct tm *npe_localtime(time_t *timep); · 2 unmodified lines | |||
| 26 | struct tm *npe_gmtime(time_t *timep); | 37 | struct tm *npe_gmtime(time_t *timep); |
| 27 | size_t strftime(char *s, size_t max, const char *format, const struct tm *tm); | 38 | size_t strftime(char *s, size_t max, const char *format, const struct tm *tm); |
| 28 | time_t mktime(struct tm *tm); | 39 | time_t mktime(struct tm *tm); |
| 40 | int clock_gettime(clockid_t clockid, struct timespec *tp); | ||
| 29 | 41 | ||
| 30 | #endif | 42 | #endif |
| @@ -0,0 +1,23 @@ | |||
| 1 | #include <errno.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include "_npe.h" | ||
| 4 | |||
| 5 | int | ||
| 6 | clock_gettime(clockid_t clockid, struct timespec *tp) | ||
| 7 | { | ||
| 8 | uvlong t; | ||
| 9 | |||
| 10 | if(clockid == CLOCK_REALTIME) | ||
| 11 | t = nsec(); | ||
| 12 | else if(clockid == CLOCK_MONOTONIC) | ||
| 13 | t = npe_nanosec(); | ||
| 14 | else{ | ||
| 15 | errno = EINVAL; | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | tp->tv_nsec = t % 1000000000; | ||
| 20 | tp->tv_sec = t / 1000000000; | ||
| 21 | |||
| 22 | return 0; | ||
| 23 | } | ||
| @@ -16,6 +16,7 @@ OFILES=\ · 15 unmodified lines | |||
| 16 | acosh.$O\ | 16 | acosh.$O\ |
| 17 | basename.$O\ | 17 | basename.$O\ |
| 18 | cbrtf.$O\ | 18 | cbrtf.$O\ |
| 19 | clock_gettime.$O\ | ||
| 19 | closedir.$O\ | 20 | closedir.$O\ |
| 20 | dirfd.$O\ | 21 | dirfd.$O\ |
| 21 | dirname.$O\ | 22 | dirname.$O\ |