Ticket #2324: boost-serialization-test-avoid-tmpnam-issue2324.diff
File boost-serialization-test-avoid-tmpnam-issue2324.diff, 2.4 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 127 138 namespace boost { 128 139 namespace archive { 129 using std::tmpnam; 140 char const * tmpnam(char * buffer) { 141 static char name[512] = {0}; 142 if (name[0] == 0) { 143 boost::filesystem::path temp = 144 boost::filesystem::unique_path("serialization-%%%%%%%%%%%%%%%%"); 145 std::strcpy(name, temp.string().c_str()); 146 } 147 if (buffer != 0) std::strcpy(buffer, name); 148 return name; 149 } 130 150 } // archive 131 151 } // boost 132 152 -
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