Ticket #4724: temp_dir_path.patch

File temp_dir_path.patch, 6.2 KB (added by Jeff Flinn <jflinn@…>, 12 years ago)

patch for temp_dir_path() addition

  • boost/filesystem/v3/operations.hpp

     
    188188    BOOST_FILESYSTEM_DECL
    189189    path system_complete(const path& p, system::error_code* ec=0);
    190190    BOOST_FILESYSTEM_DECL
     191    path temp_dir_path(system::error_code* ec=0);
     192    BOOST_FILESYSTEM_DECL
    191193    path unique_path(const path& p, system::error_code* ec=0);
    192194  }  // namespace detail
    193195
     
    443445  path system_complete(const path& p, system::error_code& ec)
    444446                                       {return detail::system_complete(p, &ec);}
    445447  inline
     448  path temp_dir_path()                {return detail::temp_dir_path();}
     449
     450  inline
     451  path temp_dir_path(system::error_code& ec)
     452                                       {return detail::temp_dir_path(&ec);}
     453  inline
    446454  path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
    447455                                       { return detail::unique_path(p); }
    448456  inline
     
    982990    using filesystem3::symlink_file;
    983991    using filesystem3::symlink_status;
    984992    using filesystem3::system_complete;
     993    using filesystem3::temp_dir_path;
    985994    using filesystem3::type_unknown;
    986995    using filesystem3::unique_path;
    987996# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  • libs/filesystem/v3/test/operations_test.cpp

     
    12691269    BOOST_TEST(!fs::equivalent(ng, file_ph));
    12701270  }
    12711271
     1272  //  temp_dir_path_tests  ---------------------------------------------------------//
     1273
     1274  void temp_dir_path_tests()
     1275  {
     1276      std::cout << "temp_dir_path_tests..." << std::endl;
     1277
     1278      BOOST_TEST(!fs::temp_dir_path().empty());
     1279      BOOST_TEST(exists(fs::temp_dir_path()));
     1280  }
     1281
    12721282  //  _tests  --------------------------------------------------------------------------//
    12731283
    12741284  void _tests()
     
    13931403  if (create_symlink_ok)  // only if symlinks supported
    13941404    remove_symlink_tests();
    13951405  write_time_tests(dir);
    1396 
     1406 
     1407  temp_dir_path_tests();
     1408 
    13971409  std::cout << "testing complete" << std::endl;
    13981410
    13991411  // post-test cleanup
  • libs/filesystem/v3/doc/reference.html

     
    114114&nbsp;&nbsp;&nbsp;&nbsp <a href="#status_known">status_known</a><br>
    115115&nbsp;&nbsp;&nbsp;&nbsp <a href="#symlink_status">symlink_status</a><br>
    116116&nbsp;&nbsp;&nbsp;&nbsp <a href="#system_complete">system_complete</a><br>
     117&nbsp;&nbsp;&nbsp;&nbsp <a href="#temp_dir_path">temp_dir_path</a><br>
    117118&nbsp;&nbsp;&nbsp;&nbsp; <a href="#unique_path">unique_path</a></td>
    118119    <td width="34%" valign="top">
    119120    <a href="#File-streams">File streams</a><br>
     
    437438      path         <a href="#system_complete">system_complete</a>(const path&amp; p);
    438439      path         <a href="#system_complete">system_complete</a>(const path&amp; p, system::error_code&amp; ec);
    439440
     441      path         <a href="#temp_dir_path">temp_dir_path</a>();
     442      path         <a href="#temp_dir_path">temp_dir_path</a>(system::error_code&amp; ec);
     443
    440444      path         <a href="#unique_path">unique_path</a>(const path&amp; model=&quot;%%%%-%%%%-%%%%-%%%%&quot;);
    441445      path         <a href="#unique_path">unique_path</a>(const path&amp; model, system::error_code&amp; ec);
    442446
     
    24422446  <p>See <a href="#complete_note">
    24432447  <i>complete()</i> note</a> for usage suggestions. <i>-- end note</i>]</p>
    24442448</blockquote>
     2449<pre>path <a name="temp_dir_path">temp_dir_path</a>();
     2450path temp_dir_path(system::error_code&amp; ec);</pre>
     2451<blockquote>
     2452  <p><i>Returns:</i> The temporary directory path as returned by the <i>POSIX</i> <code>getenv("TMPDIR")</code> environment variable,
     2453  or the <i>Windows</i> <code>GetTempPath</code> API function. <code>is_directory()</code> is true for the returned path.</p>
     2454  <p><i>Throws:</i> As specified in
     2455  <a href="#Error-reporting">
     2456  Error reporting</a>.</p>
     2457  <p>[<i>Note: </i>The <code>temp_dir_path()</code> name was chosen to emphasize that the return is a
     2458  path, not just a single directory name.&nbsp; <i>-- end note</i>]</p>
     2459</blockquote>
    24452460<pre>path <a name="unique_path">unique_path</a>(const path&amp; model=&quot;%%%%-%%%%-%%%%-%%%%&quot;);
    24462461path unique_path(const path&amp; model, system::error_code&amp; ec);</pre>
    24472462<blockquote>
  • libs/filesystem/v3/src/operations.cpp

     
    4949#include <boost/scoped_array.hpp>
    5050#include <boost/detail/workaround.hpp>
    5151#include <cstdlib>  // for malloc, free
     52#include <vector>
    5253
    5354#ifdef BOOST_FILEYSTEM_INCLUDE_IOSTREAM
    5455# include <iostream>
     
    14451446  }
    14461447
    14471448  BOOST_FILESYSTEM_DECL
     1449  path temp_dir_path(system::error_code* ec)
     1450  {
     1451#   ifdef BOOST_POSIX_API
     1452      const char* val = std::getenv("TMPDIR");
     1453     
     1454      if (error(val==0,
     1455        ec, "boost::filesystem::temp_dir_path"))
     1456          return path();
     1457       
     1458      path p(val);
     1459
     1460      if (error((ec && !is_directory(p, *ec)) ||
     1461        (!ec && !is_directory(p)),
     1462        ec, "boost::filesystem::temp_dir_path"))
     1463          return path();
     1464       
     1465      return p;
     1466     
     1467#   else  // Windows
     1468
     1469      std::vector<path::value_type> buf(GetTempPathW(0, NULL));
     1470
     1471      if (error(buf.empty() || GetTempPathW(buf.size(), &buf[0])==0,
     1472        ec, "boost::filesystem::temp_dir_path"))
     1473          return path();
     1474         
     1475      buf.pop_back();
     1476     
     1477      path p(buf.begin(), buf.end());
     1478         
     1479      if (error((ec && !is_directory(p, *ec)) ||
     1480          (!ec && !is_directory(p)),
     1481        ec, "boost::filesystem::temp_dir_path"))
     1482          return path();
     1483
     1484      return p;
     1485#   endif
     1486  }
     1487 
     1488  BOOST_FILESYSTEM_DECL
    14481489  path system_complete(const path& p, system::error_code* ec)
    14491490  {
    14501491#   ifdef BOOST_POSIX_API