File indexing completed on 2026-05-03 08:13:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
0011 #define _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
0012
0013 #include <__chrono/duration.h>
0014 #include <__config>
0015 #include <limits>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 _LIBCPP_PUSH_MACROS
0022 #include <__undef_macros>
0023
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025
0026
0027
0028 template <class _TimeSpec>
0029 _LIBCPP_HIDE_FROM_ABI inline _TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns) {
0030 using namespace chrono;
0031 seconds __s = duration_cast<seconds>(__ns);
0032 _TimeSpec __ts;
0033 typedef decltype(__ts.tv_sec) __ts_sec;
0034 const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
0035
0036 if (__s.count() < __ts_sec_max) {
0037 __ts.tv_sec = static_cast<__ts_sec>(__s.count());
0038 __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
0039 } else {
0040 __ts.tv_sec = __ts_sec_max;
0041 __ts.tv_nsec = 999999999;
0042 }
0043
0044 return __ts;
0045 }
0046
0047 _LIBCPP_END_NAMESPACE_STD
0048
0049 _LIBCPP_POP_MACROS
0050
0051 #endif