diff mbox

[v3] Fix some Filesystem TS operations

Message ID 20150520172808.GL30202@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely May 20, 2015, 5:28 p.m. UTC
On 15/05/15 19:37 +0100, Jonathan Wakely wrote:
>Testing revealed a few bugs in how I handled paths that don't exist.
>The new __gnu_test::nonexistent_path() function is a bit hacky but
>should be good enough for the testsuite.

This makes it even hackier but avoids linker warnings for using the
evil tempnam() function.

I know it should use snprintf not sprintf, but that depends on
_GLIBCXX_USE_C99 which may not be defined (because we incorrectly test
for a C99 lib using -std=gnu++98, which I'm going to fix).
diff mbox

Patch

commit fc7f3808e940243362d29acde4a09ae90aa0df81
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 20 18:17:56 2015 +0100

    	* testsuite/util/testsuite_fs.h (nonexistent_path): Don't use tempnam.

diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h
index f404a7a..3873a60 100644
--- a/libstdc++-v3/testsuite/util/testsuite_fs.h
+++ b/libstdc++-v3/testsuite/util/testsuite_fs.h
@@ -26,10 +26,8 @@ 
 #include <iostream>
 #include <string>
 #include <cstdio>
-#if defined(_GNU_SOURCE) || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
-# include <stdlib.h>
-# include <unistd.h>
-#endif
+#include <stdlib.h>
+#include <unistd.h>
 
 namespace __gnu_test
 {
@@ -84,12 +82,9 @@  namespace __gnu_test
     ::close(fd);
     p = tmp;
 #else
-    char* tmp = tempnam(".", "test.");
-    if (!tmp)
-      throw std::experimental::filesystem::filesystem_error("tempnam failed",
-	  std::error_code(errno, std::generic_category()));
-    p = tmp;
-    ::free(tmp);
+    char buf[64];
+    std::sprintf(buf, "test.%lu", (unsigned long)::getpid());
+    p = buf;
 #endif
     return p;
   }