tst: memfs-fuse3: accurately compute current time

This commit is contained in:
Bill Zissimopoulos 2019-10-09 11:39:41 -07:00
parent b04266e0fe
commit 79be3e445a
No known key found for this signature in database
GPG Key ID: 3D4F95D52C7B3EA3

View File

@ -20,8 +20,8 @@
*/
#include <cerrno>
#include <chrono>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <memory>
#include <mutex>
@ -124,8 +124,12 @@ private:
static fuse_timespec now()
{
fuse_timespec ts = { static_cast<decltype(ts.tv_sec)>(std::time(0)) };
return ts;
using namespace std::chrono;
auto now = system_clock::now();
auto sec = floor<seconds>(now);
auto nsec = floor<nanoseconds>(now) - floor<nanoseconds>(sec);
return fuse_timespec{ sec.time_since_epoch().count(), nsec.count() };
/* std::chrono epoch is UNIX epoch in C++20 */
}
static memfs *getself()