[libc-commits] [libc] [libc] Implement strftime (PR #111305)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Nov 14 09:30:32 PST 2024
================
@@ -0,0 +1,31 @@
+//===-- Implementation of strftime function -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/time/strftime.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/errno/libc_errno.h"
+#include "src/time/time_utils.h"
+
+#include "src/stdio/printf_core/writer.h"
+#include "src/time/strftime_core/strftime_main.h"
+namespace LIBC_NAMESPACE_DECL {
+
+size_t strftime(char *__restrict buffer, size_t buffsz,
+ const char *__restrict format, const struct tm *timeptr) {
+
+ printf_core::WriteBuffer wb(buffer, (buffsz > 0 ? buffsz - 1 : 0),
+ strftime_core::overflow_write_mock, nullptr);
+ printf_core::Writer writer(&wb);
+ int ret = strftime_core::strftime_main(&writer, format, timeptr);
+ if (buffsz > 0) // if the buffsz is 0 the buffer may be a null pointer.
----------------
nickdesaulniers wrote:
Perhaps before doing any work, we should explicitly validate the inputs? Then we could explicit check that the pointer parameters are not null, bufsz is not zero, etc.
https://github.com/llvm/llvm-project/pull/111305
More information about the libc-commits
mailing list