Ticket #2324: boost-serialization-test-avoid-tmpnam-issue2324.diff

File boost-serialization-test-avoid-tmpnam-issue2324.diff, 2.4 KB (added by Dean Michael Berris, 12 years ago)

Updated patch to fix compile failures on Windows with MSVC.

  • test_tools.hpp

     
    11#ifndef BOOST_SERIALIZATION_TEST_TOOLS_HPP
    22#define BOOST_SERIALIZATION_TEST_TOOLS_HPP
    33
     4#define BOOST_FILESYSTEM_VERSION 3
     5#include <boost/filesystem.hpp>
     6
    47// MS compatible compilers support #pragma once
    58#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    69# pragma once
     
    1619
    1720//  See http://www.boost.org for updates, documentation, and revision history.
    1821
    19 #include <cstdio> // remove, tmpnam
    2022#include <cstddef> // size_t
    2123#ifndef BOOST_NO_EXCEPTION_STD_NAMESPACE
    2224    #include <exception>
     
    8789            char old_dir[256];
    8890            _getcwd(old_dir, sizeof(old_dir) - 1);
    8991            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());
    9197            chdir(old_dir);
    9298        }
    9399        else{
     
    118124 
    119125namespace boost {
    120126namespace archive {
    121     using ::tempnam;
     127    using ::tmpnam;
    122128} // archive
    123129} // boost
    124130
    125131#else // defined(__hpux)
    126132
     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
    127138namespace boost {
    128139namespace 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    }
    130150} // archive
    131151} // boost
    132152
  • Jamfile.v2

     
    88
    99project libs/serialization/test
    1010    : id serialization_test
     11    : requirements <source>/boost/filesystem
    1112    ;
    1213
    1314# import rules from the boost serialization test