Index: libcxx/include/CMakeLists.txt =================================================================== --- libcxx/include/CMakeLists.txt +++ libcxx/include/CMakeLists.txt @@ -162,6 +162,13 @@ wctype.h ) +if (ZOS) + set(files + ${files} + support/ibm/nanosleep.h + ) +endif() + if(LIBCXX_INSTALL_SUPPORT_HEADERS) set(files ${files} Index: libcxx/include/__threading_support =================================================================== --- libcxx/include/__threading_support +++ libcxx/include/__threading_support @@ -15,6 +15,10 @@ #include #include +#ifdef __MVS__ +#include +#endif + #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #pragma GCC system_header #endif Index: libcxx/include/support/ibm/nanosleep.h =================================================================== --- /dev/null +++ libcxx/include/support/ibm/nanosleep.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ZOS_NANOSLEEP +#define _LIBCPP_ZOS_NANOSLEEP + +#include + +int nanosleep(const struct timespec* req, struct timespec* rem) +{ + // The nanosleep() function is not available on z/OS. Therefore, we will call + // sleep() to sleep for whole seconds and usleep() to sleep for any remaining + // fraction of a second. Any remaining nanoseconds will round up to the next + // microsecond. + + useconds_t __micro_sec = (rem->tv_nsec + 999) / 1000; + if (__micro_sec > 999999) + { + ++rem->tv_sec; + __micro_sec -= 1000000; + } + while (rem->tv_sec) + rem->tv_sec = sleep(rem->tv_sec); + if (__micro_sec) { + rem->tv_nsec = __micro_sec * 1000; + return usleep(__micro_sec); + } + rem->tv_nsec = 0; + return 0; +} + +#endif // _LIBCPP_ZOS_NANOSLEEP Index: libcxx/src/filesystem/filesystem_common.h =================================================================== --- libcxx/src/filesystem/filesystem_common.h +++ libcxx/src/filesystem/filesystem_common.h @@ -198,6 +198,7 @@ using chrono::duration_cast; using TimeSpec = struct ::timespec; +using TimeVal = struct ::timeval; using StatT = struct ::stat; template const& TS, - error_code& ec) { +TimeVal make_timeval(TimeSpec const& ts) { using namespace chrono; auto Convert = [](long nsec) { - using int_type = decltype(std::declval< ::timeval>().tv_usec); + using int_type = decltype(std::declval().tv_usec); auto dur = duration_cast(nanoseconds(nsec)).count(); return static_cast(dur); }; - struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)}, - {TS[1].tv_sec, Convert(TS[1].tv_nsec)}}; + TimeVal TV = {}; + TV.tv_sec = ts.tv_sec; + TV.tv_usec = Convert(ts.tv_nsec); + return TV; +} + +bool posix_utimes(const path& p, std::array const& TS, + error_code& ec) { + TimeVal ConvertedTS[2] = {make_timeval(TS[0]), make_timeval(TS[1])}; if (::utimes(p.c_str(), ConvertedTS) == -1) { ec = capture_errno(); return true;