1// -*- C++ -*-
2//===---------------------------- ctime -----------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CTIME
11#define _LIBCPP_CTIME
12
13/*
14    ctime synopsis
15
16Macros:
17
18    NULL
19    CLOCKS_PER_SEC
20    TIME_UTC // C++17
21
22namespace std
23{
24
25Types:
26
27    clock_t
28    size_t
29    time_t
30    tm
31    timespec // C++17
32
33clock_t clock();
34double difftime(time_t time1, time_t time0);
35time_t mktime(tm* timeptr);
36time_t time(time_t* timer);
37char* asctime(const tm* timeptr);
38char* ctime(const time_t* timer);
39tm*    gmtime(const time_t* timer);
40tm* localtime(const time_t* timer);
41size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
42                const tm* restrict timeptr);
43int timespec_get( struct timespec *ts, int base); // C++17
44}  // std
45
46*/
47
48#include <__config>
49#include <time.h>
50
51#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52#pragma GCC system_header
53#endif
54
55// FIXME:
56// Apple SDKs don't define ::timespec_get unconditionally in C++ mode. This
57// should be fixed in future SDKs, but for the time being we need to avoid
58// trying to use that declaration when the SDK doesn't provide it. Note that
59// we're detecting this here instead of in <__config> because we can't include
60// system headers from <__config>, since it leads to circular module dependencies.
61// This is also meant to be a very temporary workaround until the SDKs are fixed.
62#if defined(__APPLE__)
63#   include <sys/cdefs.h>
64#   if defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
65#       define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED
66#   endif
67#endif
68
69_LIBCPP_BEGIN_NAMESPACE_STD
70
71using ::clock_t;
72using ::size_t;
73using ::time_t;
74using ::tm;
75#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
76using ::timespec;
77#endif
78using ::clock;
79using ::difftime;
80using ::mktime;
81using ::time;
82#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
83using ::asctime;
84using ::ctime;
85using ::gmtime;
86using ::localtime;
87#endif
88using ::strftime;
89#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
90using ::timespec_get;
91#endif
92
93_LIBCPP_END_NAMESPACE_STD
94
95#endif  // _LIBCPP_CTIME
96