|
| 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/size_t.h" |
| 11 | +#include "hdr/types/struct_tm.h" |
| 12 | +#include "include/llvm-libc-types/locale_t.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 count, |
| 23 | + const char *__restrict format, |
| 24 | + const struct tm *__restrict tp, locale_t)) { |
| 25 | + printf_core::WriteBuffer wb(buffer, (buffsz > 0 ? buffsz - 1 : 0)); |
| 26 | + printf_core::Writer writer(&wb); |
| 27 | + int ret = strftime_core::strftime_main(&writer, format, timeptr); |
| 28 | + if (buffsz > 0) // if the buffsz is 0 the buffer may be a null pointer. |
| 29 | + wb.buff[wb.buff_cur] = '\0'; |
| 30 | + return (ret < 0 || static_cast<size_t>(ret) > buffsz) ? 0 : ret; |
| 31 | +} |
| 32 | + |
| 33 | +} // namespace LIBC_NAMESPACE_DECL |
0 commit comments