C++ last_write_time compared to Python

Viewed 118

I am porting a line of Python to c++ that deals with looking at file modified times. Because only later versions of C++ have the support for filesystem, I thought I would use boost and for legacy compatibility reasons I am using I am using Boost 1.64 filesystem. My port of os.path.getmtime is boost::filesystem::last_write_time. Python returns a fractional value while the implementation-dependent last_write_time returns a whole number in OSX 10.14.6 XCode 11.0.

The code is:

def GetModifiedTime(fileName):
    return os.path.getmtime(fileName)

and returns 1597265166.4072416 while the c++ code is

#include "boost/filesystem.hpp"

int main(int argc, char *argv[])
{
    boost::filesystem::path p = argv[0];
    auto v = boost::filesystem::last_write_time(p);    
    return 0;
}

and returns 1597265166.0.

I would like these two return values to match.

My belief is that the boost::filesystem will be largely compatible with std::filesystem. The last_write_time function

Returns: The time of last data modification of p, determined as if by the value of the ISO/IEC 9945 stat structure member st_mtime obtained as if by ISO/IEC 9945 stat().

in an std::time_t structure where the link says:

Arithmetic type capable of representing times. Although not defined, this is almost always an integral value holding the number of seconds (not counting leap seconds) since 00:00, Jan 1 1970 UTC, corresponding to POSIX time.

Which is unfortunate because I would like those fractional seconds back. Is last_write_time simply the wrong thing to use?

0 Answers
Related