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

via libc-commits libc-commits at lists.llvm.org
Wed Aug 26 20:27:06 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/stdio/linux/tmpnam.cpp libc/src/stdio/tmpnam.h libc/test/src/stdio/tmpnam_test.cpp libc/include/llvm-libc-macros/stdio-macros.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/stdio/linux/tmpnam.cpp b/libc/src/stdio/linux/tmpnam.cpp
index dc5fedfcd..16bb721f6 100644
--- a/libc/src/stdio/linux/tmpnam.cpp
+++ b/libc/src/stdio/linux/tmpnam.cpp
@@ -39,7 +39,7 @@ LLVM_LIBC_FUNCTION(char *, tmpnam, (char *s)) {
   if (s == nullptr)
     s = tmpbuf;
 
-  // Subset of the POSIX portable filename character set. 
+  // Subset of the POSIX portable filename character set.
   // Deliberately sized to 64 (a power of 2, rather than the full set)
   // to prevent slight modulo bias also helps in performance.
   const char CHARSET[] = "0123456789"
@@ -48,8 +48,8 @@ LLVM_LIBC_FUNCTION(char *, tmpnam, (char *s)) {
                          "_.";
   constexpr size_t CHARSET_SIZE = sizeof(CHARSET) - 1; // 64 (excluding '\0')
   static_assert((CHARSET_SIZE & (CHARSET_SIZE - 1)) == 0,
-              "CHARSET_SIZE must be a power of 2");
-  
+                "CHARSET_SIZE must be a power of 2");
+
   constexpr size_t MASK = CHARSET_SIZE - 1;
 
   // We want to construct: P_tmpdir / <14 random chars> \0
diff --git a/libc/test/src/stdio/tmpnam_test.cpp b/libc/test/src/stdio/tmpnam_test.cpp
index d7c5b0022..ba1cc1c92 100644
--- a/libc/test/src/stdio/tmpnam_test.cpp
+++ b/libc/test/src/stdio/tmpnam_test.cpp
@@ -27,10 +27,10 @@ using LIBC_NAMESPACE::cpp::string_view;
 // '/' that appears in the P_tmpdir prefix. Any byte in a returned name must be
 // one of these.
 constexpr char Allowed[] = "-./"
-                            "0123456789"
-                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                            "_"
-                            "abcdefghijklmnopqrstuvwxyz";
+                           "0123456789"
+                           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                           "_"
+                           "abcdefghijklmnopqrstuvwxyz";
 
 bool only_allowed_chars(string_view sv) {
   for (char c : sv) {

``````````

</details>


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


More information about the libc-commits mailing list