9 #define WINDOWS_TICK 10000000
10 #define SEC_TO_UNIX_EPOCH 11644473600LL
13 #include "system/stacktrace.h"
16 int last_modified(const char *filepath, time_t *time)
18 trace_assert(filepath);
24 if (stat(filepath, &attr) < 0) {
25 // errno is set by stat
28 *time = attr.st_mtime;
33 // CreateFile opens file (see flag OPEN_EXISTING)
34 HANDLE hFile = CreateFile(
37 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
43 if (hFile == INVALID_HANDLE_VALUE) {
44 // TODO(#900): convert GetLastError() to errno
45 // for now let's just assume that file was not found.
49 FILETIME filetime = { 0 };
50 BOOL res = GetFileTime(hFile, NULL, NULL, &filetime);
56 unsigned long long mod_time = filetime.dwHighDateTime;
58 mod_time |= filetime.dwLowDateTime;
59 // Taken from https://stackoverflow.com/a/6161842/1901561
60 *time = mod_time / WINDOWS_TICK - SEC_TO_UNIX_EPOCH;
63 #elif defined(__APPLE__)
65 // TODO(#901): implement last_modified for Mac OS X
66 #warning last_modified is not implemented