[libc-commits] [libc] [libc] Implement syslog functions (PR #244029)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Thu Nov 19 16:06:21 PST 2026


================
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of internal state and formatting for syslog.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/syslog/linux/syslog_internal.h"
+
+#include "hdr/syslog_macros.h"
+#include "hdr/time_macros.h"
+#include "hdr/types/pid_t.h"
+#include "hdr/types/size_t.h"
+#include "hdr/types/struct_timespec.h"
+#include "hdr/types/struct_tm.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/OSUtil/io.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/getpid.h"
+#include "src/__support/arg_list.h"
+#include "src/__support/integer_to_string.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/printf_core/core_structs.h"
+#include "src/__support/printf_core/printf_main.h"
+#include "src/__support/printf_core/writer.h"
+#include "src/__support/threads/mutex.h"
+#include "src/__support/time/clock_gettime.h"
+#include "src/errno/program_invocation_short_name.h"
+#include "src/time/strftime_core/strftime_main.h"
+#include "src/time/time_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace syslog_internal {
+
+static constexpr size_t BUFFER_SIZE = 1024;
+
+static Mutex log_mutex(/*is_priority_inherit=*/false, /*is_recursive=*/false,
+                       /*is_robust=*/false, /*is_pshared=*/false);
+LIBC_CONSTINIT static LogState log_state;
+
+LIBC_INLINE int stderr_write_hook(cpp::string_view str, void *) {
+  write_to_stderr(str);
+  return printf_core::WRITE_OK;
+}
+
+bool write_log_message(
+    printf_core::Writer<printf_core::OverflowMode::CALLBACK> &writer,
+    const LogState &state, int priority, const char *__restrict format,
+    internal::ArgList &args, const tm *timestamp, pid_t pid,
----------------
kaladron wrote:

If timestamp can't be null, could it be passed by const reference here instead?

https://github.com/llvm/llvm-project/pull/244029


More information about the libc-commits mailing list