mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-25 14:52:28 +00:00
Add more missing libc/libc++ functions
- Add sched_rr_get_interval() - Add `unbuffer` command example - Add more locale function stubs - Vendor most of remaining libcxx content
This commit is contained in:
parent
5a2bb07b36
commit
31e746c937
76 changed files with 15519 additions and 157 deletions
68
third_party/libcxx/chrono.cc
vendored
Normal file
68
third_party/libcxx/chrono.cc
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
// clang-format off
|
||||
//===------------------------- chrono.cpp ---------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "third_party/libcxx/chrono"
|
||||
#include "third_party/libcxx/cerrno" // errn"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "third_party/libcxx/system_error" // __throw_system_erro"
|
||||
|
||||
#define _LIBCPP_USE_CLOCK_GETTIME
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace chrono
|
||||
{
|
||||
|
||||
// system_clock
|
||||
|
||||
const bool system_clock::is_steady;
|
||||
|
||||
system_clock::time_point
|
||||
system_clock::now() _NOEXCEPT
|
||||
{
|
||||
struct timespec tp;
|
||||
if (0 != clock_gettime(CLOCK_REALTIME, &tp))
|
||||
__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
|
||||
return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
|
||||
}
|
||||
|
||||
time_t
|
||||
system_clock::to_time_t(const time_point& t) _NOEXCEPT
|
||||
{
|
||||
return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
|
||||
}
|
||||
|
||||
system_clock::time_point
|
||||
system_clock::from_time_t(time_t t) _NOEXCEPT
|
||||
{
|
||||
return system_clock::time_point(seconds(t));
|
||||
}
|
||||
|
||||
// steady_clock
|
||||
//
|
||||
// Warning: If this is not truly steady, then it is non-conforming. It is
|
||||
// better for it to not exist and have the rest of libc++ use system_clock
|
||||
// instead.
|
||||
|
||||
const bool steady_clock::is_steady;
|
||||
|
||||
steady_clock::time_point
|
||||
steady_clock::now() _NOEXCEPT
|
||||
{
|
||||
struct timespec tp;
|
||||
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
|
||||
__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
|
||||
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
|
||||
}
|
||||
|
||||
} // namespace chrono
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
Loading…
Add table
Add a link
Reference in a new issue