[libcxx-commits] [libcxx] [libcxx] Add fallback to standard C when `unistd` is unavailable (PR #102005)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 6 10:37:01 PDT 2024


================
@@ -55,31 +55,44 @@ extern "C" {
 }
 #endif
 
-inline
-std::string get_temp_file_name()
-{
+inline std::string get_temp_file_name() {
 #if defined(_WIN32)
-    while (true) {
-        char Name[] = "libcxx.XXXXXX";
-        if (_mktemp_s(Name, sizeof(Name)) != 0) abort();
-        int fd = _open(Name, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
-        if (fd != -1) {
-            _close(fd);
-            return Name;
-        }
-        if (errno == EEXIST)
-            continue;
-        abort();
+  while (true) {
+    char Name[] = "libcxx.XXXXXX";
+    if (_mktemp_s(Name, sizeof(Name)) != 0)
+      abort();
+    int fd = _open(Name, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
+    if (fd != -1) {
+      _close(fd);
+      return Name;
     }
+    if (errno == EEXIST)
+      continue;
+    abort();
+  }
+#elif !__has_include(<unistd.h>)
+  // Without `unistd.h` we cannot guarnatee that the file is unused, however we
----------------
mordante wrote:

```suggestion
  // Without `unistd.h` we cannot guarantee that the file is unused, however we
```

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


More information about the libcxx-commits mailing list