[libc-commits] [libc] [libc] Add tmpnam implementation (PR #204901)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Thu Jul 2 07:27:21 PDT 2026


================
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Tests for tmpnam
+/// See: https://pubs.opengroup.org/onlinepubs/9799919799/functions/tmpnam.html
+///
+//===----------------------------------------------------------------------===//
+#include "src/stdio/tmpnam.h"
+
+#include "hdr/stdio_macros.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/macros/config.h"
+#include "test/UnitTest/Test.h"
+
+#include <stddef.h> // size_t
+
+namespace {
+
+using LIBC_NAMESPACE::cpp::string_view;
+
+// The portable filename character set the implementation draws from, plus the
+// '/' that appears in the P_tmpdir prefix. Any byte in a returned name must be
+// one of these.
+constexpr char kAllowed[] = "-._/"
+                            "0123456789"
+                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                            "abcdefghijklmnopqrstuvwxyz";
+
+bool only_allowed_chars(string_view sv) {
+  for (char c : sv) {
+    bool found = false;
+    for (size_t i = 0; kAllowed[i] != '\0'; ++i) {
----------------
kaladron wrote:

Could cpp::string_view::find be helpful here?

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


More information about the libc-commits mailing list