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 /sysif.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 'sysif.c')
-rw-r--r-- | sysif.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -778,6 +778,16 @@ static int w_fstat(val stream, struct stat *buf) } #endif +time_t c_time(val time) +{ + return if3(convert(time_t, -1) > 0, c_unum(time), c_num(time)); +} + +val num_time(time_t time) +{ + return if3(convert(time_t, -1) > 0, unum(time), num(time)); +} + #if HAVE_SYS_STAT static val stat_to_list(struct stat st) { @@ -821,9 +831,9 @@ val stat_to_struct(struct stat st, val path) slotset(strct, blksize_s, zero); slotset(strct, blocks_s, zero); #endif - slotset(strct, atime_s, num(st.st_atime)); - slotset(strct, mtime_s, num(st.st_mtime)); - slotset(strct, ctime_s, num(st.st_ctime)); + slotset(strct, atime_s, num_time(st.st_atime)); + slotset(strct, mtime_s, num_time(st.st_mtime)); + slotset(strct, ctime_s, num_time(st.st_ctime)); #if HAVE_STAT_NSEC slotset(strct, atime_nsec_s, num(st.st_atim.tv_nsec)); slotset(strct, mtime_nsec_s, num(st.st_mtim.tv_nsec)); |