This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3 patch] Fix some Filesystem TS operations
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 20 May 2015 18:28:08 +0100
- Subject: Re: [v3 patch] Fix some Filesystem TS operations
- Authentication-results: sourceware.org; auth=none
- References: <20150515183734 dot GU30202 at redhat dot com>
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).
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;
}