Improve 'last_write_time(...)' accuracy and detect overflow errors.
authorEric Fiselier <eric@efcs.ca>
Wed, 28 Sep 2016 21:16:58 +0000 (21:16 +0000)
committerEric Fiselier <eric@efcs.ca>
Wed, 28 Sep 2016 21:16:58 +0000 (21:16 +0000)
commit09cc08654a98e74868b4e00b561878c5deefa045
tree1fdc7cdc29437296dc41a6fc2b502e3d394e938c
parentcb85d7f840b1d2398fcbd1998c4f10755dfeb0bb
Improve 'last_write_time(...)' accuracy and detect overflow errors.

The ::stat struct on Linux, FreeBSD, and OS X  provides the access and
modification times as an instance of 'timespec', which has a nanosecond
resolution. The 'st_mtime' and 'st_atime' members simply reference the 'tv_sec'
value of the timespec struct. This patch changes 'last_write_time(...)' so that
it extracts both the seconds and nanoseconds values of the last modification
time, providing a more accurate implementation of 'last_write_time(...)'.

Additionally this patch fixes a possible signed integer overflow bug. The
'file_time_type' type cannot represent all possible values returned by
the filesystem. Attempting to construct a 'file_time_type' from one of these
values is undefined behavior. This patch avoids that UB by detecting possible
overflows before the conversion.

llvm-svn: 282634
libcxx/src/experimental/filesystem/operations.cpp