diff options
-rw-r--r-- | src/library.js | 5 | ||||
-rw-r--r-- | tests/time/src.c | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js index 04976b92..d897556f 100644 --- a/src/library.js +++ b/src/library.js @@ -6186,8 +6186,9 @@ LibraryManager.library = { clock_gettime__deps: ['__timespec_struct_layout'], clock_gettime: function(clk_id, tp) { // int clock_gettime(clockid_t clk_id, struct timespec *tp); - {{{ makeSetValue('tp', '___timespec_struct_layout.tv_sec', '0', 'i32') }}} - {{{ makeSetValue('tp', '___timespec_struct_layout.tv_nsec', '0', 'i32') }}} + var now = Date.now(); + {{{ makeSetValue('tp', '___timespec_struct_layout.tv_sec', 'Math.floor(now/1000)', 'i32') }}}; // seconds + {{{ makeSetValue('tp', '___timespec_struct_layout.tv_nsec', '0', 'i32') }}}; // nanoseconds - not supported return 0; }, clock_settime: function(clk_id, tp) { diff --git a/tests/time/src.c b/tests/time/src.c index d33885fe..61faedfe 100644 --- a/tests/time/src.c +++ b/tests/time/src.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <time.h> #include <string.h> +#include <assert.h> +#include <math.h> int main() { time_t xmas2002 = 1040786563ll; @@ -64,6 +66,9 @@ int main() { // Verify time() returns reasonable value (between 2011 and 2030). time_t t4 = 0; time(&t4); + timespec ts; + assert(clock_gettime(0, &ts) == 0); + assert(abs(ts.tv_sec - t4) <= 2); printf("time: %d\n", t4 > 1309635200ll && t4 < 1893362400ll); // Verify difftime() calculates accurate time difference. |