Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- ctime -----------------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CTIME |
| 11 | #define _LIBCPP_CTIME |
| 12 | |
| 13 | /* |
| 14 | ctime synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | NULL |
| 19 | CLOCKS_PER_SEC |
Marshall Clow | deb471f | 2018-07-31 19:25:00 | [diff] [blame] | 20 | TIME_UTC // C++17 |
Louis Dionne | 6b77ebd | 2019-10-23 17:40:15 | [diff] [blame] | 21 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 22 | namespace std |
| 23 | { |
| 24 | |
| 25 | Types: |
| 26 | |
| 27 | clock_t |
| 28 | size_t |
| 29 | time_t |
| 30 | tm |
Marshall Clow | deb471f | 2018-07-31 19:25:00 | [diff] [blame] | 31 | timespec // C++17 |
Louis Dionne | 6b77ebd | 2019-10-23 17:40:15 | [diff] [blame] | 32 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 33 | clock_t clock(); |
| 34 | double difftime(time_t time1, time_t time0); |
| 35 | time_t mktime(tm* timeptr); |
| 36 | time_t time(time_t* timer); |
| 37 | char* asctime(const tm* timeptr); |
| 38 | char* ctime(const time_t* timer); |
| 39 | tm* gmtime(const time_t* timer); |
| 40 | tm* localtime(const time_t* timer); |
| 41 | size_t strftime(char* restrict s, size_t maxsize, const char* restrict format, |
| 42 | const tm* restrict timeptr); |
Marshall Clow | deb471f | 2018-07-31 19:25:00 | [diff] [blame] | 43 | int timespec_get( struct timespec *ts, int base); // C++17 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 44 | } // std |
| 45 | |
| 46 | */ |
| 47 | |
| 48 | #include <__config> |
| 49 | #include <time.h> |
| 50 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 51 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 52 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 53 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 54 | |
Louis Dionne | 5201b96 | 2020-09-02 14:36:48 | [diff] [blame] | 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. |
Louis Dionne | 5571467 | 2020-09-02 22:11:26 | [diff] [blame] | 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 |
Louis Dionne | 5201b96 | 2020-09-02 14:36:48 | [diff] [blame] | 67 | #endif |
| 68 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 69 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 70 | |
| 71 | using ::clock_t; |
| 72 | using ::size_t; |
| 73 | using ::time_t; |
| 74 | using ::tm; |
Dan Albert | 19fd903 | 2019-11-18 20:16:45 | [diff] [blame] | 75 | #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) |
Marshall Clow | deb471f | 2018-07-31 19:25:00 | [diff] [blame] | 76 | using ::timespec; |
| 77 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 78 | using ::clock; |
| 79 | using ::difftime; |
| 80 | using ::mktime; |
| 81 | using ::time; |
Ed Schouten | e0cf3b9 | 2015-06-24 08:44:38 | [diff] [blame] | 82 | #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 83 | using ::asctime; |
| 84 | using ::ctime; |
| 85 | using ::gmtime; |
| 86 | using ::localtime; |
Ed Schouten | e0cf3b9 | 2015-06-24 08:44:38 | [diff] [blame] | 87 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 88 | using ::strftime; |
Louis Dionne | 5201b96 | 2020-09-02 14:36:48 | [diff] [blame] | 89 | #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED) |
Marshall Clow | deb471f | 2018-07-31 19:25:00 | [diff] [blame] | 90 | using ::timespec_get; |
| 91 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 92 | |
| 93 | _LIBCPP_END_NAMESPACE_STD |
| 94 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame^] | 95 | #endif // _LIBCPP_CTIME |