Created
February 26, 2021 17:54
-
-
Save ba0f3/f3523c095697a3607abc0579b988c14a to your computer and use it in GitHub Desktop.
Get FILETIME and convert posix time to windows FILENAME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const EPOCH_DIFF = 11644473600'i64 | |
type FILETIME = object | |
dwLowDateTime: uint32 | |
dwHighDateTime: uint32 | |
proc toFileTime(tv: Timeval): FILETIME = | |
var mtime = EPOCH_DIFF + tv.tv_sec.int64 | |
mtime = mtime + tv.tv_usec * 10; | |
mtime = mtime * 10_000_000 | |
result = cast[FILETIME](mtime) | |
proc getLastWriteTime(file: string): FILETIME = | |
var | |
res: Stat | |
tv: Timeval | |
if stat(filename, res) < 0'i32: raiseOSError(osLastError(), file) | |
tv.tv_sec = res.st_mtime | |
result = toFileTime(tv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment