ctime 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  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. #ifndef _LIBCPP_CTIME
  10. #define _LIBCPP_CTIME
  11. /*
  12. ctime synopsis
  13. Macros:
  14. NULL
  15. CLOCKS_PER_SEC
  16. TIME_UTC // C++17
  17. namespace std
  18. {
  19. Types:
  20. clock_t
  21. size_t
  22. time_t
  23. tm
  24. timespec // C++17
  25. clock_t clock();
  26. double difftime(time_t time1, time_t time0);
  27. time_t mktime(tm* timeptr);
  28. time_t time(time_t* timer);
  29. char* asctime(const tm* timeptr);
  30. char* ctime(const time_t* timer);
  31. tm* gmtime(const time_t* timer);
  32. tm* localtime(const time_t* timer);
  33. size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
  34. const tm* restrict timeptr);
  35. int timespec_get( struct timespec *ts, int base); // C++17
  36. } // std
  37. */
  38. #include <__config>
  39. #include <time.h>
  40. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  41. # pragma GCC system_header
  42. #endif
  43. // FIXME:
  44. // Apple SDKs don't define ::timespec_get unconditionally in C++ mode. This
  45. // should be fixed in future SDKs, but for the time being we need to avoid
  46. // trying to use that declaration when the SDK doesn't provide it. Note that
  47. // we're detecting this here instead of in <__config> because we can't include
  48. // system headers from <__config>, since it leads to circular module dependencies.
  49. // This is also meant to be a very temporary workaround until the SDKs are fixed.
  50. #if defined(__APPLE__) && !__has_attribute(using_if_exists)
  51. # include <sys/cdefs.h>
  52. # if defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
  53. # define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED
  54. # endif
  55. #endif
  56. _LIBCPP_BEGIN_NAMESPACE_STD
  57. using ::clock_t _LIBCPP_USING_IF_EXISTS;
  58. using ::size_t _LIBCPP_USING_IF_EXISTS;
  59. using ::time_t _LIBCPP_USING_IF_EXISTS;
  60. using ::tm _LIBCPP_USING_IF_EXISTS;
  61. #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
  62. using ::timespec _LIBCPP_USING_IF_EXISTS;
  63. #endif
  64. using ::clock _LIBCPP_USING_IF_EXISTS;
  65. using ::difftime _LIBCPP_USING_IF_EXISTS;
  66. using ::mktime _LIBCPP_USING_IF_EXISTS;
  67. using ::time _LIBCPP_USING_IF_EXISTS;
  68. using ::asctime _LIBCPP_USING_IF_EXISTS;
  69. using ::ctime _LIBCPP_USING_IF_EXISTS;
  70. using ::gmtime _LIBCPP_USING_IF_EXISTS;
  71. using ::localtime _LIBCPP_USING_IF_EXISTS;
  72. using ::strftime _LIBCPP_USING_IF_EXISTS;
  73. #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
  74. using ::timespec_get _LIBCPP_USING_IF_EXISTS;
  75. #endif
  76. _LIBCPP_END_NAMESPACE_STD
  77. #endif // _LIBCPP_CTIME