[libc-commits] [libc] [libc][stdio] Add fopen_s and bootstrap annex k. (PR #152248)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Aug 6 09:56:27 PDT 2025


================
@@ -0,0 +1,42 @@
+//===-- Implementation header for abort_handler_s ---------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
+#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
+
+#include "hdr/stdio_macros.h"
+#include "hdr/types/errno_t.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/stdio/fflush.h"
+#include "src/stdio/fprintf.h"
+#include "src/stdlib/abort.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LIBC_INLINE static void abort_handler_s(const char *__restrict msg,
+                                        [[maybe_unused]] void *__restrict ptr,
+                                        errno_t error) {
+  libc_errno = error;
+  fprintf(stderr, "abort_handler_s was called in response to a "
+                  "runtime-constraint violation.\n\n");
+  if (msg)
+    fprintf(stderr, "%s\n", msg);
+  fprintf(stderr,
+          "\n\nNote to end users: This program was terminated as a result\
+      of a bug present in the software. Please reach out to your  \
+      software's vendor to get more help.\n");
+
+  fflush(stderr);
+  abort();
----------------
michaelrj-google wrote:

calling public functions from internal code isn't allowed. I'd recommend using `write_to_stderr` from `OSUtil/io.h`

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


More information about the libc-commits mailing list