[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / time / ctime.cpp
blob8adae9be73809af8b59952f2b17674bc09632e95
1 //===-- Implementation of ctime function ----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "ctime.h"
10 #include "src/__support/CPP/limits.h"
11 #include "src/__support/common.h"
12 #include "src/__support/macros/config.h"
13 #include "time_utils.h"
15 namespace LIBC_NAMESPACE_DECL {
17 using LIBC_NAMESPACE::time_utils::TimeConstants;
19 LLVM_LIBC_FUNCTION(char *, ctime, (const time_t *t_ptr)) {
20 if (t_ptr == nullptr || *t_ptr > cpp::numeric_limits<int32_t>::max()) {
21 return nullptr;
23 static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE];
24 return time_utils::asctime(time_utils::localtime(t_ptr), buffer,
25 TimeConstants::ASCTIME_MAX_BYTES);
28 } // namespace LIBC_NAMESPACE_DECL