fixed return value of file-ctime and file-mtime (were incorrect due
to truncation)
This commit is contained in:
parent
fda6a1a2a6
commit
bc11d4f44f
|
@ -291,19 +291,23 @@
|
|||
(define ($file-time x who proc)
|
||||
(unless (string? x)
|
||||
(die who "not a string" x))
|
||||
(let ([p (cons #f #f)])
|
||||
(let ([v (proc (string->utf8 x) p)])
|
||||
(case v
|
||||
[(0) (+ (* (car p) #e1e9) (cdr p))]
|
||||
[else (raise/strerror who v x)]))))
|
||||
(let ([v (proc (string->utf8 x))])
|
||||
(cond
|
||||
[(bytevector? v)
|
||||
(let ([n0 (bytevector-u8-ref v 0)]
|
||||
[n1 (bytevector-u8-ref v 1)])
|
||||
(+ (* (bytevector-uint-ref v 2 (native-endianness) n0)
|
||||
#e1e9)
|
||||
(bytevector-uint-ref v (+ 2 n0) (native-endianness) n1)))]
|
||||
[else (raise/strerror who v x)])))
|
||||
|
||||
(define (file-ctime x)
|
||||
($file-time x 'file-ctime
|
||||
(lambda (u p) (foreign-call "ikrt_file_ctime" u p))))
|
||||
(lambda (u) (foreign-call "ikrt_file_ctime2" u))))
|
||||
|
||||
(define (file-mtime x)
|
||||
($file-time x 'file-mtime
|
||||
(lambda (u p) (foreign-call "ikrt_file_mtime" u p))))
|
||||
(lambda (u) (foreign-call "ikrt_file_mtime2" u))))
|
||||
|
||||
(define ($getenv-bv key)
|
||||
(foreign-call "ikrt_getenv" key))
|
||||
|
|
|
@ -285,6 +285,41 @@ ikrt_shutdown(ikptr s /*, ikpcb* pcb*/){
|
|||
}
|
||||
|
||||
|
||||
static ikptr
|
||||
timespec_bytevector(struct timespec* s, ikpcb* pcb) {
|
||||
int len = sizeof(struct timespec);
|
||||
ikptr r = ik_safe_alloc(pcb, align(disp_bytevector_data+len+3));
|
||||
ref(r, 0) = fix(len+2);
|
||||
*((char*)(r+disp_bytevector_data+0)) = sizeof(s->tv_sec);
|
||||
*((char*)(r+disp_bytevector_data+1)) = sizeof(s->tv_nsec);
|
||||
memcpy((char*)(r+disp_bytevector_data+2), s, len);
|
||||
*((char*)(r+disp_bytevector_data+len+2)) = 0;
|
||||
return r + bytevector_tag;
|
||||
}
|
||||
|
||||
ikptr
|
||||
ikrt_file_ctime2(ikptr filename, ikpcb* pcb){
|
||||
struct stat s;
|
||||
int err = stat((char*)(filename + off_bytevector_data), &s);
|
||||
if(err) {
|
||||
return ik_errno_to_code();
|
||||
}
|
||||
return timespec_bytevector(&s.st_ctimespec, pcb);
|
||||
}
|
||||
|
||||
ikptr
|
||||
ikrt_file_mtime2(ikptr filename, ikpcb* pcb){
|
||||
struct stat s;
|
||||
int err = stat((char*)(filename + off_bytevector_data), &s);
|
||||
if(err) {
|
||||
return ik_errno_to_code();
|
||||
}
|
||||
return timespec_bytevector(&s.st_mtimespec, pcb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ikptr
|
||||
ikrt_file_ctime(ikptr filename, ikptr res){
|
||||
struct stat s;
|
||||
|
|
Loading…
Reference in New Issue