File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ // ===-- Implementation of ctime_s 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+ // ===----------------------------------------------------------------------===//
8+
9+ #include " ctime_s.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"
14+ #include < cerrno>
15+
16+ namespace LIBC_NAMESPACE_DECL {
17+
18+ using LIBC_NAMESPACE::time_utils::TimeConstants;
19+
20+ LLVM_LIBC_FUNCTION (int , ctime_s,
21+ (char *buffer, size_t buffer_size, const time_t *t_ptr)) {
22+ if (t_ptr == nullptr || buffer == nullptr ||
23+ *time > cpp::numeric_limits<int32_t >::max ()) {
24+ return EINVAL;
25+ }
26+
27+ if (buffer_size < TimeConstants::ASCTIME_MAX_BYTES) {
28+ return ERANGE;
29+ }
30+
31+ if (time_utils::asctime (time_utils::localtime (t_ptr), buffer, buffer_size) ==
32+ nullptr ) {
33+ return EINVAL;
34+ }
35+
36+ return 0 ;
37+ }
38+
39+ } // namespace LIBC_NAMESPACE_DECL
Original file line number Diff line number Diff line change 1+ // ===-- Implementation header of ctime_s ------------------------*- C++ -*-===//
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+ // ===----------------------------------------------------------------------===//
8+
9+ #ifndef LLVM_LIBC_SRC_TIME_CTIME_S_H
10+ #define LLVM_LIBC_SRC_TIME_CTIME_S_H
11+
12+ #include " hdr/types/time_t.h"
13+ #include " src/__support/macros/config.h"
14+
15+ namespace LIBC_NAMESPACE_DECL {
16+
17+ int ctime_s (char *buffer, size_t buffer_size, const time_t *t_ptr);
18+
19+ } // namespace LIBC_NAMESPACE_DECL
20+
21+ #endif // LLVM_LIBC_SRC_TIME_CTIME_S_H
You can’t perform that action at this time.
0 commit comments