diff options
-rwxr-xr-x | configure | 20 | ||||
-rw-r--r-- | time.c | 17 | ||||
-rw-r--r-- | time.h | 1 | ||||
-rw-r--r-- | txr.1 | 17 |
4 files changed, 54 insertions, 1 deletions
@@ -3593,6 +3593,26 @@ else printf "no\n" fi +printf "Checking for clock_gettime ... " +cat > conftest.c <<! +#include <time.h> + +int main(void) +{ + struct timespec ts; + (void) clock_gettime(CLOCK_REALTIME, &ts); + return 0; +} +! + +if conftest ; then + printf "yes\n" + printf "#define HAVE_CLOCK_GETTIME 1\n" >> config.h + have_sys_types=y +else + printf "no\n" +fi + printf "Checking for loff_t ... " cat > conftest.c <<! #include <sys/types.h> @@ -63,6 +63,22 @@ val time_sec_usec(void) return cons(num_time(tv.tv_sec), num(tv.tv_usec)); } +val time_sec_nsec(void) +{ +#if HAVE_CLOCK_GETTIME + struct timespec ts; + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) + return nil; + return cons(num_time(ts.tv_sec), num(ts.tv_nsec)); +#else + struct timeval tv; + if (gettimeofday(&tv, 0) == -1) + return nil; + return cons(num_time(tv.tv_sec), num(1000 * tv.tv_usec)); +#endif +} + + #if !HAVE_GMTIME_R struct tm *gmtime_r(const time_t *timep, struct tm *result); struct tm *localtime_r(const time_t *timep, struct tm *result); @@ -497,6 +513,7 @@ void time_init(void) reg_fun(intern(lit("time"), user_package), func_n0(time_sec)); reg_fun(intern(lit("time-usec"), user_package), func_n0(time_sec_usec)); + reg_fun(intern(lit("time-nsec"), user_package), func_n0(time_sec_nsec)); reg_fun(intern(lit("time-string-local"), user_package), func_n2(time_string_local)); reg_fun(intern(lit("time-string-utc"), user_package), func_n2(time_string_utc)); reg_fun(intern(lit("time-fields-local"), user_package), func_n1(time_fields_local)); @@ -31,6 +31,7 @@ extern val dst_s, gmtoff_s, zone_s; val time_sec(void); val time_sec_usec(void); +val time_sec_nsec(void); val time_string_local(val time, val format); val time_string_utc(val time, val format); val time_fields_local(val time); @@ -55976,10 +55976,11 @@ parameter, which defaults to the value of .codn *random-state* . .SS* Time -.coNP Functions @ time and @ time-usec +.coNP Functions @, time @ time-usec and @ time-nsec .synb .mets (time) .mets (time-usec) +.mets (time-nsec) .syne .desc The @@ -55998,6 +55999,20 @@ field holds the seconds measured in the same way, and whose field extends the precision by giving number of microseconds as an integer value between 0 and 999999. +The +.code time-nsec +function is similar to +.code time-usec +except that the returned cons cell's +.code cdr +field gives a number of nanoseconds as an integer value +between 0 and 999999999. + +Note: on hosts where obtaining nanosecond precision is not available, the +.code time-nsec +function obtains a microseconds value instead, and multiplies +it by 1000. + .coNP Functions @ time-string-local and @ time-string-utc .synb .mets (time-string-local < time << format ) |