summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-04-22 19:18:15 -0700
committerMichael Pavone <pavone@retrodev.com>2016-04-22 19:18:15 -0700
commit2105a52a24e24b1b34cf397cb76b9df30f94d1b2 (patch)
treebda46bf0174828d8214ebd4c341a04d3cf6242c0
parent9260a65a70b5d67a12b4c70a0e616f75711971dd (diff)
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
-rw-r--r--util.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/util.c b/util.c
index c0506ce..5ee8b51 100644
--- a/util.c
+++ b/util.c
@@ -286,23 +286,19 @@ dir_entry *get_dir_list(char *path, size_t *numret)
time_t get_modification_time(char *path)
{
- HANDLE file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- if (file == INVALID_HANDLE_VALUE) {
- return 0;
- }
- FILETIME ft;
- uint8_t ret = GetFileTime(file, NULL, NULL, &ft);
- CloseHandle(file);
- if (ret) {
- uint64_t wintime = ((uint64_t)ft.dwHighDateTime) << 32 | ft.dwLowDateTime;
- //convert to seconds
- wintime /= 10000000;
- //adjust for difference between Windows and Unix Epoch
- wintime -= 11644473600LL;
- return (time_t)wintime;
- } else {
+ HANDLE results;
+ WIN32_FIND_DATA file;
+ results = FindFirstFile(path, &file);
+ if (results == INVALID_HANDLE_VALUE) {
return 0;
}
+ FindClose(results);
+ uint64_t wintime = ((uint64_t)file.ftLastWriteTime.dwHighDateTime) << 32 | file.ftLastWriteTime.dwLowDateTime;
+ //convert to seconds
+ wintime /= 10000000;
+ //adjust for difference between Windows and Unix Epoch
+ wintime -= 11644473600LL;
+ return (time_t)wintime;
}
int ensure_dir_exists(char *path)