[all-commits] [llvm/llvm-project] 64e4dd: [libcxx] [test] Fix back-to-back use of get_temp_f...

Martin Storsjö via All-commits all-commits at lists.llvm.org
Mon Apr 11 09:48:49 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 64e4dd329c0c9d4c462594df004afd3102a54412
  Author: Martin Storsjö <martin at martin.st>
  Date:   2022-04-11 (Mon, 11 Apr 2022)

  Changed paths:
    M libcxx/test/support/platform_support.h

  Log Message:
  [libcxx] [test] Fix back-to-back use of get_temp_file_name() on Windows

On non-Windows platforms, get_temp_file_name() uses `mkstemp()`,
which picks a unique name and creates a file atomically. The
Windows implementation uses `_mktemp_s()`, which doesn't create the
file. The documentation of `_mktemp_s()` also says that by design,
the function uses the same pattern within a process, as long as that
file doesn't exist.

Thus previously, two consecutive calls to `get_temp_file_name()`
on Windows returned the same file name.

Try to create the suggested temp file with `_O_EXCL` (marking the
file name as already used for future calls to `_mktemp_s`) and retry
if we weren't able to exclusively create the file.

This fixes the test failures on Windows observed in D122257.

Differential Revision: https://reviews.llvm.org/D122612

More information about the All-commits mailing list