Fix fileModifiedTime on 32 bit systems

Can't use MKBIGI for the result, since that'll be a negative number for
the current time! So use MKBIGUI instead to ensure it stays unsigned.
This commit is contained in:
Edwin Brady 2020-03-06 09:12:24 +00:00
parent 10fd4e71f8
commit bbd0f286c2
3 changed files with 6 additions and 5 deletions

View File

@ -150,7 +150,8 @@ do_getFileAccessTime h =
private
do_getFileModifiedTime : Ptr -> IO Integer
do_getFileModifiedTime h =
do MkRaw i <- foreign FFI_C "fileModifiedTime" (Ptr -> IO (Raw Integer)) h
do vm <- getMyVM
MkRaw i <- foreign FFI_C "fileModifiedTime" (Ptr -> Ptr -> IO (Raw Integer)) vm h
pure i
private
@ -175,7 +176,7 @@ export
fileModifiedTime : File -> IO (Either FileError Integer)
fileModifiedTime (FHandle h)
= do s <- do_getFileModifiedTime h
if (s < 0)
if (s == -1)
then Left <$> getFileError
else pure (Right s)

View File

@ -74,13 +74,13 @@ VAL fileAccessTime(void* h) {
}
}
VAL fileModifiedTime(void* h) {
VAL fileModifiedTime(VM* vm, void* h) {
FILE* f = (FILE*)h;
int fd = fileno(f);
struct stat buf;
if (fstat(fd, &buf) == 0) {
return MKBIGI(buf.st_mtime);
return MKBIGUI(vm, buf.st_mtime);
} else {
return MKBIGI(-1);
}

View File

@ -18,7 +18,7 @@ int fileSize(void* h);
// Return a negative number if not a file (e.g. directory or device)
VAL fileAccessTime(void* h);
VAL fileModifiedTime(void* h);
VAL fileModifiedTime(VM* vm, void* h);
VAL fileStatusTime(void* h);
void* idris_dirOpen(char* dname);