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

Aaron Ballman via libc-commits libc-commits at lists.llvm.org
Fri Aug 8 10:03:24 PDT 2025


================
@@ -0,0 +1,21 @@
+//===-- Definition of type constraint_handler_t ---------------------------===//
+//
+// 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_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
+#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
+
+#include "errno_t.h"
+
+#ifdef LIBC_HAS_ANNEX_K
+
+typedef void (*constraint_handler_t)(const char *__restrict msg,
+                                     void *__restrict ptr, errno_t error);
----------------
AaronBallman wrote:

In user code, leading `__` is undefined behavior. But it's that way specifically because `__` is reserved for implementers so that they have a way to avoid name collisions with user code. It's actually necessary for conformance, because otherwise you run into a problem like this:
```
#define msg "muahahahaha I am a good person doing good things"

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
```
where you get a compile error because that causes us to parse:
```
typedef void (*constraint_handler_t)(const char *__restrict "muahahahaha I am a good person doing good things",
                                     void *__restrict ptr, errno_t error);
```

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


More information about the libc-commits mailing list