[libc-commits] [libc] [libc] Add tmpnam implementation (PR #204901)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Thu Aug 27 22:22:47 PDT 2026
================
@@ -54,5 +54,25 @@ extern FILE *stderr;
#ifndef SEEK_END
#define SEEK_END 2
#endif
+/*
+ * L_tmpnam = 20 ("/tmp/" + 14 random chars + '\0').
+ * Suffix length 14 (base-64) ensures a < 10^-12 collision
+ * probability for up to 10^6 calls (via birthday bound).
+ */
+#ifndef L_tmpnam
+#define L_tmpnam 20
+#endif
+/*
+ * TMP_MAX = 1,000,000 (10^6 calls per process).
+ * Generous decimal call ceiling for the L_tmpnam guarantee;
+ * provides a 6x safety margin below the 6.2M limit (P ~= 2.6 x 10^-14).
+ */
+#ifndef TMP_MAX
+#define TMP_MAX 1000000
+#endif
+
+#ifndef P_tmpdir
----------------
vonosmas wrote:
FWIW this is removed from recent POSIX, I would suggest to avoid including it unless we find it really necessary down the road. It's OK to hardcode `/tmp` in the implementation, I think (e.g. we've opted in for not adding it for `tmpfile` implementation - https://github.com/llvm/llvm-project/pull/213396)
https://github.com/llvm/llvm-project/pull/204901
More information about the libc-commits
mailing list