diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-10-31 19:38:03 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-10-31 19:38:03 -0700 |
commit | d40e8bd6d7956f757bffd34c7288fd996e617c1e (patch) | |
tree | 6ffc3dfa4cc992f8fcd19acc48f7a73de104ac13 /lib.c | |
parent | 1d3d115e1f50d1f1feaec7d409c853621b8d939f (diff) | |
download | txr-d40e8bd6d7956f757bffd34c7288fd996e617c1e.tar.gz txr-d40e8bd6d7956f757bffd34c7288fd996e617c1e.tar.bz2 txr-d40e8bd6d7956f757bffd34c7288fd996e617c1e.zip |
lib: don't assume time_t is signed.
We introduce the function c_time to convert a Lisp integer
to time_t, and num_time to do the reverse conversion.
The FFI type time-t already does this right.
(See registration of time-t in ffi_init_extra_types).
* hash.c (gen_hash_seed): The first value out of time_sec_usec
corresponds to a time_t value. We now convert this to C number
using c_time rather than c_num. Also, while we are touching
this code, the microseconds value can convert directly to
ucnum with c_unum.
* lib.c (time_sec_usec): Use num_time for seconds.
(time_string_local, time_string_utc, time_fields_local,
time_fields_utc, time_struct_local, time_struct_utc): Use c_time.
(make_time_impl, time_parse_utc): Use num_time instead of num.
* signal.h (getitimer_wrap, setitimer_wrap): Convert tv_sec
members of struct timeval using c_time and num_time.
* sysif.c (c_time, num_time): New functions.
(stat_to_struct): Convert st_atime, st_mtime and st_ctime
to Lisp using num_time instead of num.
* sysif.c (c_time, num_time): Declared.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -12079,7 +12079,7 @@ val time_sec_usec(void) struct timeval tv; if (gettimeofday(&tv, 0) == -1) return nil; - return cons(num(tv.tv_sec), num(tv.tv_usec)); + return cons(num_time(tv.tv_sec), num(tv.tv_usec)); } #if !HAVE_GMTIME_R @@ -12126,7 +12126,7 @@ static val string_time(struct tm *(*break_time_fn)(const time_t *, struct tm *), val time_string_local(val time, val format) { - time_t secs = c_num(time); + time_t secs = c_time(time); const wchar_t *wcfmt = c_str(format); char *u8fmt = utf8_dup_to(wcfmt); val timestr = string_time(localtime_r, u8fmt, secs); @@ -12136,7 +12136,7 @@ val time_string_local(val time, val format) val time_string_utc(val time, val format) { - time_t secs = c_num(time); + time_t secs = c_time(time); const wchar_t *wcfmt = c_str(format); char *u8fmt = utf8_dup_to(wcfmt); val timestr = string_time(gmtime_r, u8fmt, secs); @@ -12186,7 +12186,7 @@ static val broken_time_struct(struct tm *tms) val time_fields_local(val time) { struct tm tms; - time_t secs = c_num(time); + time_t secs = c_time(time); if (localtime_r(&secs, &tms) == 0) return nil; @@ -12197,7 +12197,7 @@ val time_fields_local(val time) val time_fields_utc(val time) { struct tm tms; - time_t secs = c_num(time); + time_t secs = c_time(time); if (gmtime_r(&secs, &tms) == 0) return nil; @@ -12208,7 +12208,7 @@ val time_fields_utc(val time) val time_struct_local(val time) { struct tm tms; - time_t secs = c_num(time); + time_t secs = c_time(time); if (localtime_r(&secs, &tms) == 0) return nil; @@ -12219,7 +12219,7 @@ val time_struct_local(val time) val time_struct_utc(val time) { struct tm tms; - time_t secs = c_num(time); + time_t secs = c_time(time); if (gmtime_r(&secs, &tms) == 0) return nil; @@ -12288,7 +12288,7 @@ static val make_time_impl(time_t (*pmktime)(struct tm *), hour, minute, second, isdst); time = pmktime(&local); - return time == -1 ? nil : num(time); + return time == -1 ? nil : num_time(time); } val make_time(val year, val month, val day, @@ -12458,9 +12458,9 @@ val time_parse_utc(val format, val string) if (!strptime_wrap(string, format, &tms)) return nil; #if HAVE_TIMEGM - return num(timegm(&tms)); + return num_time(timegm(&tms)); #else - return num(timegm_hack(&tms)); + return num_time(timegm_hack(&tms)); #endif } |