Skip to content

Commit

Permalink
Fix fileModifiedTime on 32 bit systems
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edwinb committed Mar 6, 2020
1 parent 10fd4e7 commit bbd0f28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions libs/prelude/Prelude/File.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions rts/idris_stdfgn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion rts/idris_stdfgn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bbd0f28

Please sign in to comment.