Mercurial > prosody-hg
comparison util-src/time.c @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 94cacf9fd0ae |
| children | a187600ec7d6 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 1 #ifndef _POSIX_C_SOURCE | 1 #ifndef _POSIX_C_SOURCE |
| 2 #define _POSIX_C_SOURCE 199309L | 2 #define _POSIX_C_SOURCE 200809L |
| 3 #endif | 3 #endif |
| 4 | 4 |
| 5 #include <time.h> | 5 #include <time.h> |
| 6 #include <lua.h> | 6 #include <lua.h> |
| 7 | 7 |
| 8 lua_Number tv2number(struct timespec *tv) { | 8 static lua_Number tv2number(struct timespec *tv) { |
| 9 return tv->tv_sec + tv->tv_nsec * 1e-9; | 9 return tv->tv_sec + tv->tv_nsec * 1e-9; |
| 10 } | 10 } |
| 11 | 11 |
| 12 int lc_time_realtime(lua_State *L) { | 12 static int lc_time_realtime(lua_State *L) { |
| 13 struct timespec t; | 13 struct timespec t; |
| 14 clock_gettime(CLOCK_REALTIME, &t); | 14 clock_gettime(CLOCK_REALTIME, &t); |
| 15 lua_pushnumber(L, tv2number(&t)); | 15 lua_pushnumber(L, tv2number(&t)); |
| 16 return 1; | 16 return 1; |
| 17 } | 17 } |
| 18 | 18 |
| 19 int lc_time_monotonic(lua_State *L) { | 19 static int lc_time_monotonic(lua_State *L) { |
| 20 struct timespec t; | 20 struct timespec t; |
| 21 clock_gettime(CLOCK_MONOTONIC, &t); | 21 clock_gettime(CLOCK_MONOTONIC, &t); |
| 22 lua_pushnumber(L, tv2number(&t)); | 22 lua_pushnumber(L, tv2number(&t)); |
| 23 return 1; | 23 return 1; |
| 24 } | 24 } |
