Changeset View
Changeset View
Standalone View
Standalone View
contrib/libc++/src/experimental/filesystem/operations.cpp
Show First 20 Lines • Show All 542 Lines • ▼ Show 20 Lines | |||||
// Static assert that these values properly round trip. | // Static assert that these values properly round trip. | ||||
static_assert((seconds(min_seconds) + duration_cast<microseconds>(nanoseconds(min_nsec_timespec))) | static_assert((seconds(min_seconds) + duration_cast<microseconds>(nanoseconds(min_nsec_timespec))) | ||||
- duration_cast<microseconds>(seconds(1)) | - duration_cast<microseconds>(seconds(1)) | ||||
== file_time_type::duration::min(), ""); | == file_time_type::duration::min(), ""); | ||||
constexpr auto max_time_t = numeric_limits<time_t>::max(); | constexpr auto max_time_t = numeric_limits<time_t>::max(); | ||||
constexpr auto min_time_t = numeric_limits<time_t>::min(); | constexpr auto min_time_t = numeric_limits<time_t>::min(); | ||||
#if !defined(__LP64__) && defined(__clang__) | #if !defined(TIME_T_64BIT) && defined(__clang__) | ||||
#pragma clang diagnostic push | #pragma clang diagnostic push | ||||
#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" | #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" | ||||
#endif | #endif | ||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 | _LIBCPP_CONSTEXPR_AFTER_CXX11 | ||||
bool is_representable(TimeSpec const& tm) { | bool is_representable(TimeSpec const& tm) { | ||||
if (tm.tv_sec >= 0) { | if (tm.tv_sec >= 0) { | ||||
return (tm.tv_sec < max_seconds) || | return (tm.tv_sec < max_seconds) || | ||||
(tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec); | (tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec); | ||||
} else if (tm.tv_sec == (min_seconds - 1)) { | } else if (tm.tv_sec == (min_seconds - 1)) { | ||||
return tm.tv_nsec >= min_nsec_timespec; | return tm.tv_nsec >= min_nsec_timespec; | ||||
} else { | } else { | ||||
return (tm.tv_sec >= min_seconds); | return (tm.tv_sec >= min_seconds); | ||||
} | } | ||||
} | } | ||||
#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | #ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | ||||
#if defined(__LP64__) | #if defined(TIME_T_64BIT) | ||||
static_assert(is_representable({max_seconds, max_nsec}), ""); | static_assert(is_representable({max_seconds, max_nsec}), ""); | ||||
static_assert(!is_representable({max_seconds + 1, 0}), ""); | static_assert(!is_representable({max_seconds + 1, 0}), ""); | ||||
static_assert(!is_representable({max_seconds, max_nsec + 1}), ""); | static_assert(!is_representable({max_seconds, max_nsec + 1}), ""); | ||||
static_assert(!is_representable({max_time_t, 0}), ""); | static_assert(!is_representable({max_time_t, 0}), ""); | ||||
static_assert(is_representable({min_seconds, 0}), ""); | static_assert(is_representable({min_seconds, 0}), ""); | ||||
static_assert(is_representable({min_seconds - 1, min_nsec_timespec}), ""); | static_assert(is_representable({min_seconds - 1, min_nsec_timespec}), ""); | ||||
static_assert(is_representable({min_seconds - 1, min_nsec_timespec + 1}), ""); | static_assert(is_representable({min_seconds - 1, min_nsec_timespec + 1}), ""); | ||||
static_assert(!is_representable({min_seconds - 1, min_nsec_timespec - 1}), ""); | static_assert(!is_representable({min_seconds - 1, min_nsec_timespec - 1}), ""); | ||||
Show All 14 Lines | if (nsecs.count() < 0) { | ||||
nsecs = nsecs + seconds(1); | nsecs = nsecs + seconds(1); | ||||
} | } | ||||
using TLim = numeric_limits<time_t>; | using TLim = numeric_limits<time_t>; | ||||
if (secs.count() >= 0) | if (secs.count() >= 0) | ||||
return secs.count() <= TLim::max(); | return secs.count() <= TLim::max(); | ||||
return secs.count() >= TLim::min(); | return secs.count() >= TLim::min(); | ||||
} | } | ||||
#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | #ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | ||||
#if defined(__LP64__) | #if defined(TIME_T_64BIT) | ||||
static_assert(is_representable(file_time_type::max()), ""); | static_assert(is_representable(file_time_type::max()), ""); | ||||
static_assert(is_representable(file_time_type::min()), ""); | static_assert(is_representable(file_time_type::min()), ""); | ||||
#else | #else | ||||
static_assert(!is_representable(file_time_type::max()), ""); | static_assert(!is_representable(file_time_type::max()), ""); | ||||
static_assert(!is_representable(file_time_type::min()), ""); | static_assert(!is_representable(file_time_type::min()), ""); | ||||
static_assert(is_representable(file_time_type(seconds(max_time_t))), ""); | static_assert(is_representable(file_time_type(seconds(max_time_t))), ""); | ||||
static_assert(is_representable(file_time_type(seconds(min_time_t))), ""); | static_assert(is_representable(file_time_type(seconds(min_time_t))), ""); | ||||
#endif | #endif | ||||
Show All 9 Lines | if (tm.tv_sec >= 0) { | ||||
return file_time_type(seconds(tm.tv_sec)); | return file_time_type(seconds(tm.tv_sec)); | ||||
} else { // tm.tv_sec < 0 | } else { // tm.tv_sec < 0 | ||||
auto adj_subsec = duration_cast<microseconds>(seconds(1) - nanoseconds(tm.tv_nsec)); | auto adj_subsec = duration_cast<microseconds>(seconds(1) - nanoseconds(tm.tv_nsec)); | ||||
auto Dur = seconds(tm.tv_sec + 1) - adj_subsec; | auto Dur = seconds(tm.tv_sec + 1) - adj_subsec; | ||||
return file_time_type(Dur); | return file_time_type(Dur); | ||||
} | } | ||||
} | } | ||||
#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | #ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR | ||||
#if defined(__LP64__) | #if defined(TIME_T_64BIT) | ||||
static_assert(convert_timespec({max_seconds, max_nsec}) == file_time_type::max(), ""); | static_assert(convert_timespec({max_seconds, max_nsec}) == file_time_type::max(), ""); | ||||
static_assert(convert_timespec({max_seconds, max_nsec - 1}) < file_time_type::max(), ""); | static_assert(convert_timespec({max_seconds, max_nsec - 1}) < file_time_type::max(), ""); | ||||
static_assert(convert_timespec({max_seconds - 1, 999999999}) < file_time_type::max(), ""); | static_assert(convert_timespec({max_seconds - 1, 999999999}) < file_time_type::max(), ""); | ||||
static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec}) == file_time_type::min(), ""); | static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec}) == file_time_type::min(), ""); | ||||
static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec + 1}) > file_time_type::min(), ""); | static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec + 1}) > file_time_type::min(), ""); | ||||
static_assert(convert_timespec({min_seconds , 0}) > file_time_type::min(), ""); | static_assert(convert_timespec({min_seconds , 0}) > file_time_type::min(), ""); | ||||
#else | #else | ||||
// FIXME add tests for 32 bit builds | // FIXME add tests for 32 bit builds | ||||
#endif | #endif | ||||
#endif | #endif | ||||
#if !defined(__LP64__) && defined(__clang__) | #if !defined(TIME_T_64BIT) && defined(__clang__) | ||||
#pragma clang diagnostic pop | #pragma clang diagnostic pop | ||||
#endif | #endif | ||||
template <class SubSecDurT, class SubSecT> | template <class SubSecDurT, class SubSecT> | ||||
bool set_times_checked(time_t* sec_out, SubSecT* subsec_out, file_time_type tp) { | bool set_times_checked(time_t* sec_out, SubSecT* subsec_out, file_time_type tp) { | ||||
using namespace chrono; | using namespace chrono; | ||||
auto dur = tp.time_since_epoch(); | auto dur = tp.time_since_epoch(); | ||||
auto sec_dur = duration_cast<seconds>(dur); | auto sec_dur = duration_cast<seconds>(dur); | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |