[libc-commits] [libc] [WIP] Basic structures for strftime (PR #111305)
via libc-commits
libc-commits at lists.llvm.org
Sun Oct 13 08:41:00 PDT 2024
================
@@ -0,0 +1,28 @@
+//===-- 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));
+ printf_core::Writer writer(&wb);
+ strftime_core::strftime_main(&writer, format, timeptr);
+ return -1;
----------------
graphite-app[bot] wrote:
The current implementation always returns `-1`, which is incorrect. The function should return the number of characters written, or 0 if the result doesn't fit in the buffer. Consider replacing `return -1;` with `return writer.get_chars_written();`. Additionally, you may want to add logic to handle buffer overflow and return 0 in such cases.
*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
https://github.com/llvm/llvm-project/pull/111305
More information about the libc-commits
mailing list