Ticket #2324: boost-serialization-test-avoid-tmpnam-issue2324.2.diff
File boost-serialization-test-avoid-tmpnam-issue2324.2.diff, 2.6 KB (added by , 12 years ago) |
---|
-
test_tools.hpp
1 1 #ifndef BOOST_SERIALIZATION_TEST_TOOLS_HPP 2 2 #define BOOST_SERIALIZATION_TEST_TOOLS_HPP 3 3 4 #define BOOST_FILESYSTEM_VERSION 3 5 #include <boost/filesystem.hpp> 6 4 7 // MS compatible compilers support #pragma once 5 8 #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 9 # pragma once … … 16 19 17 20 // See http://www.boost.org for updates, documentation, and revision history. 18 21 19 #include <cstdio> // remove, tmpnam20 22 #include <cstddef> // size_t 21 23 #ifndef BOOST_NO_EXCEPTION_STD_NAMESPACE 22 24 #include <exception> … … 87 89 char old_dir[256]; 88 90 _getcwd(old_dir, sizeof(old_dir) - 1); 89 91 chdir(dir); 90 std::tmpnam(ibuffer + i); 92 // (C) Copyright 2010 Dean Michael Berris. <mikhailberis@gmail.com> 93 // Instead of using std::tmpnam, we use Boost.Filesystem's unique_path 94 boost::filesystem::path tmp_path = 95 boost::filesystem::unique_path("%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); 96 std::strcat(ibuffer, tmp_path.string().c_str()); 91 97 chdir(old_dir); 92 98 } 93 99 else{ … … 118 124 119 125 namespace boost { 120 126 namespace archive { 121 using ::t empnam;127 using ::tmpnam; 122 128 } // archive 123 129 } // boost 124 130 125 131 #else // defined(__hpux) 126 132 133 // (C) Copyright 2010 Dean Michael Berris. 134 // Instead of using the potentially dangrous tempnam function that's part 135 // of the C standard library, on Unix/Linux we use the more portable and 136 // "safe" unique_path function provided in the Boost.Filesystem library. 137 138 #include <boost/archive/tmpdir.hpp> 139 127 140 namespace boost { 128 141 namespace archive { 129 using std::tmpnam; 142 char const * tmpnam(char * buffer) { 143 static char name[512] = {0}; 144 if (name[0] == 0) { 145 boost::filesystem::path tempdir(tmpdir()); 146 boost::filesystem::path tempfilename = 147 boost::filesystem::unique_path("serialization-%%%%%%%%%%%%%%%%"); 148 boost::filesystem::path temp = tempdir / tempfilename; 149 std::strcat(name, temp.string().c_str()); 150 } 151 if (buffer != 0) std::strcpy(buffer, name); 152 return name; 153 } 130 154 } // archive 131 155 } // boost 132 156 -
Jamfile.v2
8 8 9 9 project libs/serialization/test 10 10 : id serialization_test 11 : requirements <source>/boost/filesystem 11 12 ; 12 13 13 14 # import rules from the boost serialization test