Mercurial > octave
comparison liboctave/system/oct-time.cc @ 32090:7d663f770c5a
load-path: Avoid using file_stat on Windows (bug #59711).
* liboctave/system/oct-time.h, oct-time.cc (octave::sys::file_time): New class
to handle an efficient native file time type per platform.
* libinterp/corefcn/load-path.h (load_path::dir_info::dir_mtime,
load_path::dir_info::dir_time_last_checked): Change type to new class.
* libinterp/corefcn/load-path.cc (subdirs_modified, load_path::dir_info::update,
load_path::dir_info::initialize): Avoid using file_stat on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 13 May 2023 13:33:57 +0200 |
parents | 21f9b34eb893 |
children | 53e15e754725 |
comparison
equal
deleted
inserted
replaced
32089:212145b8e5f0 | 32090:7d663f770c5a |
---|---|
34 #include <limits> | 34 #include <limits> |
35 #include <ostream> | 35 #include <ostream> |
36 | 36 |
37 #if defined (OCTAVE_USE_WINDOWS_API) | 37 #if defined (OCTAVE_USE_WINDOWS_API) |
38 # include <windows.h> | 38 # include <windows.h> |
39 #else | |
40 # include "file-stat.h" | |
39 #endif | 41 #endif |
40 | 42 |
41 #include "lo-error.h" | 43 #include "lo-error.h" |
42 #include "lo-utils.h" | 44 #include "lo-utils.h" |
43 #include "lo-sysdep.h" | 45 #include "lo-sysdep.h" |
368 &m_nsignals, &m_nvcsw, &m_nivcsw); | 370 &m_nsignals, &m_nvcsw, &m_nivcsw); |
369 | 371 |
370 m_cpu = cpu_time (usr_sec, sys_sec, usr_usec, sys_usec); | 372 m_cpu = cpu_time (usr_sec, sys_sec, usr_usec, sys_usec); |
371 } | 373 } |
372 | 374 |
375 file_time::file_time () | |
376 { | |
377 #if defined (OCTAVE_USE_WINDOWS_API) | |
378 FILETIME curr_file_time; | |
379 GetSystemTimeAsFileTime (&curr_file_time); | |
380 m_time | |
381 = (static_cast<OCTAVE_TIME_T> (curr_file_time.dwHighDateTime)) >> 32 | |
382 | curr_file_time.dwLowDateTime; | |
383 #else | |
384 time_t ot_unix_time; | |
385 time_t ot_usec; | |
386 octave_gettimeofday_wrapper (&ot_unix_time, &ot_usec); | |
387 // Discard usec. We are assuming a 1 second resolution anyway. | |
388 m_time = ot_unix_time; | |
389 #endif | |
390 } | |
391 | |
392 file_time::file_time (const std::string& filename) | |
393 { | |
394 #if defined (OCTAVE_USE_WINDOWS_API) | |
395 std::wstring wfull_name = sys::u8_to_wstring (filename); | |
396 HANDLE h_file | |
397 = CreateFile (wfull_name.c_str (), GENERIC_READ, | |
398 FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, | |
399 nullptr); | |
400 FILETIME last_access_time; | |
401 GetFileTime (h_file, nullptr, &last_access_time, nullptr); | |
402 | |
403 m_time | |
404 = (static_cast<OCTAVE_TIME_T> (last_access_time.dwHighDateTime)) >> 32 | |
405 | last_access_time.dwLowDateTime; | |
406 #else | |
407 file_stat fs = file_stat (filename); | |
408 m_time = fs.mtime ().unix_time (); | |
409 #endif | |
410 } | |
411 | |
373 OCTAVE_END_NAMESPACE(sys) | 412 OCTAVE_END_NAMESPACE(sys) |
374 OCTAVE_END_NAMESPACE(octave) | 413 OCTAVE_END_NAMESPACE(octave) |