1 | //===-- Implementation of strftime_l 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 "src/time/strftime_l.h" |
10 | #include "hdr/types/locale_t.h" |
11 | #include "hdr/types/size_t.h" |
12 | #include "hdr/types/struct_tm.h" |
13 | #include "src/__support/common.h" |
14 | #include "src/__support/macros/config.h" |
15 | #include "src/stdio/printf_core/writer.h" |
16 | #include "src/time/strftime_core/strftime_main.h" |
17 | |
18 | namespace LIBC_NAMESPACE_DECL { |
19 | |
20 | // TODO: Add support for locales. |
21 | LLVM_LIBC_FUNCTION(size_t, strftime_l, |
22 | (char *__restrict buffer, size_t buffsz, |
23 | const char *__restrict format, const tm *timeptr, |
24 | locale_t)) { |
25 | printf_core::WriteBuffer<printf_core::Mode< |
26 | printf_core::WriteMode::FILL_BUFF_AND_DROP_OVERFLOW>::value> |
27 | wb(buffer, (buffsz > 0 ? buffsz - 1 : 0)); |
28 | printf_core::Writer writer(wb); |
29 | int ret = strftime_core::strftime_main(&writer, format, timeptr); |
30 | if (buffsz > 0) // if the buffsz is 0 the buffer may be a null pointer. |
31 | wb.buff[wb.buff_cur] = '\0'; |
32 | return (ret < 0 || static_cast<size_t>(ret) > buffsz) ? 0 : ret; |
33 | } |
34 | |
35 | } // namespace LIBC_NAMESPACE_DECL |
36 | |