Mercurial > repos > blastem
comparison util.c @ 974:fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 22 Apr 2016 19:18:15 -0700 |
parents | 4899d3ae37b3 |
children | 51885857c019 |
comparison
equal
deleted
inserted
replaced
973:fbd783ccbadb | 974:fd7702bcc034 |
---|---|
284 return ret; | 284 return ret; |
285 } | 285 } |
286 | 286 |
287 time_t get_modification_time(char *path) | 287 time_t get_modification_time(char *path) |
288 { | 288 { |
289 HANDLE file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); | 289 HANDLE results; |
290 if (file == INVALID_HANDLE_VALUE) { | 290 WIN32_FIND_DATA file; |
291 results = FindFirstFile(path, &file); | |
292 if (results == INVALID_HANDLE_VALUE) { | |
291 return 0; | 293 return 0; |
292 } | 294 } |
293 FILETIME ft; | 295 FindClose(results); |
294 uint8_t ret = GetFileTime(file, NULL, NULL, &ft); | 296 uint64_t wintime = ((uint64_t)file.ftLastWriteTime.dwHighDateTime) << 32 | file.ftLastWriteTime.dwLowDateTime; |
295 CloseHandle(file); | 297 //convert to seconds |
296 if (ret) { | 298 wintime /= 10000000; |
297 uint64_t wintime = ((uint64_t)ft.dwHighDateTime) << 32 | ft.dwLowDateTime; | 299 //adjust for difference between Windows and Unix Epoch |
298 //convert to seconds | 300 wintime -= 11644473600LL; |
299 wintime /= 10000000; | 301 return (time_t)wintime; |
300 //adjust for difference between Windows and Unix Epoch | |
301 wintime -= 11644473600LL; | |
302 return (time_t)wintime; | |
303 } else { | |
304 return 0; | |
305 } | |
306 } | 302 } |
307 | 303 |
308 int ensure_dir_exists(char *path) | 304 int ensure_dir_exists(char *path) |
309 { | 305 { |
310 if (CreateDirectory(path, NULL)) { | 306 if (CreateDirectory(path, NULL)) { |