diff options
author | 2017-10-17 15:18:57 -0400 | |
---|---|---|
committer | 2017-10-17 21:18:57 +0200 | |
commit | 86f50b0d65e78f71d046218ffe7833271023d8c8 (patch) | |
tree | d16ad18dd925dcd16c3750b44291b877afc7a0a1 /src/tools/imgtool/modules/macutil.cpp | |
parent | 78c658c7a2bb2ee9e3f721dad292cb951d8f30ad (diff) |
Created a more flexible imgtool::datetime structure for use within Imgtool (#2263)
* Created a more flexible imgtool::datetime structure for use within Imgtool
This is intended to replace most usage of time_t
* Changing the granularity of imgtool_clock from 1ms to 100ns, as per Vas' suggestion
* Created arbitrary_datetime in timeconv.h to facilitate interpretation of datetime info
I concluded that invoking std::mktime on manually assembled std::tm is bad, because it is indeterminate how the std::tm members may be "dominant". This required that I go further in imgtool, and update a number of drivers and eliminate the parameter of imgtool::datetime that takes std::tm.
Diffstat (limited to 'src/tools/imgtool/modules/macutil.cpp')
-rw-r--r-- | src/tools/imgtool/modules/macutil.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/tools/imgtool/modules/macutil.cpp b/src/tools/imgtool/modules/macutil.cpp index 1bab14487cd..08c8b84989f 100644 --- a/src/tools/imgtool/modules/macutil.cpp +++ b/src/tools/imgtool/modules/macutil.cpp @@ -15,32 +15,54 @@ typedef util::arbitrary_clock<std::uint32_t, 1904, 1, 1, 0, 0, 0, std::ratio<1, 1> > classic_mac_clock; -time_t mac_crack_time(uint32_t t) +//------------------------------------------------- +// mac_crack_time +//------------------------------------------------- + +imgtool::datetime mac_crack_time(uint32_t t) { classic_mac_clock::duration d(t); - std::chrono::time_point<std::chrono::system_clock> tp = classic_mac_clock::to_system_clock(std::chrono::time_point<classic_mac_clock>(d)); - return std::chrono::system_clock::to_time_t(tp); + std::chrono::time_point<classic_mac_clock> tp(d); + return imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, tp); } +//------------------------------------------------- +// mac_setup_time +//------------------------------------------------- -uint32_t mac_setup_time(time_t t) +uint32_t mac_setup_time(const imgtool::datetime &t) { - auto system_time_point = std::chrono::system_clock::from_time_t(t); - auto mac_time_point = classic_mac_clock::from_system_clock(system_time_point); + auto mac_time_point = classic_mac_clock::from_arbitrary_time_point(t.time_point()); return mac_time_point.time_since_epoch().count(); } +//------------------------------------------------- +// mac_setup_time +//------------------------------------------------- + +uint32_t mac_setup_time(time_t t) +{ + imgtool::datetime dt(imgtool::datetime::datetime_type::LOCAL, t); + return mac_setup_time(dt); +} + + +//------------------------------------------------- +// mac_time_now +//------------------------------------------------- uint32_t mac_time_now(void) { - time_t now; - time(&now); - return mac_setup_time(now); + imgtool::datetime dt = imgtool::datetime::now(imgtool::datetime::datetime_type::LOCAL); + return mac_setup_time(dt); } +//------------------------------------------------- +// mac_identify_fork +//------------------------------------------------- imgtoolerr_t mac_identify_fork(const char *fork_string, mac_fork_t *fork_num) { |