Ticket #4724: temp_dir_path2.patch
File temp_dir_path2.patch, 7.0 KB (added by , 12 years ago) |
---|
-
boost/filesystem/v3/operations.hpp
188 188 BOOST_FILESYSTEM_DECL 189 189 path system_complete(const path& p, system::error_code* ec=0); 190 190 BOOST_FILESYSTEM_DECL 191 path temp_dir_path(system::error_code* ec=0); 192 BOOST_FILESYSTEM_DECL 191 193 path unique_path(const path& p, system::error_code* ec=0); 192 194 } // namespace detail 193 195 … … 443 445 path system_complete(const path& p, system::error_code& ec) 444 446 {return detail::system_complete(p, &ec);} 445 447 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 446 454 path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%") 447 455 { return detail::unique_path(p); } 448 456 inline … … 982 990 using filesystem3::symlink_file; 983 991 using filesystem3::symlink_status; 984 992 using filesystem3::system_complete; 993 using filesystem3::temp_dir_path; 985 994 using filesystem3::type_unknown; 986 995 using filesystem3::unique_path; 987 996 # ifndef BOOST_FILESYSTEM_NO_DEPRECATED -
libs/filesystem/v3/test/operations_test.cpp
1269 1269 BOOST_TEST(!fs::equivalent(ng, file_ph)); 1270 1270 } 1271 1271 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 fs::path ph = fs::temp_dir_path()/"temp_dir_path_test.txt"; 1282 1283 { 1284 if(exists(ph)) remove(ph); 1285 1286 std::ofstream f(ph.BOOST_FILESYSTEM_C_STR); 1287 1288 f << "passed"; 1289 } 1290 1291 BOOST_TEST(exists(ph)); 1292 1293 { 1294 std::ifstream f(ph.BOOST_FILESYSTEM_C_STR); 1295 std::string s; 1296 1297 f >> s; 1298 1299 BOOST_TEST(s == "passed"); 1300 } 1301 1302 remove(ph); 1303 1304 BOOST_TEST(!exists(ph)); 1305 } 1306 1272 1307 // _tests --------------------------------------------------------------------------// 1273 1308 1274 1309 void _tests() … … 1393 1428 if (create_symlink_ok) // only if symlinks supported 1394 1429 remove_symlink_tests(); 1395 1430 write_time_tests(dir); 1396 1431 1432 temp_dir_path_tests(); 1433 1397 1434 std::cout << "testing complete" << std::endl; 1398 1435 1399 1436 // post-test cleanup -
libs/filesystem/v3/doc/reference.html
114 114   <a href="#status_known">status_known</a><br> 115 115   <a href="#symlink_status">symlink_status</a><br> 116 116   <a href="#system_complete">system_complete</a><br> 117   <a href="#temp_dir_path">temp_dir_path</a><br> 117 118 <a href="#unique_path">unique_path</a></td> 118 119 <td width="34%" valign="top"> 119 120 <a href="#File-streams">File streams</a><br> … … 437 438 path <a href="#system_complete">system_complete</a>(const path& p); 438 439 path <a href="#system_complete">system_complete</a>(const path& p, system::error_code& ec); 439 440 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& ec); 443 440 444 path <a href="#unique_path">unique_path</a>(const path& model="%%%%-%%%%-%%%%-%%%%"); 441 445 path <a href="#unique_path">unique_path</a>(const path& model, system::error_code& ec); 442 446 … … 2442 2446 <p>See <a href="#complete_note"> 2443 2447 <i>complete()</i> note</a> for usage suggestions. <i>-- end note</i>]</p> 2444 2448 </blockquote> 2449 <pre>path <a name="temp_dir_path">temp_dir_path</a>(); 2450 path temp_dir_path(system::error_code& 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. 2454 </p> 2455 <p><i>Throws:</i> As specified in <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.</p> 2459 <p>For <i>POSIX</i> systems the definition of the first existing environment variable from the list: TMPDIR, TMP, TEMP, TEMPDIR is used. 2460 <i>-- end note</i>]</p> 2461 </blockquote> 2445 2462 <pre>path <a name="unique_path">unique_path</a>(const path& model="%%%%-%%%%-%%%%-%%%%"); 2446 2463 path unique_path(const path& model, system::error_code& ec);</pre> 2447 2464 <blockquote> -
libs/filesystem/v3/src/operations.cpp
49 49 #include <boost/scoped_array.hpp> 50 50 #include <boost/detail/workaround.hpp> 51 51 #include <cstdlib> // for malloc, free 52 #include <vector> 52 53 53 54 #ifdef BOOST_FILEYSTEM_INCLUDE_IOSTREAM 54 55 # include <iostream> … … 1445 1446 } 1446 1447 1447 1448 BOOST_FILESYSTEM_DECL 1449 path temp_dir_path(system::error_code* ec) 1450 { 1451 # ifdef BOOST_POSIX_API 1452 const char* val = 0; 1453 1454 (val = std::getenv("TMPDIR" )) || 1455 (val = std::getenv("TMP" )) || 1456 (val = std::getenv("TEMP" )) || 1457 (val = std::getenv("TEMPDIR")); 1458 1459 if (error(val==0, 1460 ec, "boost::filesystem::temp_dir_path")) 1461 return path(); 1462 1463 path p(val); 1464 1465 if (error((ec && !is_directory(p, *ec)) || 1466 (!ec && !is_directory(p)), 1467 ec, "boost::filesystem::temp_dir_path")) 1468 return path(); 1469 1470 return p; 1471 1472 # else // Windows 1473 1474 std::vector<path::value_type> buf(GetTempPathW(0, NULL)); 1475 1476 if (error(buf.empty() || GetTempPathW(buf.size(), &buf[0])==0, 1477 ec, "boost::filesystem::temp_dir_path")) 1478 return path(); 1479 1480 buf.pop_back(); 1481 1482 path p(buf.begin(), buf.end()); 1483 1484 if (error((ec && !is_directory(p, *ec)) || 1485 (!ec && !is_directory(p)), 1486 ec, "boost::filesystem::temp_dir_path")) 1487 return path(); 1488 1489 return p; 1490 # endif 1491 } 1492 1493 BOOST_FILESYSTEM_DECL 1448 1494 path system_complete(const path& p, system::error_code* ec) 1449 1495 { 1450 1496 # ifdef BOOST_POSIX_API