[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,141 @@
+//===-- Unittests for 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 "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/signal_macros.h"
+#include "src/stdlib/mkstemp.h"
+#include "src/unistd/access.h"
+#include "src/unistd/close.h"
+#include "src/unistd/read.h"
+#include "src/unistd/unlink.h"
+#include "src/unistd/write.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcMkstempTest, ValidTemplate) {
+  char tmpl[] = "tmp_XXXXXX";
----------------
michaelrj-google wrote:

the filepath is going to be a bit complicated when we want to support bazel, since bazel is strict about where tests are allowed to write files. It provides a path to a file, which we normally use by calling `libc_make_test_file_path`. The fact that the paths need to be writeable here makes that a bit more complicated. Your best bet may be to call `strdup` on the result of `libc_make_test_file_path` and free the pointer at the end of the test.

See https://github.com/llvm/llvm-project/blob/main/libc/test/src/unistd/unlink_test.cpp for how `libc_make_test_file_path` is used.

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


More information about the libc-commits mailing list