[libc-commits] [libc] [libc] implement mkstemp (PR #199220)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri May 22 12:17:34 PDT 2026


================
@@ -0,0 +1,86 @@
+//===-- Implementation of mkstemp -----------------------------------------===//
+//
+// 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/stdlib/mkstemp.h"
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/getrandom.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, mkstemp, (char *tmpl)) {
+  LIBC_CRASH_ON_NULLPTR(tmpl);
+
+  // keep walking until we find the null terminator
+  int len = 0;
+  char *walk = tmpl;
+  while (*walk != '\0') {
+    walk++;
+    len++;
+  }
+
+  // invalid string length check
+  if (len < 6) {
+    libc_errno = EINVAL;
+    return -1;
+  }
----------------
michaelrj-google wrote:

this could be simplified by creating a `cpp::string_view` on `tmpl`.

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


More information about the libc-commits mailing list