Reformatted code for more consistent look and better readability.

This commit is contained in:
Andrey Semashev 2021-04-24 22:37:57 +03:00
parent 83429c9bfd
commit c03249c375
93 changed files with 10409 additions and 10003 deletions

View File

@ -5,13 +5,13 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int test_main(int, char*[]) // note name int test_main(int, char*[]) // note name
{ {
BOOST_TEST(2 + 2 == 5); // one convertible-to-bool argument BOOST_TEST(2 + 2 == 5); // one convertible-to-bool argument
BOOST_TEST_EQ(4 + 4, 9); // two EqualityComparible arguments BOOST_TEST_EQ(4 + 4, 9); // two EqualityComparible arguments
BOOST_TEST(fs::exists(".")); // should pass, so nothing reported BOOST_TEST(fs::exists(".")); // should pass, so nothing reported
return ::boost::report_errors(); // required return ::boost::report_errors(); // required
} }
// Copyright Beman Dawes 2014 // Copyright Beman Dawes 2014

View File

@ -26,9 +26,9 @@
int main() int main()
{ {
unsigned char buf[16] = {}; unsigned char buf[16] = {};
boost::winapi::BCRYPT_ALG_HANDLE_ handle; boost::winapi::BCRYPT_ALG_HANDLE_ handle;
boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0); boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast<boost::winapi::PUCHAR_>(static_cast<unsigned char*>(buf)), static_cast<boost::winapi::ULONG_>(sizeof(buf)), 0); status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast< boost::winapi::PUCHAR_ >(static_cast< unsigned char* >(buf)), static_cast< boost::winapi::ULONG_ >(sizeof(buf)), 0);
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0); boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
} }

View File

@ -17,156 +17,154 @@ using boost::filesystem::path;
using std::string; using std::string;
using std::cout; using std::cout;
namespace namespace {
std::ifstream infile;
std::ofstream posix_outfile;
std::ifstream posix_infile;
std::ofstream outfile;
bool posix;
const string empty_string;
struct column_base
{ {
std::ifstream infile;
std::ofstream posix_outfile;
std::ifstream posix_infile;
std::ofstream outfile;
bool posix;
const string empty_string;
struct column_base
{
virtual string heading() const = 0; virtual string heading() const = 0;
virtual string cell_value( const path & p ) const = 0; virtual string cell_value(const path& p) const = 0;
}; };
struct c0 : public column_base struct c0 : public column_base
{ {
string heading() const { return string("<code>string()</code>"); } string heading() const { return string("<code>string()</code>"); }
string cell_value( const path & p ) const { return p.string(); } string cell_value(const path& p) const { return p.string(); }
} o0; } o0;
struct c1 : public column_base struct c1 : public column_base
{ {
string heading() const { return string("<code>generic_<br>string()</code>"); } string heading() const { return string("<code>generic_<br>string()</code>"); }
string cell_value( const path & p ) const { return p.generic_string(); } string cell_value(const path& p) const { return p.generic_string(); }
} o1; } o1;
struct c2 : public column_base struct c2 : public column_base
{ {
string heading() const { return string("Iteration<br>over<br>Elements"); } string heading() const { return string("Iteration<br>over<br>Elements"); }
string cell_value( const path & p ) const string cell_value(const path& p) const
{ {
string s; string s;
for( path::iterator i(p.begin()); i != p.end(); ++i ) for (path::iterator i(p.begin()); i != p.end(); ++i)
{ {
if ( i != p.begin() ) s += ','; if (i != p.begin())
s += (*i).string(); s += ',';
} s += (*i).string();
return s; }
return s;
} }
} o2; } o2;
struct c3 : public column_base struct c3 : public column_base
{ {
string heading() const { return string("<code>root_<br>path()</code>"); } string heading() const { return string("<code>root_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.root_path().string(); } string cell_value(const path& p) const { return p.root_path().string(); }
} o3; } o3;
struct c4 : public column_base struct c4 : public column_base
{ {
string heading() const { return string("<code>root_<br>name()</code>"); } string heading() const { return string("<code>root_<br>name()</code>"); }
string cell_value( const path & p ) const { return p.root_name().string(); } string cell_value(const path& p) const { return p.root_name().string(); }
} o4; } o4;
struct c5 : public column_base struct c5 : public column_base
{ {
string heading() const { return string("<code>root_<br>directory()</code>"); } string heading() const { return string("<code>root_<br>directory()</code>"); }
string cell_value( const path & p ) const { return p.root_directory().string(); } string cell_value(const path& p) const { return p.root_directory().string(); }
} o5; } o5;
struct c6 : public column_base struct c6 : public column_base
{ {
string heading() const { return string("<code>relative_<br>path()</code>"); } string heading() const { return string("<code>relative_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.relative_path().string(); } string cell_value(const path& p) const { return p.relative_path().string(); }
} o6; } o6;
struct c7 : public column_base struct c7 : public column_base
{ {
string heading() const { return string("<code>parent_<br>path()</code>"); } string heading() const { return string("<code>parent_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.parent_path().string(); } string cell_value(const path& p) const { return p.parent_path().string(); }
} o7; } o7;
struct c8 : public column_base struct c8 : public column_base
{ {
string heading() const { return string("<code>filename()</code>"); } string heading() const { return string("<code>filename()</code>"); }
string cell_value( const path & p ) const { return p.filename().string(); } string cell_value(const path& p) const { return p.filename().string(); }
} o8; } o8;
const column_base * column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 }; const column_base* column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 };
// do_cell ---------------------------------------------------------------// // do_cell ---------------------------------------------------------------//
void do_cell( const string & test_case, int i ) void do_cell(const string& test_case, int i)
{ {
string temp = column[i]->cell_value(path(test_case)); string temp = column[i]->cell_value(path(test_case));
string value; string value;
outfile << "<td>"; outfile << "<td>";
if (temp.empty()) if (temp.empty())
value = "<font size=\"-1\"><i>empty</i></font>"; value = "<font size=\"-1\"><i>empty</i></font>";
else else
value = string("<code>") + temp + "</code>"; value = string("<code>") + temp + "</code>";
if (posix) if (posix)
posix_outfile << value << '\n'; posix_outfile << value << '\n';
else else
{ {
std::getline(posix_infile, temp); std::getline(posix_infile, temp);
if (value != temp) // POSIX and Windows differ if (value != temp) // POSIX and Windows differ
{ {
value.insert(0, "<br>"); value.insert(0, "<br>");
value.insert(0, temp); value.insert(0, temp);
value.insert(0, "<span style=\"background-color: #CCFFCC\">"); value.insert(0, "<span style=\"background-color: #CCFFCC\">");
value += "</span>"; value += "</span>";
} }
outfile << value; outfile << value;
} }
outfile << "</td>\n"; outfile << "</td>\n";
} }
// do_row ------------------------------------------------------------------// // do_row ------------------------------------------------------------------//
void do_row( const string & test_case ) void do_row(const string& test_case)
{ {
outfile << "<tr>\n"; outfile << "<tr>\n";
if (test_case.empty()) if (test_case.empty())
outfile << "<td><font size=\"-1\"><i>empty</i></font></td>\n"; outfile << "<td><font size=\"-1\"><i>empty</i></font></td>\n";
else else
outfile << "<td><code>" << test_case << "</code></td>\n"; outfile << "<td><code>" << test_case << "</code></td>\n";
for ( int i = 0; i < sizeof(column)/sizeof(column_base&); ++i ) for (int i = 0; i < sizeof(column) / sizeof(column_base&); ++i)
{ {
do_cell( test_case, i ); do_cell(test_case, i);
} }
outfile << "</tr>\n"; outfile << "</tr>\n";
} }
// do_table ----------------------------------------------------------------// // do_table ----------------------------------------------------------------//
void do_table() void do_table()
{ {
outfile << outfile << "<h1>Path Decomposition Table</h1>\n"
"<h1>Path Decomposition Table</h1>\n" "<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n"
"<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n" "implementations yield different results. The top value is the\n"
"implementations yield different results. The top value is the\n" "<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n"
"<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n" "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
"<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n" "<p>\n";
"<p>\n"
;
// generate the column headings // generate the column headings
outfile << "<tr><td><b>Constructor<br>argument</b></td>\n"; outfile << "<tr><td><b>Constructor<br>argument</b></td>\n";
for ( int i = 0; i < sizeof(column)/sizeof(column_base&); ++i ) for (int i = 0; i < sizeof(column) / sizeof(column_base&); ++i)
{ {
outfile << "<td><b>" << column[i]->heading() << "</b></td>\n"; outfile << "<td><b>" << column[i]->heading() << "</b></td>\n";
} }
outfile << "</tr>\n"; outfile << "</tr>\n";
@ -174,16 +172,16 @@ namespace
// generate a row for each input line // generate a row for each input line
string test_case; string test_case;
while ( std::getline( infile, test_case ) ) while (std::getline(infile, test_case))
{ {
if (!test_case.empty() && *--test_case.end() == '\r') if (!test_case.empty() && *--test_case.end() == '\r')
test_case.erase(test_case.size()-1); test_case.erase(test_case.size() - 1);
if (test_case.empty() || test_case[0] != '#') if (test_case.empty() || test_case[0] != '#')
do_row( test_case ); do_row(test_case);
} }
outfile << "</table>\n"; outfile << "</table>\n";
} }
} // unnamed namespace } // unnamed namespace
@ -192,69 +190,65 @@ namespace
#define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE #define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
#include <boost/test/included/prg_exec_monitor.hpp> #include <boost/test/included/prg_exec_monitor.hpp>
int cpp_main( int argc, char * argv[] ) // note name! int cpp_main(int argc, char* argv[]) // note name!
{ {
if ( argc != 5 ) if (argc != 5)
{
std::cerr <<
"Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
"Run on POSIX first, then on Windows\n"
" \"POSIX\" causes POSIX results to be saved in posix-file;\n"
" \"Windows\" causes POSIX results read from posix-file\n"
" input-file contains the paths to appear in the table.\n"
" posix-file will be used for POSIX results\n"
" output-file will contain the generated HTML.\n"
;
return 1;
}
infile.open( argv[2] );
if ( !infile )
{
std::cerr << "Could not open input file: " << argv[2] << std::endl;
return 1;
}
if (string(argv[1]) == "POSIX")
{
posix = true;
posix_outfile.open( argv[3] );
if ( !posix_outfile )
{ {
std::cerr << "Could not open POSIX output file: " << argv[3] << std::endl; std::cerr << "Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
return 1; "Run on POSIX first, then on Windows\n"
" \"POSIX\" causes POSIX results to be saved in posix-file;\n"
" \"Windows\" causes POSIX results read from posix-file\n"
" input-file contains the paths to appear in the table.\n"
" posix-file will be used for POSIX results\n"
" output-file will contain the generated HTML.\n";
return 1;
} }
}
else infile.open(argv[2]);
{ if (!infile)
posix = false;
posix_infile.open( argv[3] );
if ( !posix_infile )
{ {
std::cerr << "Could not open POSIX input file: " << argv[3] << std::endl; std::cerr << "Could not open input file: " << argv[2] << std::endl;
return 1; return 1;
} }
}
outfile.open( argv[4] ); if (string(argv[1]) == "POSIX")
if ( !outfile ) {
{ posix = true;
std::cerr << "Could not open output file: " << argv[2] << std::endl; posix_outfile.open(argv[3]);
return 1; if (!posix_outfile)
} {
std::cerr << "Could not open POSIX output file: " << argv[3] << std::endl;
return 1;
}
}
else
{
posix = false;
posix_infile.open(argv[3]);
if (!posix_infile)
{
std::cerr << "Could not open POSIX input file: " << argv[3] << std::endl;
return 1;
}
}
outfile << "<html>\n" outfile.open(argv[4]);
"<head>\n" if (!outfile)
"<title>Path Decomposition Table</title>\n" {
"</head>\n" std::cerr << "Could not open output file: " << argv[2] << std::endl;
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n" return 1;
; }
do_table(); outfile << "<html>\n"
"<head>\n"
"<title>Path Decomposition Table</title>\n"
"</head>\n"
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n";
outfile << "</body>\n" do_table();
"</html>\n"
;
return 0; outfile << "</body>\n"
"</html>\n";
return 0;
} }

View File

@ -12,30 +12,31 @@
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
using std::cout; using std::cout;
using std::endl; using std::endl;
using namespace boost::filesystem; using namespace boost::filesystem;
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
# ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API" << endl; cout << "BOOST_WINDOWS_API" << endl;
# else #else
cout << "BOOST_POSIX_API" << endl; cout << "BOOST_POSIX_API" << endl;
# endif #endif
path test_dir(current_path() / "dspr_demo"); path test_dir(current_path() / "dspr_demo");
remove_all(test_dir); remove_all(test_dir);
create_directories(test_dir / "a/c/d"); create_directories(test_dir / "a/c/d");
current_path(test_dir / "a"); current_path(test_dir / "a");
create_directory_symlink("c/d", "b"); create_directory_symlink("c/d", "b");
save_string_file("name.txt", "Windows"); save_string_file("name.txt", "Windows");
save_string_file("c/name.txt", "POSIX"); save_string_file("c/name.txt", "POSIX");
current_path(test_dir); current_path(test_dir);
std::string s; std::string s;
load_string_file("a/b/../name.txt", s); load_string_file("a/b/../name.txt", s);
cout << s << endl; cout << s << endl;
return 0; return 0;
} }

View File

@ -24,162 +24,177 @@ using boost::system::error_code;
using boost::system::system_error; using boost::system::system_error;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
void report_system_error(const system_error& ex)
{ {
void report_system_error(const system_error& ex)
{
cout << " threw system_error:\n" cout << " threw system_error:\n"
<< " ex.code().value() is " << ex.code().value() << '\n' << " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n' << " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n' << " ex.what() is " << ex.what() << '\n';
; }
}
void report_filesystem_error(const system_error& ex) void report_filesystem_error(const system_error& ex)
{ {
cout << " threw filesystem_error exception:\n" cout << " threw filesystem_error exception:\n"
<< " ex.code().value() is " << ex.code().value() << '\n' << " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n' << " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n' << " ex.what() is " << ex.what() << '\n';
; }
}
void report_status(fs::file_status s) void report_status(fs::file_status s)
{ {
cout << " file_status::type() is "; cout << " file_status::type() is ";
switch (s.type()) switch (s.type())
{ {
case fs::status_error: case fs::status_error:
cout << "status_error\n"; break; cout << "status_error\n";
break;
case fs::file_not_found: case fs::file_not_found:
cout << "file_not_found\n"; break; cout << "file_not_found\n";
break;
case fs::regular_file: case fs::regular_file:
cout << "regular_file\n"; break; cout << "regular_file\n";
break;
case fs::directory_file: case fs::directory_file:
cout << "directory_file\n"; break; cout << "directory_file\n";
break;
case fs::symlink_file: case fs::symlink_file:
cout << "symlink_file\n"; break; cout << "symlink_file\n";
break;
case fs::block_file: case fs::block_file:
cout << "block_file\n"; break; cout << "block_file\n";
break;
case fs::character_file: case fs::character_file:
cout << "character_file\n"; break; cout << "character_file\n";
break;
case fs::fifo_file: case fs::fifo_file:
cout << "fifo_file\n"; break; cout << "fifo_file\n";
break;
case fs::socket_file: case fs::socket_file:
cout << "socket_file\n"; break; cout << "socket_file\n";
break;
case fs::type_unknown: case fs::type_unknown:
cout << "type_unknown\n"; break; cout << "type_unknown\n";
break;
default: default:
cout << "not a valid enumeration constant\n"; cout << "not a valid enumeration constant\n";
} }
} }
void report_error_code(const error_code& ec) void report_error_code(const error_code& ec)
{ {
cout << " ec:\n" cout << " ec:\n"
<< " value() is " << ec.value() << '\n' << " value() is " << ec.value() << '\n'
<< " category().name() is " << ec.category().name() << '\n' << " category().name() is " << ec.category().name() << '\n'
<< " message() is " << ec.message() << '\n' << " message() is " << ec.message() << '\n';
;
}
bool threw_exception;
} }
bool threw_exception;
} // namespace
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
cout << "Usage: error_demo path\n"; cout << "Usage: error_demo path\n";
return 1; return 1;
} }
error_code ec; error_code ec;
//// construct path - no error_code //// construct path - no error_code
//try { path p1(argv[1]); } //try { path p1(argv[1]); }
//catch (const system_error& ex) //catch (const system_error& ex)
//{ //{
// cout << "construct path without error_code"; // cout << "construct path without error_code";
// report_system_error(ex); // report_system_error(ex);
//} //}
//// construct path - with error_code //// construct path - with error_code
path p (argv[1]); path p(argv[1]);
fs::file_status s; fs::file_status s;
bool b (false); bool b(false);
fs::directory_iterator di; fs::directory_iterator di;
// get status - no error_code // get status - no error_code
cout << "\nstatus(\"" << p.string() << "\");\n"; cout << "\nstatus(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { s = fs::status(p); } try
catch (const system_error& ex) {
{ s = fs::status(p);
report_filesystem_error(ex); }
threw_exception = true; catch (const system_error& ex)
} {
if (!threw_exception) report_filesystem_error(ex);
cout << " Did not throw exception\n"; threw_exception = true;
report_status(s); }
if (!threw_exception)
cout << " Did not throw exception\n";
report_status(s);
// get status - with error_code // get status - with error_code
cout << "\nstatus(\"" << p.string() << "\", ec);\n"; cout << "\nstatus(\"" << p.string() << "\", ec);\n";
s = fs::status(p, ec); s = fs::status(p, ec);
report_status(s); report_status(s);
report_error_code(ec); report_error_code(ec);
// query existence - no error_code // query existence - no error_code
cout << "\nexists(\"" << p.string() << "\");\n"; cout << "\nexists(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { b = fs::exists(p); } try
catch (const system_error& ex) {
{ b = fs::exists(p);
report_filesystem_error(ex); }
threw_exception = true; catch (const system_error& ex)
} {
if (!threw_exception) report_filesystem_error(ex);
{ threw_exception = true;
cout << " Did not throw exception\n" }
<< " Returns: " << (b ? "true" : "false") << '\n'; if (!threw_exception)
} {
cout << " Did not throw exception\n"
<< " Returns: " << (b ? "true" : "false") << '\n';
}
// query existence - with error_code // query existence - with error_code
// directory_iterator - no error_code // directory_iterator - no error_code
cout << "\ndirectory_iterator(\"" << p.string() << "\");\n"; cout << "\ndirectory_iterator(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { di = fs::directory_iterator(p); } try
catch (const system_error& ex) {
{ di = fs::directory_iterator(p);
report_filesystem_error(ex); }
threw_exception = true; catch (const system_error& ex)
} {
if (!threw_exception) report_filesystem_error(ex);
{ threw_exception = true;
cout << " Did not throw exception\n" }
<< (di == fs::directory_iterator() ? " Equal" : " Not equal") if (!threw_exception)
<< " to the end iterator\n"; {
} cout << " Did not throw exception\n"
<< (di == fs::directory_iterator() ? " Equal" : " Not equal")
<< " to the end iterator\n";
}
// directory_iterator - with error_code // directory_iterator - with error_code
cout << "\ndirectory_iterator(\"" << p.string() << "\", ec);\n"; cout << "\ndirectory_iterator(\"" << p.string() << "\", ec);\n";
di = fs::directory_iterator(p, ec); di = fs::directory_iterator(p, ec);
cout << (di == fs::directory_iterator() ? " Equal" : " Not equal") cout << (di == fs::directory_iterator() ? " Equal" : " Not equal")
<< " to the end iterator\n"; << " to the end iterator\n";
report_error_code(ec); report_error_code(ec);
return 0; return 0;
} }

View File

@ -13,32 +13,32 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main( int argc, char* argv[] ) int main(int argc, char* argv[])
{ {
if ( argc != 2 ) if (argc != 2)
{ {
std::cout << "Usage: file_size path\n"; std::cout << "Usage: file_size path\n";
return 1; return 1;
} }
std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n'; std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n';
fs::path p( argv[1] ); fs::path p(argv[1]);
if ( !fs::exists( p ) ) if (!fs::exists(p))
{ {
std::cout << "not found: " << argv[1] << std::endl; std::cout << "not found: " << argv[1] << std::endl;
return 1; return 1;
} }
if ( !fs::is_regular( p ) ) if (!fs::is_regular(p))
{ {
std::cout << "not a regular file: " << argv[1] << std::endl; std::cout << "not a regular file: " << argv[1] << std::endl;
return 1; return 1;
} }
std::cout << "size of " << argv[1] << " is " << fs::file_size( p ) std::cout << "size of " << argv[1] << " is " << fs::file_size(p)
<< std::endl; << std::endl;
return 0; return 0;
} }

View File

@ -13,55 +13,54 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
using std::cout; using std::endl; using std::cout;
using std::endl;
using namespace boost::filesystem; using namespace boost::filesystem;
namespace namespace {
{
path p;
void print_boost_macros() path p;
{
void print_boost_macros()
{
std::cout << "Boost " std::cout << "Boost "
<< BOOST_VERSION / 100000 << '.' << BOOST_VERSION / 100000 << '.'
<< BOOST_VERSION / 100 % 1000 << '.' << BOOST_VERSION / 100 % 1000 << '.'
<< BOOST_VERSION % 100 << ", " << BOOST_VERSION % 100 << ", "
# ifndef _WIN64 #ifndef _WIN64
<< BOOST_COMPILER << ", " << BOOST_COMPILER << ", "
# else #else
<< BOOST_COMPILER << " with _WIN64 defined, " << BOOST_COMPILER << " with _WIN64 defined, "
# endif #endif
<< BOOST_STDLIB << ", " << BOOST_STDLIB << ", "
<< BOOST_PLATFORM << BOOST_PLATFORM
<< std::endl; << std::endl;
} }
const char* file_type_tab[] = const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file",
{ "status_error", "file_not_found", "regular_file", "directory_file", "symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file", "type_unknown" };
"type_unknown"
};
const char* file_type_c_str(enum file_type t) const char* file_type_c_str(enum file_type t)
{ {
return file_type_tab[t]; return file_type_tab[t];
} }
void show_status(file_status s, boost::system::error_code ec) void show_status(file_status s, boost::system::error_code ec)
{ {
boost::system::error_condition econd; boost::system::error_condition econd;
if (ec) if (ec)
{ {
econd = ec.default_error_condition(); econd = ec.default_error_condition();
cout << "sets ec to indicate an error:\n" cout << "sets ec to indicate an error:\n"
<< " ec.value() is " << ec.value() << '\n' << " ec.value() is " << ec.value() << '\n'
<< " ec.message() is \"" << ec.message() << "\"\n" << " ec.message() is \"" << ec.message() << "\"\n"
<< " ec.default_error_condition().value() is " << econd.value() << '\n' << " ec.default_error_condition().value() is " << econd.value() << '\n'
<< " ec.default_error_condition().message() is \"" << econd.message() << "\"\n"; << " ec.default_error_condition().message() is \"" << econd.message() << "\"\n";
} }
else else
cout << "clears ec.\n"; cout << "clears ec.\n";
cout << "s.type() is " << s.type() cout << "s.type() is " << s.type()
<< ", which is defined as \"" << file_type_c_str(s.type()) << "\"\n"; << ", which is defined as \"" << file_type_c_str(s.type()) << "\"\n";
@ -72,46 +71,46 @@ namespace
cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n"; cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n";
cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n"; cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n";
cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n"; cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n";
} }
void try_exists() void try_exists()
{ {
cout << "\nexists(" << p << ") "; cout << "\nexists(" << p << ") ";
try try
{ {
bool result = exists(p); bool result = exists(p);
cout << "is " << (result ? "true" : "false") << "\n"; cout << "is " << (result ? "true" : "false") << "\n";
} }
catch (const filesystem_error& ex) catch (const filesystem_error& ex)
{ {
cout << "throws a filesystem_error exception: " << ex.what() << "\n"; cout << "throws a filesystem_error exception: " << ex.what() << "\n";
} }
}
} }
} // namespace
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
print_boost_macros(); print_boost_macros();
if (argc < 2) if (argc < 2)
{ {
std::cout << "Usage: file_status <path>\n"; std::cout << "Usage: file_status <path>\n";
p = argv[0]; p = argv[0];
} }
else else
p = argv[1]; p = argv[1];
boost::system::error_code ec; boost::system::error_code ec;
file_status s = status(p, ec); file_status s = status(p, ec);
cout << "\nfile_status s = status(" << p << ", ec) "; cout << "\nfile_status s = status(" << p << ", ec) ";
show_status(s, ec); show_status(s, ec);
s = symlink_status(p, ec); s = symlink_status(p, ec);
cout << "\nfile_status s = symlink_status(" << p << ", ec) "; cout << "\nfile_status s = symlink_status(" << p << ", ec) ";
show_status(s, ec); show_status(s, ec);
try_exists(); try_exists();
return 0; return 0;
} }

View File

@ -13,9 +13,9 @@
#define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
# ifdef BOOST_FILESYSTEM_NARROW_ONLY #ifdef BOOST_FILESYSTEM_NARROW_ONLY
# error This compiler or standard library does not support wide-character strings or paths #error This compiler or standard library does not support wide-character strings or paths
# endif #endif
#include "mbpath.hpp" #include "mbpath.hpp"
#include <iostream> #include <iostream>
@ -25,66 +25,76 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
// we can't use boost::filesystem::copy_file() because the argument types
// differ, so provide a not-very-smart replacement.
void copy_file(const fs::wpath& from, const user::mbpath& to)
{ {
// we can't use boost::filesystem::copy_file() because the argument types fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary);
// differ, so provide a not-very-smart replacement. if (!from_file)
{
std::cout << "input open failed\n";
return;
}
void copy_file( const fs::wpath & from, const user::mbpath & to ) fs::ofstream to_file(to, std::ios_base::out | std::ios_base::binary);
{ if (!to_file)
fs::ifstream from_file( from, std::ios_base::in | std::ios_base::binary ); {
if ( !from_file ) { std::cout << "input open failed\n"; return; } std::cout << "output open failed\n";
return;
fs::ofstream to_file( to, std::ios_base::out | std::ios_base::binary ); }
if ( !to_file ) { std::cout << "output open failed\n"; return; }
char c; char c;
while ( from_file.get(c) ) while (from_file.get(c))
{ {
to_file.put(c); to_file.put(c);
if ( to_file.fail() ) { std::cout << "write error\n"; return; } if (to_file.fail())
{
std::cout << "write error\n";
return;
}
} }
if ( !from_file.eof() ) { std::cout << "read error\n"; } if (!from_file.eof())
} {
std::cout << "read error\n";
}
} }
int main( int argc, char * argv[] ) } // namespace
int main(int argc, char* argv[])
{ {
if ( argc != 2 ) if (argc != 2)
{
std::cout << "Copy files in the current directory to a target directory\n"
<< "Usage: mbcopy <target-dir>\n";
return 1;
}
// For encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc( global_loc, new fs::detail::utf8_codecvt_facet );
user::mbpath_traits::imbue( loc );
std::string target_string( argv[1] );
user::mbpath target_dir( user::mbpath_traits::to_internal( target_string ) );
if ( !fs::is_directory( target_dir ) )
{
std::cout << "Error: " << argv[1] << " is not a directory\n";
return 1;
}
for ( fs::wdirectory_iterator it( L"." );
it != fs::wdirectory_iterator(); ++it )
{
if ( fs::is_regular_file(it->status()) )
{ {
copy_file( *it, target_dir / it->path().filename() ); std::cout << "Copy files in the current directory to a target directory\n"
<< "Usage: mbcopy <target-dir>\n";
return 1;
} }
}
return 0; // For encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);
user::mbpath_traits::imbue(loc);
std::string target_string(argv[1]);
user::mbpath target_dir(user::mbpath_traits::to_internal(target_string));
if (!fs::is_directory(target_dir))
{
std::cout << "Error: " << argv[1] << " is not a directory\n";
return 1;
}
for (fs::wdirectory_iterator it(L".");
it != fs::wdirectory_iterator(); ++it)
{
if (fs::is_regular_file(it->status()))
{
copy_file(*it, target_dir / it->path().filename());
}
}
return 0;
} }

View File

@ -9,9 +9,9 @@
// See Boost.Filesystem home page at http://www.boost.org/libs/filesystem // See Boost.Filesystem home page at http://www.boost.org/libs/filesystem
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
# ifdef BOOST_FILESYSTEM_NARROW_ONLY #ifdef BOOST_FILESYSTEM_NARROW_ONLY
# error This compiler or standard library does not support wide-character strings or paths #error This compiler or standard library does not support wide-character strings or paths
# endif #endif
#include "mbpath.hpp" #include "mbpath.hpp"
#include <boost/system/system_error.hpp> #include <boost/system/system_error.hpp>
@ -19,62 +19,60 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
{
// ISO C calls this "the locale-specific native environment":
std::locale loc("");
const std::codecvt<wchar_t, char, std::mbstate_t> * // ISO C calls this "the locale-specific native environment":
cvt( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> > std::locale loc("");
( loc ) );
const std::codecvt< wchar_t, char, std::mbstate_t >*
cvt(&std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc));
} // namespace
namespace user {
mbpath_traits::external_string_type
mbpath_traits::to_external(const mbpath& ph, const internal_string_type& src)
{
std::size_t work_size(cvt->max_length() * (src.size() + 1));
boost::scoped_array< char > work(new char[work_size]);
std::mbstate_t state;
const internal_string_type::value_type* from_next;
external_string_type::value_type* to_next;
if (cvt->out(
state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_external conversion error",
ph, boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = '\0';
return external_string_type(work.get());
} }
namespace user mbpath_traits::internal_string_type
mbpath_traits::to_internal(const external_string_type& src)
{ {
mbpath_traits::external_string_type std::size_t work_size(src.size() + 1);
mbpath_traits::to_external( const mbpath & ph, boost::scoped_array< wchar_t > work(new wchar_t[work_size]);
const internal_string_type & src )
{
std::size_t work_size( cvt->max_length() * (src.size()+1) );
boost::scoped_array<char> work( new char[ work_size ] );
std::mbstate_t state; std::mbstate_t state;
const internal_string_type::value_type * from_next; const external_string_type::value_type* from_next;
external_string_type::value_type * to_next; internal_string_type::value_type* to_next;
if ( cvt->out( if (cvt->in(
state, src.c_str(), src.c_str()+src.size(), from_next, work.get(), state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get()+work_size, to_next ) != std::codecvt_base::ok ) work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception<fs::basic_filesystem_error<mbpath> >( boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error<mbpath>( fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_external conversion error", "user::mbpath::to_internal conversion error",
ph, boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) ); boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = '\0'; *to_next = L'\0';
return external_string_type( work.get() ); return internal_string_type(work.get());
} }
mbpath_traits::internal_string_type void mbpath_traits::imbue(const std::locale& new_loc)
mbpath_traits::to_internal( const external_string_type & src ) {
{
std::size_t work_size( src.size()+1 );
boost::scoped_array<wchar_t> work( new wchar_t[ work_size ] );
std::mbstate_t state;
const external_string_type::value_type * from_next;
internal_string_type::value_type * to_next;
if ( cvt->in(
state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
work.get()+work_size, to_next ) != std::codecvt_base::ok )
boost::throw_exception<fs::basic_filesystem_error<mbpath> >(
fs::basic_filesystem_error<mbpath>(
"user::mbpath::to_internal conversion error",
boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) );
*to_next = L'\0';
return internal_string_type( work.get() );
}
void mbpath_traits::imbue( const std::locale & new_loc )
{
loc = new_loc; loc = new_loc;
cvt = &std::use_facet cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc);
<std::codecvt<wchar_t, char, std::mbstate_t> >( loc ); }
}
} // namespace user } // namespace user

View File

@ -10,35 +10,38 @@
// See http://../doc/path.htm#mbpath for more information // See http://../doc/path.htm#mbpath for more information
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <cwchar> // for std::mbstate_t #include <cwchar> // for std::mbstate_t
#include <string> #include <string>
#include <locale> #include <locale>
namespace user namespace user {
struct mbpath_traits;
typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath;
struct mbpath_traits
{ {
struct mbpath_traits;
typedef boost::filesystem::basic_path<std::wstring, mbpath_traits> mbpath;
struct mbpath_traits
{
typedef std::wstring internal_string_type; typedef std::wstring internal_string_type;
typedef std::string external_string_type; typedef std::string external_string_type;
static external_string_type to_external( const mbpath & ph, static external_string_type to_external(const mbpath& ph, const internal_string_type& src);
const internal_string_type & src );
static internal_string_type to_internal( const external_string_type & src ); static internal_string_type to_internal(const external_string_type& src);
static void imbue(const std::locale& loc);
};
static void imbue( const std::locale & loc );
};
} // namespace user } // namespace user
namespace boost namespace boost {
namespace filesystem {
template<>
struct is_basic_path< user::mbpath >
{ {
namespace filesystem static const bool value = true;
{ };
template<> struct is_basic_path<user::mbpath>
{ static const bool value = true; }; } // namespace filesystem
} } // namespace boost
}

View File

@ -9,74 +9,78 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace std; using namespace std;
using namespace boost::filesystem; using namespace boost::filesystem;
const char * say_what(bool b) { return b ? "true" : "false"; } const char* say_what(bool b)
{
return b ? "true" : "false";
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
cout << "Usage: path_info path-element [path-element...]\n" cout << "Usage: path_info path-element [path-element...]\n"
"Composes a path via operator/= from one or more path-element arguments\n" "Composes a path via operator/= from one or more path-element arguments\n"
"Example: path_info foo/bar baz\n" "Example: path_info foo/bar baz\n"
# ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
" would report info about the composed path foo/bar/baz\n"; " would report info about the composed path foo/bar/baz\n";
# else // BOOST_WINDOWS_API #else // BOOST_WINDOWS_API
" would report info about the composed path foo/bar\\baz\n"; " would report info about the composed path foo/bar\\baz\n";
# endif #endif
return 1; return 1;
} }
path p; path p;
for (; argc > 1; --argc, ++argv) for (; argc > 1; --argc, ++argv)
p /= argv[1]; // compose path p from the command line arguments p /= argv[1]; // compose path p from the command line arguments
cout << "\ncomposed path:\n"; cout << "\ncomposed path:\n";
cout << " operator<<()---------: " << p << "\n"; cout << " operator<<()---------: " << p << "\n";
cout << " make_preferred()-----: " << p.make_preferred() << "\n"; cout << " make_preferred()-----: " << p.make_preferred() << "\n";
cout << "\nelements:\n"; cout << "\nelements:\n";
for (auto element : p) for (auto element : p)
cout << " " << element << '\n'; cout << " " << element << '\n';
cout << "\nobservers, native format:" << endl; cout << "\nobservers, native format:" << endl;
# ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
cout << " native()-------------: " << p.native() << endl; cout << " native()-------------: " << p.native() << endl;
cout << " c_str()--------------: " << p.c_str() << endl; cout << " c_str()--------------: " << p.c_str() << endl;
# else // BOOST_WINDOWS_API #else // BOOST_WINDOWS_API
wcout << L" native()-------------: " << p.native() << endl; wcout << L" native()-------------: " << p.native() << endl;
wcout << L" c_str()--------------: " << p.c_str() << endl; wcout << L" c_str()--------------: " << p.c_str() << endl;
# endif #endif
cout << " string()-------------: " << p.string() << endl; cout << " string()-------------: " << p.string() << endl;
wcout << L" wstring()------------: " << p.wstring() << endl; wcout << L" wstring()------------: " << p.wstring() << endl;
cout << "\nobservers, generic format:\n"; cout << "\nobservers, generic format:\n";
cout << " generic_string()-----: " << p.generic_string() << endl; cout << " generic_string()-----: " << p.generic_string() << endl;
wcout << L" generic_wstring()----: " << p.generic_wstring() << endl; wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
cout << "\ndecomposition:\n"; cout << "\ndecomposition:\n";
cout << " root_name()----------: " << p.root_name() << '\n'; cout << " root_name()----------: " << p.root_name() << '\n';
cout << " root_directory()-----: " << p.root_directory() << '\n'; cout << " root_directory()-----: " << p.root_directory() << '\n';
cout << " root_path()----------: " << p.root_path() << '\n'; cout << " root_path()----------: " << p.root_path() << '\n';
cout << " relative_path()------: " << p.relative_path() << '\n'; cout << " relative_path()------: " << p.relative_path() << '\n';
cout << " parent_path()--------: " << p.parent_path() << '\n'; cout << " parent_path()--------: " << p.parent_path() << '\n';
cout << " filename()-----------: " << p.filename() << '\n'; cout << " filename()-----------: " << p.filename() << '\n';
cout << " stem()---------------: " << p.stem() << '\n'; cout << " stem()---------------: " << p.stem() << '\n';
cout << " extension()----------: " << p.extension() << '\n'; cout << " extension()----------: " << p.extension() << '\n';
cout << "\nquery:\n"; cout << "\nquery:\n";
cout << " empty()--------------: " << say_what(p.empty()) << '\n'; cout << " empty()--------------: " << say_what(p.empty()) << '\n';
cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n'; cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n'; cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n'; cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n'; cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n'; cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n'; cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n'; cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n'; cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
cout << " has_extension()------: " << say_what(p.has_extension()) << '\n'; cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
return 0; return 0;
} }

View File

@ -12,10 +12,10 @@
// As an example program, we don't want to use any deprecated features // As an example program, we don't want to use any deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
@ -27,66 +27,66 @@ namespace fs = boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
fs::path p(fs::current_path()); fs::path p(fs::current_path());
if (argc > 1) if (argc > 1)
p = fs::system_complete(argv[1]); p = fs::system_complete(argv[1]);
else else
std::cout << "\nusage: simple_ls [path]" << std::endl; std::cout << "\nusage: simple_ls [path]" << std::endl;
unsigned long file_count = 0; unsigned long file_count = 0;
unsigned long dir_count = 0; unsigned long dir_count = 0;
unsigned long other_count = 0; unsigned long other_count = 0;
unsigned long err_count = 0; unsigned long err_count = 0;
if (!fs::exists(p)) if (!fs::exists(p))
{
std::cout << "\nNot found: " << p << std::endl;
return 1;
}
if (fs::is_directory(p))
{
std::cout << "\nIn directory: " << p << "\n\n";
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_itr(p);
dir_itr != end_iter;
++dir_itr)
{ {
try std::cout << "\nNot found: " << p << std::endl;
{ return 1;
if (fs::is_directory(dir_itr->status()))
{
++dir_count;
std::cout << dir_itr->path().filename() << " [directory]\n";
}
else if (fs::is_regular_file(dir_itr->status()))
{
++file_count;
std::cout << dir_itr->path().filename() << "\n";
}
else
{
++other_count;
std::cout << dir_itr->path().filename() << " [other]\n";
}
}
catch (const std::exception & ex)
{
++err_count;
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
} }
std::cout << "\n" << file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";
}
else // must be a file
{
std::cout << "\nFound: " << p << "\n";
}
return 0; if (fs::is_directory(p))
{
std::cout << "\nIn directory: " << p << "\n\n";
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_itr(p);
dir_itr != end_iter;
++dir_itr)
{
try
{
if (fs::is_directory(dir_itr->status()))
{
++dir_count;
std::cout << dir_itr->path().filename() << " [directory]\n";
}
else if (fs::is_regular_file(dir_itr->status()))
{
++file_count;
std::cout << dir_itr->path().filename() << "\n";
}
else
{
++other_count;
std::cout << dir_itr->path().filename() << " [other]\n";
}
}
catch (const std::exception& ex)
{
++err_count;
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
}
std::cout << "\n"
<< file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";
}
else // must be a file
{
std::cout << "\nFound: " << p << "\n";
}
return 0;
} }

View File

@ -12,20 +12,20 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
std::cout << "Usage: stems <path>\n"; std::cout << "Usage: stems <path>\n";
return 1; return 1;
} }
boost::filesystem::path p(argv[1]), name(p.filename()); boost::filesystem::path p(argv[1]), name(p.filename());
for(;;) for (;;)
{ {
std::cout << "filename " << name << " has stem " << name.stem() std::cout << "filename " << name << " has stem " << name.stem()
<< " and extension " << name.extension() << "\n"; << " and extension " << name.extension() << "\n";
if (name.stem().empty() || name.extension().empty()) if (name.stem().empty() || name.extension().empty())
return 0; return 0;
name = name.stem(); name = name.stem();
} }
} }

View File

@ -14,26 +14,26 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
typedef std::basic_string<TCHAR> tstring; typedef std::basic_string< TCHAR > tstring;
void func( const fs::path & p ) void func(fs::path const& p)
{ {
assert( fs::exists( p ) ); assert(fs::exists(p));
} }
int main() int main()
{ {
// get a path that is known to exist // get a path that is known to exist
fs::path cp = fs::current_path(); fs::path cp = fs::current_path();
// demo: get tstring from the path // demo: get tstring from the path
tstring cp_as_tstring = cp.string<tstring>(); tstring cp_as_tstring = cp.string< tstring >();
// demo: pass tstring to filesystem function taking path // demo: pass tstring to filesystem function taking path
assert( fs::exists( cp_as_tstring ) ); assert(fs::exists(cp_as_tstring));
// demo: pass tstring to user function taking path // demo: pass tstring to user function taking path
func( cp_as_tstring ); func(cp_as_tstring);
return 0; return 0;
} }

View File

@ -9,15 +9,16 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
std::cout << "Usage: tut0 path\n"; std::cout << "Usage: tut0 path\n";
return 1; return 1;
} }
std::cout << argv[1] << '\n'; std::cout << argv[1] << '\n';
return 0; return 0;
} }

View File

@ -9,15 +9,16 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
std::cout << "Usage: tut1 path\n"; std::cout << "Usage: tut1 path\n";
return 1; return 1;
} }
std::cout << argv[1] << " " << file_size(argv[1]) << '\n'; std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0; return 0;
} }

View File

@ -9,32 +9,31 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace std; using namespace std;
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
cout << "Usage: tut2 path\n"; cout << "Usage: tut2 path\n";
return 1; return 1;
} }
path p(argv[1]); // avoid repeated path construction below path p(argv[1]); // avoid repeated path construction below
if (exists(p)) // does path p actually exist?
{
if (is_regular_file(p)) // is path p a regular file?
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p)) // is path p a directory?
cout << p << " is a directory\n";
if (exists(p)) // does path p actually exist?
{
if (is_regular_file(p)) // is path p a regular file?
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p)) // is path p a directory?
cout << p << " is a directory\n";
else
cout << p << " exists, but is not a regular file or directory\n";
}
else else
cout << p << " exists, but is not a regular file or directory\n"; cout << p << " does not exist\n";
}
else
cout << p << " does not exist\n";
return 0; return 0;
} }

View File

@ -9,44 +9,45 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using std::cout; using std::cout;
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{
cout << "Usage: tut3 path\n";
return 1;
}
path p (argv[1]);
try
{
if (exists(p))
{ {
if (is_regular_file(p)) cout << "Usage: tut3 path\n";
cout << p << " size is " << file_size(p) << '\n'; return 1;
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (const directory_entry& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
} }
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex) path p(argv[1]);
{
cout << ex.what() << '\n';
}
return 0; try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (directory_entry const& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
} }

View File

@ -11,51 +11,52 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using std::cout; using std::cout;
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{
cout << "Usage: tut4 path\n";
return 1;
}
path p (argv[1]);
try
{
if (exists(p))
{ {
if (is_regular_file(p)) cout << "Usage: tut4 path\n";
cout << p << " size is " << file_size(p) << '\n'; return 1;
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
std::vector<path> v;
for (auto&& x : directory_iterator(p))
v.push_back(x.path());
std::sort(v.begin(), v.end());
for (auto&& x : v)
cout << " " << x.filename() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
} }
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex) path p(argv[1]);
{
cout << ex.what() << '\n';
}
return 0; try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
std::vector< path > v;
for (auto&& x : directory_iterator(p))
v.push_back(x.path());
std::sort(v.begin(), v.end());
for (auto&& x : v)
cout << " " << x.filename() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
} }

View File

@ -10,43 +10,60 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <string> #include <string>
#include <list> #include <list>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main() int main()
{ {
// \u263A is "Unicode WHITE SMILING FACE = have a nice day!" // \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
std::string narrow_string ("smile2"); std::string narrow_string("smile2");
std::wstring wide_string (L"smile2\u263A"); std::wstring wide_string(L"smile2\u263A");
std::list<char> narrow_list; std::list< char > narrow_list;
narrow_list.push_back('s'); narrow_list.push_back('s');
narrow_list.push_back('m'); narrow_list.push_back('m');
narrow_list.push_back('i'); narrow_list.push_back('i');
narrow_list.push_back('l'); narrow_list.push_back('l');
narrow_list.push_back('e'); narrow_list.push_back('e');
narrow_list.push_back('3'); narrow_list.push_back('3');
std::list<wchar_t> wide_list; std::list< wchar_t > wide_list;
wide_list.push_back(L's'); wide_list.push_back(L's');
wide_list.push_back(L'm'); wide_list.push_back(L'm');
wide_list.push_back(L'i'); wide_list.push_back(L'i');
wide_list.push_back(L'l'); wide_list.push_back(L'l');
wide_list.push_back(L'e'); wide_list.push_back(L'e');
wide_list.push_back(L'3'); wide_list.push_back(L'3');
wide_list.push_back(L'\u263A'); wide_list.push_back(L'\u263A');
{ fs::ofstream f("smile"); } {
{ fs::ofstream f(L"smile\u263A"); } fs::ofstream f("smile");
{ fs::ofstream f(narrow_string); } }
{ fs::ofstream f(wide_string); } {
{ fs::ofstream f(narrow_list); } fs::ofstream f(L"smile\u263A");
{ fs::ofstream f(wide_list); } }
narrow_list.pop_back(); {
narrow_list.push_back('4'); fs::ofstream f(narrow_string);
wide_list.pop_back(); }
wide_list.pop_back(); {
wide_list.push_back(L'4'); fs::ofstream f(wide_string);
wide_list.push_back(L'\u263A'); }
{ fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); } {
{ fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); } fs::ofstream f(narrow_list);
}
{
fs::ofstream f(wide_list);
}
narrow_list.pop_back();
narrow_list.push_back('4');
wide_list.pop_back();
wide_list.pop_back();
wide_list.push_back(L'4');
wide_list.push_back(L'\u263A');
{
fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end()));
}
{
fs::ofstream f(fs::path(wide_list.begin(), wide_list.end()));
}
return 0; return 0;
} }

View File

@ -10,39 +10,39 @@
#include <iostream> #include <iostream>
#include <exception> #include <exception>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{
std::cout << "Usage: tut6a path\n";
return 1;
}
try
{
for (recursive_directory_iterator it (argv[1]);
it != recursive_directory_iterator();
++it)
{ {
if (it.level() > 1) std::cout << "Usage: tut6a path\n";
it.pop(); return 1;
else
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
std::cout << it->path() << '\n';
}
} }
}
catch (const std::exception& ex) try
{ {
std::cout << "************* exception *****************\n"; for (recursive_directory_iterator it(argv[1]);
std::cout << ex.what() << '\n'; it != recursive_directory_iterator();
} ++it)
{
if (it.level() > 1)
it.pop();
else
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
return 0; std::cout << it->path() << '\n';
}
}
}
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';
}
return 0;
} }

View File

@ -10,41 +10,43 @@
#include <iostream> #include <iostream>
#include <exception> #include <exception>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{
std::cout << "Usage: tut6b path\n";
return 1;
}
try
{
for (recursive_directory_iterator it (argv[1]);
it != recursive_directory_iterator();
)
{ {
for (int i = 0; i <= it.level(); ++i) std::cout << "Usage: tut6b path\n";
std::cout << " "; return 1;
std::cout << it->path() << '\n';
try { ++it; }
catch (const filesystem_error& ex)
{
std::cout << "************* filesystem_error *****************\n";
std::cout << ex.what() << '\n';
}
} }
}
catch (const std::exception& ex) try
{ {
std::cout << "************* exception *****************\n"; for (recursive_directory_iterator it(argv[1]);
std::cout << ex.what() << '\n'; it != recursive_directory_iterator();)
} {
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
return 0; std::cout << it->path() << '\n';
try
{
++it;
}
catch (filesystem_error& ex)
{
std::cout << "************* filesystem_error *****************\n";
std::cout << ex.what() << '\n';
}
}
}
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';
}
return 0;
} }

View File

@ -17,24 +17,23 @@ using namespace boost::system;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
{ {
std::cout << "Usage: tut6c path\n"; std::cout << "Usage: tut6c path\n";
return 1; return 1;
} }
error_code ec; error_code ec;
for (recursive_directory_iterator it (argv[1], ec); for (recursive_directory_iterator it(argv[1], ec);
it != recursive_directory_iterator(); it != recursive_directory_iterator();)
) {
{ for (int i = 0; i <= it.level(); ++i)
for (int i = 0; i <= it.level(); ++i) std::cout << " ";
std::cout << " ";
std::cout << it->path() << '\n'; std::cout << it->path() << '\n';
it.increment(ec); it.increment(ec);
} }
return 0; return 0;
} }

View File

@ -12,13 +12,13 @@
#ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP #ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP
#define BOOST_FILESYSTEM_FILESYSTEM_HPP #define BOOST_FILESYSTEM_FILESYSTEM_HPP
# include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
# include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
# include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
# include <boost/filesystem/directory.hpp> #include <boost/filesystem/directory.hpp>
# include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
# include <boost/filesystem/file_status.hpp> #include <boost/filesystem/file_status.hpp>
# include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
# include <boost/filesystem/string_file.hpp> #include <boost/filesystem/string_file.hpp>
#endif // BOOST_FILESYSTEM_FILESYSTEM_HPP #endif // BOOST_FILESYSTEM_FILESYSTEM_HPP

View File

@ -12,29 +12,29 @@
#ifndef BOOST_FILESYSTEM3_CONFIG_HPP #ifndef BOOST_FILESYSTEM3_CONFIG_HPP
#define BOOST_FILESYSTEM3_CONFIG_HPP #define BOOST_FILESYSTEM3_CONFIG_HPP
# if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3 #if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
# error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3 #error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
# endif #endif
# if !defined(BOOST_FILESYSTEM_VERSION) #if !defined(BOOST_FILESYSTEM_VERSION)
# define BOOST_FILESYSTEM_VERSION 3 #define BOOST_FILESYSTEM_VERSION 3
# endif #endif
#define BOOST_FILESYSTEM_I18N // aid users wishing to compile several versions #define BOOST_FILESYSTEM_I18N // aid users wishing to compile several versions
// This header implements separate compilation features as described in // This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html // http://www.boost.org/more/separate_compilation.html
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API #include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
#include <boost/detail/workaround.hpp> #include <boost/detail/workaround.hpp>
// BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------// // BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------//
# ifdef BOOST_FILESYSTEM_SOURCE #ifdef BOOST_FILESYSTEM_SOURCE
# define BOOST_FILESYSTEM_DEPRECATED #define BOOST_FILESYSTEM_DEPRECATED
# undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined #undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined
# endif #endif
// throw an exception ----------------------------------------------------------------// // throw an exception ----------------------------------------------------------------//
// //
@ -46,50 +46,48 @@
#define BOOST_FILESYSTEM_THROW(EX) throw EX #define BOOST_FILESYSTEM_THROW(EX) throw EX
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
// This header implements separate compilation features as described in // This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html // http://www.boost.org/more/separate_compilation.html
// normalize macros ------------------------------------------------------------------// // normalize macros ------------------------------------------------------------------//
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) \ #if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) && !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK) #define BOOST_FILESYSTEM_STATIC_LINK
# define BOOST_FILESYSTEM_STATIC_LINK
#endif #endif
#if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_FILESYSTEM_DYN_LINK) #if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_FILESYSTEM_DYN_LINK #define BOOST_FILESYSTEM_DYN_LINK
#elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) #elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK)
# define BOOST_FILESYSTEM_STATIC_LINK #define BOOST_FILESYSTEM_STATIC_LINK
#endif #endif
#if defined(BOOST_FILESYSTEM_DYN_LINK) && defined(BOOST_FILESYSTEM_STATIC_LINK) #if defined(BOOST_FILESYSTEM_DYN_LINK) && defined(BOOST_FILESYSTEM_STATIC_LINK)
# error Must not define both BOOST_FILESYSTEM_DYN_LINK and BOOST_FILESYSTEM_STATIC_LINK #error Must not define both BOOST_FILESYSTEM_DYN_LINK and BOOST_FILESYSTEM_STATIC_LINK
#endif #endif
#if defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB) #if defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
# define BOOST_FILESYSTEM_NO_LIB #define BOOST_FILESYSTEM_NO_LIB
#endif #endif
// enable dynamic linking ------------------------------------------------------------// // enable dynamic linking ------------------------------------------------------------//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK) #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# if defined(BOOST_FILESYSTEM_SOURCE) #if defined(BOOST_FILESYSTEM_SOURCE)
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT #define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
# endif
#else #else
# define BOOST_FILESYSTEM_DECL #define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
#endif
#else
#define BOOST_FILESYSTEM_DECL
#endif #endif
// enable automatic library variant selection ----------------------------------------// // enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) \ #if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
&& !defined(BOOST_FILESYSTEM_NO_LIB)
// //
// Set the name of our library, this will get undef'ed by auto_link.hpp // Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it: // once it's done with it:
@ -99,12 +97,12 @@
// If we're importing code from a dll, then tell auto_link.hpp about it: // If we're importing code from a dll, then tell auto_link.hpp about it:
// //
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK) #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_DYN_LINK #define BOOST_DYN_LINK
#endif #endif
// //
// And include the header that does the work: // And include the header that does the work:
// //
#include <boost/config/auto_link.hpp> #include <boost/config/auto_link.hpp>
#endif // auto-linking disabled #endif // auto-linking disabled
#endif // BOOST_FILESYSTEM3_CONFIG_HPP #endif // BOOST_FILESYSTEM3_CONFIG_HPP

View File

@ -15,44 +15,42 @@
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost namespace boost {
namespace filesystem {
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline std::string extension(const path& p)
{ {
namespace filesystem return p.extension().string();
{ }
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED inline std::string basename(const path& p)
{
return p.stem().string();
}
inline std::string extension(const path & p) inline path change_extension(const path& p, const path& new_extension)
{ {
return p.extension().string(); path new_p(p);
} new_p.replace_extension(new_extension);
return new_p;
}
inline std::string basename(const path & p) #endif
{
return p.stem().string();
}
inline path change_extension( const path & p, const path & new_extension ) } // namespace filesystem
{
path new_p( p );
new_p.replace_extension( new_extension );
return new_p;
}
# endif
} // namespace filesystem
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP #endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP

View File

@ -20,25 +20,23 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <cstdlib> #include <cstdlib>
namespace boost namespace boost {
namespace detail {
inline const char* macro_value(const char* name, const char* value)
{ {
namespace detail static const char* no_value = "[no value]";
{ static const char* not_defined = "[not defined]";
inline const char* macro_value(const char* name, const char* value)
{
static const char* no_value = "[no value]";
static const char* not_defined = "[not defined]";
BOOST_ASSERT_MSG(name, "name argument must not be a null pointer"); BOOST_ASSERT_MSG(name, "name argument must not be a null pointer");
BOOST_ASSERT_MSG(value, "value argument must not be a null pointer"); BOOST_ASSERT_MSG(value, "value argument must not be a null pointer");
return strcmp(name, value + 1) return strcmp(name, value + 1) ? ((*value && *(value + 1)) ? (value + 1) : no_value) : not_defined; // name == value+1 so the macro is not defined
? ((*value && *(value+1)) ? (value+1) : no_value) }
: not_defined; // name == value+1 so the macro is not defined
} } // namespace detail
} // detail } // namespace boost
} // boost
#define BOOST_MACRO_VALUE(X) boost::detail::macro_value(#X, BOOST_STRINGIZE(=X)) #define BOOST_MACRO_VALUE(X) boost::detail::macro_value(#X, BOOST_STRINGIZE(=X))
#endif // BOOST_FILESYSTEM_MACRO_VALUE_HPP #endif // BOOST_FILESYSTEM_MACRO_VALUE_HPP

View File

@ -10,9 +10,14 @@
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \ #define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace filesystem { namespace detail { namespace boost { \
namespace filesystem { \
namespace detail {
#define BOOST_UTF8_END_NAMESPACE }}} #define BOOST_UTF8_END_NAMESPACE \
} \
} \
}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL #define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.hpp> #include <boost/detail/utf8_codecvt_facet.hpp>

File diff suppressed because it is too large Load Diff

View File

@ -13,9 +13,9 @@
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
@ -31,9 +31,9 @@
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
#pragma warning(push) #pragma warning(push)
// 'm_A' : class 'A' needs to have dll-interface to be used by clients of class 'B' // 'm_A' : class 'A' needs to have dll-interface to be used by clients of class 'B'
#pragma warning(disable: 4251) #pragma warning(disable : 4251)
// non dll-interface class 'A' used as base for dll-interface class 'B' // non dll-interface class 'A' used as base for dll-interface class 'B'
#pragma warning(disable: 4275) #pragma warning(disable : 4275)
#endif #endif
namespace boost { namespace boost {
@ -46,47 +46,53 @@ namespace filesystem {
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
class BOOST_SYMBOL_VISIBLE filesystem_error : class BOOST_SYMBOL_VISIBLE filesystem_error :
public system::system_error public system::system_error
{ {
// see http://www.boost.org/more/error_handling.html for design rationale // see http://www.boost.org/more/error_handling.html for design rationale
public: public:
BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, system::error_code ec); BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, system::error_code ec);
BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec); BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec);
BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec); BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec);
BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that); BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that);
BOOST_FILESYSTEM_DECL filesystem_error& operator= (filesystem_error const& that); BOOST_FILESYSTEM_DECL filesystem_error& operator=(filesystem_error const& that);
BOOST_FILESYSTEM_DECL ~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW; BOOST_FILESYSTEM_DECL ~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW;
const path& path1() const BOOST_NOEXCEPT const path& path1() const BOOST_NOEXCEPT
{ {
return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path(); return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path();
} }
const path& path2() const BOOST_NOEXCEPT const path& path2() const BOOST_NOEXCEPT
{ {
return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path(); return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path();
} }
BOOST_FILESYSTEM_DECL const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE; BOOST_FILESYSTEM_DECL const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE;
private: private:
BOOST_FILESYSTEM_DECL static const path& get_empty_path() BOOST_NOEXCEPT; BOOST_FILESYSTEM_DECL static const path& get_empty_path() BOOST_NOEXCEPT;
private: private:
struct impl : struct impl :
public boost::intrusive_ref_counter< impl > public boost::intrusive_ref_counter< impl >
{ {
path m_path1; // may be empty() path m_path1; // may be empty()
path m_path2; // may be empty() path m_path2; // may be empty()
std::string m_what; // not built until needed std::string m_what; // not built until needed
BOOST_DEFAULTED_FUNCTION(impl(), {}) BOOST_DEFAULTED_FUNCTION(impl(), {})
explicit impl(path const& path1) : m_path1(path1) {} explicit impl(path const& path1) :
impl(path const& path1, path const& path2) : m_path1(path1), m_path2(path2) {} m_path1(path1)
}; {
boost::intrusive_ptr< impl > m_imp_ptr; }
impl(path const& path1, path const& path2) :
m_path1(path1), m_path2(path2)
{
}
};
boost::intrusive_ptr< impl > m_imp_ptr;
}; };
} // namespace filesystem } // namespace filesystem
@ -97,4 +103,5 @@ private:
#endif #endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_EXCEPTION_HPP #endif // BOOST_FILESYSTEM3_EXCEPTION_HPP

View File

@ -18,12 +18,11 @@
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <boost/detail/bitmask.hpp> #include <boost/detail/bitmask.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
@ -39,24 +38,24 @@ namespace filesystem {
enum file_type enum file_type
{ {
status_error, status_error,
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
status_unknown = status_error, status_unknown = status_error,
# endif #endif
file_not_found, file_not_found,
regular_file, regular_file,
directory_file, directory_file,
// the following may not apply to some operating systems or file systems // the following may not apply to some operating systems or file systems
symlink_file, symlink_file,
block_file, block_file,
character_file, character_file,
fifo_file, fifo_file,
socket_file, socket_file,
reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
type_unknown, // file does exist, but isn't one of the above types or type_unknown, // file does exist, but isn't one of the above types or
// we don't have strong enough permission to find its type // we don't have strong enough permission to find its type
_detail_directory_symlink // internal use only; never exposed to users _detail_directory_symlink // internal use only; never exposed to users
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
@ -65,58 +64,58 @@ enum file_type
enum perms enum perms
{ {
no_perms = 0, // file_not_found is no_perms rather than perms_not_known no_perms = 0, // file_not_found is no_perms rather than perms_not_known
// POSIX equivalent macros given in comments. // POSIX equivalent macros given in comments.
// Values are from POSIX and are given in octal per the POSIX standard. // Values are from POSIX and are given in octal per the POSIX standard.
// permission bits // permission bits
owner_read = 0400, // S_IRUSR, Read permission, owner owner_read = 0400, // S_IRUSR, Read permission, owner
owner_write = 0200, // S_IWUSR, Write permission, owner owner_write = 0200, // S_IWUSR, Write permission, owner
owner_exe = 0100, // S_IXUSR, Execute/search permission, owner owner_exe = 0100, // S_IXUSR, Execute/search permission, owner
owner_all = 0700, // S_IRWXU, Read, write, execute/search by owner owner_all = 0700, // S_IRWXU, Read, write, execute/search by owner
group_read = 040, // S_IRGRP, Read permission, group group_read = 040, // S_IRGRP, Read permission, group
group_write = 020, // S_IWGRP, Write permission, group group_write = 020, // S_IWGRP, Write permission, group
group_exe = 010, // S_IXGRP, Execute/search permission, group group_exe = 010, // S_IXGRP, Execute/search permission, group
group_all = 070, // S_IRWXG, Read, write, execute/search by group group_all = 070, // S_IRWXG, Read, write, execute/search by group
others_read = 04, // S_IROTH, Read permission, others others_read = 04, // S_IROTH, Read permission, others
others_write = 02, // S_IWOTH, Write permission, others others_write = 02, // S_IWOTH, Write permission, others
others_exe = 01, // S_IXOTH, Execute/search permission, others others_exe = 01, // S_IXOTH, Execute/search permission, others
others_all = 07, // S_IRWXO, Read, write, execute/search by others others_all = 07, // S_IRWXO, Read, write, execute/search by others
all_all = 0777, // owner_all|group_all|others_all all_all = 0777, // owner_all|group_all|others_all
// other POSIX bits // other POSIX bits
set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
sticky_bit = 01000, // S_ISVTX, sticky_bit = 01000, // S_ISVTX,
// (POSIX XSI) On directories, restricted deletion flag // (POSIX XSI) On directories, restricted deletion flag
// (V7) 'sticky bit': save swapped text even after use // (V7) 'sticky bit': save swapped text even after use
// (SunOS) On non-directories: don't cache this file // (SunOS) On non-directories: don't cache this file
// (SVID-v4.2) On directories: restricted deletion flag // (SVID-v4.2) On directories: restricted deletion flag
// Also see http://en.wikipedia.org/wiki/Sticky_bit // Also see http://en.wikipedia.org/wiki/Sticky_bit
perms_mask = 07777, // all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit perms_mask = 07777, // all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit
perms_not_known = 0xFFFF, // present when directory_entry cache not loaded perms_not_known = 0xFFFF, // present when directory_entry cache not loaded
// options for permissions() function // options for permissions() function
add_perms = 0x1000, // adds the given permission bits to the current bits add_perms = 0x1000, // adds the given permission bits to the current bits
remove_perms = 0x2000, // removes the given permission bits from the current bits; remove_perms = 0x2000, // removes the given permission bits from the current bits;
// choose add_perms or remove_perms, not both; if neither add_perms // choose add_perms or remove_perms, not both; if neither add_perms
// nor remove_perms is given, replace the current bits with // nor remove_perms is given, replace the current bits with
// the given bits. // the given bits.
symlink_perms = 0x4000, // on POSIX, don't resolve symlinks; implied on Windows symlink_perms = 0x4000, // on POSIX, don't resolve symlinks; implied on Windows
// BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values // BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values
_detail_extend_perms_32_1 = 0x7fffffff, _detail_extend_perms_32_1 = 0x7fffffff,
_detail_extend_perms_32_2 = -0x7fffffff-1 _detail_extend_perms_32_2 = -0x7fffffff - 1
}; };
BOOST_BITMASK(perms) BOOST_BITMASK(perms)
@ -128,110 +127,125 @@ BOOST_BITMASK(perms)
class file_status class file_status
{ {
public: public:
BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
m_value(status_error), m_perms(perms_not_known) m_value(status_error),
{ m_perms(perms_not_known)
} {
explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT : }
m_value(v), m_perms(perms_not_known) explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT :
{ m_value(v),
} m_perms(perms_not_known)
BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT : {
m_value(v), m_perms(prms) }
{ BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT :
} m_value(v),
m_perms(prms)
{
}
// As of October 2015 the interaction between noexcept and =default is so troublesome // As of October 2015 the interaction between noexcept and =default is so troublesome
// for VC++, GCC, and probably other compilers, that =default is not used with noexcept // for VC++, GCC, and probably other compilers, that =default is not used with noexcept
// functions. GCC is not even consistent for the same release on different platforms. // functions. GCC is not even consistent for the same release on different platforms.
BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT :
m_value(rhs.m_value), m_perms(rhs.m_perms) m_value(rhs.m_value),
{ m_perms(rhs.m_perms)
} {
BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT }
{ BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
m_value = rhs.m_value; {
m_perms = rhs.m_perms; m_value = rhs.m_value;
return *this; m_perms = rhs.m_perms;
} return *this;
}
# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
// Note: std::move is not constexpr in C++11, that's why we're not using it here // Note: std::move is not constexpr in C++11, that's why we're not using it here
BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT :
m_value(static_cast< file_type&& >(rhs.m_value)), m_perms(static_cast< enum perms&& >(rhs.m_perms)) m_value(static_cast< file_type&& >(rhs.m_value)),
{ m_perms(static_cast< enum perms&& >(rhs.m_perms))
} {
BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT }
{ BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
m_value = static_cast< file_type&& >(rhs.m_value); {
m_perms = static_cast< enum perms&& >(rhs.m_perms); m_value = static_cast< file_type&& >(rhs.m_value);
return *this; m_perms = static_cast< enum perms&& >(rhs.m_perms);
} return *this;
# endif }
#endif
// observers // observers
BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; } BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; }
BOOST_CONSTEXPR perms permissions() const BOOST_NOEXCEPT { return m_perms; } BOOST_CONSTEXPR perms permissions() const BOOST_NOEXCEPT { return m_perms; }
// modifiers // modifiers
BOOST_CXX14_CONSTEXPR void type(file_type v) BOOST_NOEXCEPT { m_value = v; } BOOST_CXX14_CONSTEXPR void type(file_type v) BOOST_NOEXCEPT { m_value = v; }
BOOST_CXX14_CONSTEXPR void permissions(perms prms) BOOST_NOEXCEPT { m_perms = prms; } BOOST_CXX14_CONSTEXPR void permissions(perms prms) BOOST_NOEXCEPT { m_perms = prms; }
BOOST_CONSTEXPR bool operator==(const file_status& rhs) const BOOST_NOEXCEPT BOOST_CONSTEXPR bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
{ {
return type() == rhs.type() && permissions() == rhs.permissions(); return type() == rhs.type() && permissions() == rhs.permissions();
} }
BOOST_CONSTEXPR bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT BOOST_CONSTEXPR bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
{ {
return !(*this == rhs); return !(*this == rhs);
} }
private: private:
file_type m_value; file_type m_value;
enum perms m_perms; enum perms m_perms;
}; };
inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT
{ {
return f.type() != status_error; return f.type() != status_error;
}
inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT
{
return f.permissions() != perms_not_known;
}
inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT
{
return filesystem::type_present(f) && filesystem::permissions_present(f);
}
inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT
{
return f.type() != status_error && f.type() != file_not_found;
}
inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT
{
return f.type() == regular_file;
}
inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT
{
return f.type() == directory_file;
}
inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT
{
return f.type() == symlink_file;
}
inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT
{
return filesystem::exists(f) && !filesystem::is_regular_file(f)
&& !filesystem::is_directory(f) && !filesystem::is_symlink(f);
} }
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT
inline bool is_regular(file_status f) BOOST_NOEXCEPT { return filesystem::is_regular_file(f); } {
# endif return f.permissions() != perms_not_known;
}
inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT
{
return filesystem::type_present(f) && filesystem::permissions_present(f);
}
inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT
{
return f.type() != status_error && f.type() != file_not_found;
}
inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT
{
return f.type() == regular_file;
}
inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT
{
return f.type() == directory_file;
}
inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT
{
return f.type() == symlink_file;
}
inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT
{
return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular(file_status f) BOOST_NOEXCEPT
{
return filesystem::is_regular_file(f);
}
#endif
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP #endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP

View File

@ -14,9 +14,9 @@
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <iosfwd> #include <iosfwd>
@ -26,160 +26,160 @@
// on Windows, except for standard libaries known to have wchar_t overloads for // on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str() // file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \ #if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION)) // !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware #define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
# define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available #else // use the native c_str, which will be narrow on POSIX, wide on Windows
#else // use the native c_str, which will be narrow on POSIX, wide on Windows #define BOOST_FILESYSTEM_C_STR c_str()
# define BOOST_FILESYSTEM_C_STR c_str()
#endif #endif
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
#pragma warning(push) #pragma warning(push)
// 'boost::filesystem::basic_fstream<charT>' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance // 'boost::filesystem::basic_fstream<charT>' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance
#pragma warning(disable: 4250) #pragma warning(disable : 4250)
#endif #endif
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// basic_filebuf // // basic_filebuf //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> > template< class charT, class traits = std::char_traits< charT > >
class basic_filebuf : public std::basic_filebuf<charT,traits> class basic_filebuf :
{ public std::basic_filebuf< charT, traits >
private: // disallow copying {
basic_filebuf(const basic_filebuf&); public:
const basic_filebuf& operator=(const basic_filebuf&); BOOST_DEFAULTED_FUNCTION(basic_filebuf(), {})
BOOST_DELETED_FUNCTION(basic_filebuf(const basic_filebuf&))
BOOST_DELETED_FUNCTION(const basic_filebuf& operator=(const basic_filebuf&))
public: public:
basic_filebuf() {} basic_filebuf< charT, traits >* open(const path& p, std::ios_base::openmode mode)
virtual ~basic_filebuf() {}
basic_filebuf<charT,traits>*
open(const path& p, std::ios_base::openmode mode)
{ {
return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode) return std::basic_filebuf< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode) ? this : 0;
? this : 0;
} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// basic_ifstream // // basic_ifstream //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> > template< class charT, class traits = std::char_traits< charT > >
class basic_ifstream : public std::basic_ifstream<charT,traits> class basic_ifstream :
{ public std::basic_ifstream< charT, traits >
private: // disallow copying {
basic_ifstream(const basic_ifstream&); public:
const basic_ifstream& operator=(const basic_ifstream&); BOOST_DEFAULTED_FUNCTION(basic_ifstream(), {})
public:
basic_ifstream() {}
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ifstream(const path& p) explicit basic_ifstream(const path& p) :
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {} std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
basic_ifstream(const path& p, std::ios_base::openmode mode) basic_ifstream(const path& p, std::ios_base::openmode mode) :
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ifstream(const basic_ifstream&))
BOOST_DELETED_FUNCTION(const basic_ifstream& operator=(const basic_ifstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); } {
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_ifstream() {} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// basic_ofstream // // basic_ofstream //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> > template< class charT, class traits = std::char_traits< charT > >
class basic_ofstream : public std::basic_ofstream<charT,traits> class basic_ofstream :
{ public std::basic_ofstream< charT, traits >
private: // disallow copying {
basic_ofstream(const basic_ofstream&); public:
const basic_ofstream& operator=(const basic_ofstream&); BOOST_DEFAULTED_FUNCTION(basic_ofstream(), {})
public:
basic_ofstream() {}
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ofstream(const path& p) explicit basic_ofstream(const path& p) :
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {} std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
basic_ofstream(const path& p, std::ios_base::openmode mode) basic_ofstream(const path& p, std::ios_base::openmode mode) :
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ofstream(const basic_ofstream&))
BOOST_DELETED_FUNCTION(const basic_ofstream& operator=(const basic_ofstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); } {
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_ofstream() {} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// basic_fstream // // basic_fstream //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> > template< class charT, class traits = std::char_traits< charT > >
class basic_fstream : public std::basic_fstream<charT,traits> class basic_fstream :
{ public std::basic_fstream< charT, traits >
private: // disallow copying {
basic_fstream(const basic_fstream&); public:
const basic_fstream & operator=(const basic_fstream&); BOOST_DEFAULTED_FUNCTION(basic_fstream(), {})
public:
basic_fstream() {}
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_fstream(const path& p) explicit basic_fstream(const path& p) :
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out) {}
std::ios_base::in | std::ios_base::out) {}
basic_fstream(const path& p, std::ios_base::openmode mode) basic_fstream(const path& p, std::ios_base::openmode mode) :
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_fstream(const basic_fstream&))
BOOST_DELETED_FUNCTION(const basic_fstream& operator=(const basic_fstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, {
std::ios_base::in | std::ios_base::out); } std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_fstream() {} }
};
};
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// typedefs // // typedefs //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
typedef basic_filebuf<char> filebuf; typedef basic_filebuf< char > filebuf;
typedef basic_ifstream<char> ifstream; typedef basic_ifstream< char > ifstream;
typedef basic_ofstream<char> ofstream; typedef basic_ofstream< char > ofstream;
typedef basic_fstream<char> fstream; typedef basic_fstream< char > fstream;
typedef basic_filebuf<wchar_t> wfilebuf; typedef basic_filebuf< wchar_t > wfilebuf;
typedef basic_ifstream<wchar_t> wifstream; typedef basic_ifstream< wchar_t > wifstream;
typedef basic_ofstream<wchar_t> wofstream; typedef basic_ofstream< wchar_t > wofstream;
typedef basic_fstream<wchar_t> wfstream; typedef basic_fstream< wchar_t > wfstream;
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
@ -189,4 +189,5 @@ namespace filesystem
#endif #endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FSTREAM_HPP
#endif // BOOST_FILESYSTEM3_FSTREAM_HPP

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,16 +12,17 @@
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <boost/type_traits/is_array.hpp> #include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/decay.hpp> #include <boost/type_traits/decay.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/core/enable_if.hpp> #include <boost/core/enable_if.hpp>
#include <cwchar> // for mbstate_t #include <cstddef>
#include <cwchar> // for mbstate_t
#include <string> #include <string>
#include <vector> #include <vector>
#include <list> #include <list>
@ -32,321 +33,359 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost { namespace filesystem { namespace boost {
namespace filesystem {
BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category(); BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
// uses std::codecvt_base::result used for error codes: // uses std::codecvt_base::result used for error codes:
// //
// ok: Conversion successful. // ok: Conversion successful.
// partial: Not all source characters converted; one or more additional source // partial: Not all source characters converted; one or more additional source
// characters are needed to produce the final target character, or the // characters are needed to produce the final target character, or the
// size of the target intermediate buffer was too small to hold the result. // size of the target intermediate buffer was too small to hold the result.
// error: A character in the source could not be converted to the target encoding. // error: A character in the source could not be converted to the target encoding.
// noconv: The source and target characters have the same type and encoding, so no // noconv: The source and target characters have the same type and encoding, so no
// conversion was necessary. // conversion was necessary.
class directory_entry; class directory_entry;
namespace path_traits { namespace path_traits {
typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type; typedef std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type;
// is_pathable type trait; allows disabling over-agressive class path member templates // is_pathable type trait; allows disabling over-agressive class path member templates
template <class T> template< class T >
struct is_pathable { static const bool value = false; }; struct is_pathable
{
static const bool value = false;
};
template<> struct is_pathable<char*> { static const bool value = true; }; template<>
template<> struct is_pathable<const char*> { static const bool value = true; }; struct is_pathable< char* >
template<> struct is_pathable<wchar_t*> { static const bool value = true; }; {
template<> struct is_pathable<const wchar_t*> { static const bool value = true; }; static const bool value = true;
template<> struct is_pathable<std::string> { static const bool value = true; }; };
template<> struct is_pathable<std::wstring> { static const bool value = true; };
template<> struct is_pathable<std::vector<char> > { static const bool value = true; };
template<> struct is_pathable<std::vector<wchar_t> > { static const bool value = true; };
template<> struct is_pathable<std::list<char> > { static const bool value = true; };
template<> struct is_pathable<std::list<wchar_t> > { static const bool value = true; };
template<> struct is_pathable<directory_entry> { static const bool value = true; };
// Pathable empty template<>
struct is_pathable< const char* >
{
static const bool value = true;
};
template <class Container> inline template<>
struct is_pathable< wchar_t* >
{
static const bool value = true;
};
template<>
struct is_pathable< const wchar_t* >
{
static const bool value = true;
};
template<>
struct is_pathable< std::string >
{
static const bool value = true;
};
template<>
struct is_pathable< std::wstring >
{
static const bool value = true;
};
template<>
struct is_pathable< std::vector< char > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::vector< wchar_t > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::list< char > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::list< wchar_t > >
{
static const bool value = true;
};
template<>
struct is_pathable< directory_entry >
{
static const bool value = true;
};
// Pathable empty
template< class Container >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "bool" at some future date (2012?) // conforming compilers. Replace by plain "bool" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, bool>::type typename boost::disable_if< boost::is_array< Container >, bool >::type
empty(const Container & c) empty(Container const& c)
{ return c.begin() == c.end(); } {
return c.begin() == c.end();
}
template <class T> inline template< class T >
bool empty(T * const & c_str) inline bool empty(T* const& c_str)
{ {
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
return !*c_str; return !*c_str;
} }
template <typename T, size_t N> inline template< typename T, std::size_t N >
bool empty(T (&x)[N]) inline bool empty(T (&x)[N])
{ return !x[0]; } {
return !x[0];
}
// value types differ ---------------------------------------------------------------// // value types differ ---------------------------------------------------------------//
// //
// A from_end argument of 0 is less efficient than a known end, so use only if needed // A from_end argument of 0 is less efficient than a known end, so use only if needed
// with codecvt // with codecvt
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const char* from, void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
std::wstring & to, std::wstring& to, codecvt_type const& cvt);
const codecvt_type& cvt);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to, std::string& to, codecvt_type const& cvt);
const codecvt_type& cvt);
inline inline void convert(const char* from, std::wstring& to, codecvt_type const& cvt)
void convert(const char* from, {
std::wstring & to,
const codecvt_type& cvt)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
convert(from, 0, to, cvt); convert(from, 0, to, cvt);
} }
inline inline void convert(const wchar_t* from, std::string& to, codecvt_type const& cvt)
void convert(const wchar_t* from, {
std::string & to,
const codecvt_type& cvt)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
convert(from, 0, to, cvt); convert(from, 0, to, cvt);
} }
// without codecvt // without codecvt
inline inline void convert(const char* from,
void convert(const char* from, const char* from_end, // 0 for null terminated MBCS
const char* from_end, // 0 for null terminated MBCS std::wstring& to);
std::wstring & to);
inline inline void convert(const wchar_t* from,
void convert(const wchar_t* from, const wchar_t* from_end, // 0 for null terminated MBCS
const wchar_t* from_end, // 0 for null terminated MBCS std::string& to);
std::string & to);
inline inline void convert(const char* from, std::wstring& to);
void convert(const char* from,
std::wstring & to);
inline inline void convert(const wchar_t* from, std::string& to);
void convert(const wchar_t* from,
std::string & to);
// value types same -----------------------------------------------------------------// // value types same -----------------------------------------------------------------//
// char with codecvt // char with codecvt
inline inline void convert(const char* from, const char* from_end, std::string& to, codecvt_type const&)
void convert(const char* from, const char* from_end, std::string & to, {
const codecvt_type&)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const char* from, std::string& to, codecvt_type const&)
void convert(const char* from, {
std::string & to,
const codecvt_type&)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
} }
// wchar_t with codecvt // wchar_t with codecvt
inline inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to, codecvt_type const&)
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to, {
const codecvt_type&)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const wchar_t* from, std::wstring& to, codecvt_type const&)
void convert(const wchar_t* from, {
std::wstring & to,
const codecvt_type&)
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
} }
// char without codecvt // char without codecvt
inline inline void convert(const char* from, const char* from_end, std::string& to)
void convert(const char* from, const char* from_end, std::string & to) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const char* from, std::string& to)
void convert(const char* from, std::string & to) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
} }
// wchar_t without codecvt // wchar_t without codecvt
inline inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to)
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const wchar_t* from, std::wstring& to)
void convert(const wchar_t* from, std::wstring & to) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
} }
// Source dispatch -----------------------------------------------------------------// // Source dispatch -----------------------------------------------------------------//
// contiguous containers with codecvt // contiguous containers with codecvt
template <class U> inline template< class U >
void dispatch(const std::string& c, U& to, const codecvt_type& cvt) inline void dispatch(std::string const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt) inline void dispatch(std::wstring const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt) inline void dispatch(std::vector< char > const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt) inline void dispatch(std::vector< wchar_t > const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
// contiguous containers without codecvt // contiguous containers without codecvt
template <class U> inline template< class U >
void dispatch(const std::string& c, U& to) inline void dispatch(std::string const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::wstring& c, U& to) inline void dispatch(std::wstring const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<char>& c, U& to) inline void dispatch(std::vector< char > const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<wchar_t>& c, U& to) inline void dispatch(std::vector< wchar_t > const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
// non-contiguous containers with codecvt // non-contiguous containers with codecvt
template <class Container, class U> inline template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?) // conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, void>::type typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(const Container & c, U& to, const codecvt_type& cvt) dispatch(Container const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
{ {
std::basic_string<typename Container::value_type> s(c.begin(), c.end()); std::basic_string< typename Container::value_type > s(c.begin(), c.end());
convert(s.c_str(), s.c_str()+s.size(), to, cvt); convert(s.c_str(), s.c_str() + s.size(), to, cvt);
} }
} }
// c_str // c_str
template <class T, class U> inline template< class T, class U >
void dispatch(T * const & c_str, U& to, const codecvt_type& cvt) inline void dispatch(T* const& c_str, U& to, codecvt_type const& cvt)
{ {
// std::cout << "dispatch() const T *\n"; // std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
convert(c_str, to, cvt); convert(c_str, to, cvt);
} }
// Note: there is no dispatch on C-style arrays because the array may // Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size. // contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de, void dispatch(directory_entry const& de,
# ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring & to, std::wstring& to,
# else #else
std::string & to, std::string& to,
# endif #endif
const codecvt_type&); codecvt_type const&);
// non-contiguous containers without codecvt // non-contiguous containers without codecvt
template <class Container, class U> inline template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?) // conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, void>::type typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(const Container & c, U& to) dispatch(Container const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
{ {
std::basic_string<typename Container::value_type> seq(c.begin(), c.end()); std::basic_string< typename Container::value_type > seq(c.begin(), c.end());
convert(seq.c_str(), seq.c_str()+seq.size(), to); convert(seq.c_str(), seq.c_str() + seq.size(), to);
} }
} }
// c_str // c_str
template <class T, class U> inline template< class T, class U >
void dispatch(T * const & c_str, U& to) inline void dispatch(T* const& c_str, U& to)
{ {
// std::cout << "dispatch() const T *\n"; // std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
convert(c_str, to); convert(c_str, to);
} }
// Note: there is no dispatch on C-style arrays because the array may // Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size. // contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de, void dispatch(directory_entry const& de,
# ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring & to std::wstring& to
# else #else
std::string & to std::string& to
# endif #endif
); );
} // namespace path_traits
}}} // namespace boost::filesystem::path_traits } // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM_PATH_TRAITS_HPP #endif // BOOST_FILESYSTEM_PATH_TRAITS_HPP

View File

@ -10,34 +10,35 @@
#ifndef BOOST_FILESYSTEM_STRING_FILE_HPP #ifndef BOOST_FILESYSTEM_STRING_FILE_HPP
#define BOOST_FILESYSTEM_STRING_FILE_HPP #define BOOST_FILESYSTEM_STRING_FILE_HPP
#include <cstddef>
#include <string> #include <string>
#include <ios>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
namespace boost namespace boost {
namespace filesystem {
inline void save_string_file(path const& p, std::string const& str)
{ {
namespace filesystem filesystem::ofstream file;
{ file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
inline file.open(p, std::ios_base::binary);
void save_string_file(const path& p, const std::string& str) file.write(str.c_str(), str.size());
{
filesystem::ofstream file;
file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
file.open(p, std::ios_base::binary);
file.write(str.c_str(), str.size());
} }
inline inline void load_string_file(path const& p, std::string& str)
void load_string_file(const path& p, std::string& str)
{ {
filesystem::ifstream file; filesystem::ifstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
file.open(p, std::ios_base::binary); file.open(p, std::ios_base::binary);
std::size_t sz = static_cast<std::size_t>(filesystem::file_size(p)); std::size_t sz = static_cast< std::size_t >(filesystem::file_size(p));
str.resize(sz, '\0'); str.resize(sz, '\0');
file.read(&str[0], sz); file.read(&str[0], sz);
} }
} // namespace filesystem
} // namespace boost
#endif // include guard } // namespace filesystem
} // namespace boost
#endif // BOOST_FILESYSTEM_STRING_FILE_HPP

View File

@ -13,65 +13,67 @@
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp> #include <boost/filesystem/path_traits.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <locale> #include <locale>
#include <string>
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace namespace boost {
namespace filesystem {
namespace {
class codecvt_error_cat BOOST_FINAL :
public boost::system::error_category
{ {
class codecvt_error_cat : public boost::system::error_category public:
{ BOOST_DEFAULTED_FUNCTION(codecvt_error_cat(), {})
public: const char* name() const BOOST_SYSTEM_NOEXCEPT BOOST_OVERRIDE;
codecvt_error_cat(){} std::string message(int ev) const BOOST_OVERRIDE;
const char* name() const BOOST_SYSTEM_NOEXCEPT BOOST_OVERRIDE; };
std::string message(int ev) const BOOST_OVERRIDE;
};
const char* codecvt_error_cat::name() const BOOST_SYSTEM_NOEXCEPT const char* codecvt_error_cat::name() const BOOST_SYSTEM_NOEXCEPT
{ {
return "codecvt"; return "codecvt";
} }
std::string codecvt_error_cat::message(int ev) const std::string codecvt_error_cat::message(int ev) const
{ {
std::string str; std::string str;
switch (ev) switch (ev)
{ {
case std::codecvt_base::ok: case std::codecvt_base::ok:
str = "ok"; str = "ok";
break; break;
case std::codecvt_base::partial: case std::codecvt_base::partial:
str = "partial"; str = "partial";
break; break;
case std::codecvt_base::error: case std::codecvt_base::error:
str = "error"; str = "error";
break; break;
case std::codecvt_base::noconv: case std::codecvt_base::noconv:
str = "noconv"; str = "noconv";
break; break;
default: default:
str = "unknown error"; str = "unknown error";
break;
} }
return str; return str;
} }
} // unnamed namespace } // unnamed namespace
namespace boost BOOST_FILESYSTEM_DECL boost::system::error_category const& codecvt_error_category()
{ {
namespace filesystem static const codecvt_error_cat codecvt_error_cat_const;
{ return codecvt_error_cat_const;
}
BOOST_FILESYSTEM_DECL const boost::system::error_category& codecvt_error_category() } // namespace filesystem
{
static const codecvt_error_cat codecvt_error_cat_const;
return codecvt_error_cat_const;
}
} // namespace filesystem
} // namespace boost } // namespace boost

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ namespace filesystem {
typedef int err_t; typedef int err_t;
// POSIX uses a 0 return to indicate success // POSIX uses a 0 return to indicate success
#define BOOST_ERRNO errno #define BOOST_ERRNO errno
#define BOOST_ERROR_FILE_NOT_FOUND ENOENT #define BOOST_ERROR_FILE_NOT_FOUND ENOENT
#define BOOST_ERROR_ALREADY_EXISTS EEXIST #define BOOST_ERROR_ALREADY_EXISTS EEXIST
@ -43,7 +43,7 @@ typedef int err_t;
typedef boost::winapi::DWORD_ err_t; typedef boost::winapi::DWORD_ err_t;
// Windows uses a non-0 return to indicate success // Windows uses a non-0 return to indicate success
#define BOOST_ERRNO boost::winapi::GetLastError() #define BOOST_ERRNO boost::winapi::GetLastError()
#define BOOST_ERROR_FILE_NOT_FOUND boost::winapi::ERROR_FILE_NOT_FOUND_ #define BOOST_ERROR_FILE_NOT_FOUND boost::winapi::ERROR_FILE_NOT_FOUND_
#define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_ #define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
@ -55,52 +55,52 @@ typedef boost::winapi::DWORD_ err_t;
// Implemented in exception.cpp // Implemented in exception.cpp
void emit_error(err_t error_num, system::error_code* ec, const char* message); void emit_error(err_t error_num, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message); void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message); void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message);
inline bool error(err_t error_num, system::error_code* ec, const char* message) inline bool error(err_t error_num, system::error_code* ec, const char* message)
{ {
if (BOOST_LIKELY(!error_num)) if (BOOST_LIKELY(!error_num))
{ {
if (ec) if (ec)
ec->clear(); ec->clear();
return false; return false;
} }
else else
{ // error { // error
filesystem::emit_error(error_num, ec, message); filesystem::emit_error(error_num, ec, message);
return true; return true;
} }
} }
inline bool error(err_t error_num, const path& p, system::error_code* ec, const char* message) inline bool error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{ {
if (BOOST_LIKELY(!error_num)) if (BOOST_LIKELY(!error_num))
{ {
if (ec) if (ec)
ec->clear(); ec->clear();
return false; return false;
} }
else else
{ // error { // error
filesystem::emit_error(error_num, p, ec, message); filesystem::emit_error(error_num, p, ec, message);
return true; return true;
} }
} }
inline bool error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message) inline bool error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{ {
if (BOOST_LIKELY(!error_num)) if (BOOST_LIKELY(!error_num))
{ {
if (ec) if (ec)
ec->clear(); ec->clear();
return false; return false;
} }
else else
{ // error { // error
filesystem::emit_error(error_num, p1, p2, ec, message); filesystem::emit_error(error_num, p1, p2, ec, message);
return true; return true;
} }
} }
} // namespace filesystem } // namespace filesystem

View File

@ -23,55 +23,55 @@ namespace boost {
namespace filesystem { namespace filesystem {
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, system::error_code ec) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, system::error_code ec) :
system::system_error(ec, what_arg) system::system_error(ec, what_arg)
{ {
try try
{ {
m_imp_ptr.reset(new impl()); m_imp_ptr.reset(new impl());
} }
catch (...) catch (...)
{ {
m_imp_ptr.reset(); m_imp_ptr.reset();
} }
} }
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, system::error_code ec) :
system::system_error(ec, what_arg) system::system_error(ec, what_arg)
{ {
try try
{ {
m_imp_ptr.reset(new impl(path1_arg)); m_imp_ptr.reset(new impl(path1_arg));
} }
catch (...) catch (...)
{ {
m_imp_ptr.reset(); m_imp_ptr.reset();
} }
} }
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
system::system_error(ec, what_arg) system::system_error(ec, what_arg)
{ {
try try
{ {
m_imp_ptr.reset(new impl(path1_arg, path2_arg)); m_imp_ptr.reset(new impl(path1_arg, path2_arg));
} }
catch (...) catch (...)
{ {
m_imp_ptr.reset(); m_imp_ptr.reset();
} }
} }
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) :
system::system_error(static_cast< system::system_error const& >(that)), system::system_error(static_cast< system::system_error const& >(that)),
m_imp_ptr(that.m_imp_ptr) m_imp_ptr(that.m_imp_ptr)
{ {
} }
BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator= (filesystem_error const& that) BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator=(filesystem_error const& that)
{ {
static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that); static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
m_imp_ptr = that.m_imp_ptr; m_imp_ptr = that.m_imp_ptr;
return *this; return *this;
} }
BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW
@ -80,65 +80,66 @@ BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NO
BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
{ {
if (m_imp_ptr.get()) try if (m_imp_ptr.get())
{ try
if (m_imp_ptr->m_what.empty()) {
{ if (m_imp_ptr->m_what.empty())
m_imp_ptr->m_what = system::system_error::what(); {
if (!m_imp_ptr->m_path1.empty()) m_imp_ptr->m_what = system::system_error::what();
{ if (!m_imp_ptr->m_path1.empty())
m_imp_ptr->m_what += ": \""; {
m_imp_ptr->m_what += m_imp_ptr->m_path1.string(); m_imp_ptr->m_what += ": \"";
m_imp_ptr->m_what += "\""; m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
} m_imp_ptr->m_what += "\"";
if (!m_imp_ptr->m_path2.empty()) }
{ if (!m_imp_ptr->m_path2.empty())
m_imp_ptr->m_what += ", \""; {
m_imp_ptr->m_what += m_imp_ptr->m_path2.string(); m_imp_ptr->m_what += ", \"";
m_imp_ptr->m_what += "\""; m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
} m_imp_ptr->m_what += "\"";
} }
}
return m_imp_ptr->m_what.c_str(); return m_imp_ptr->m_what.c_str();
} }
catch (...) catch (...)
{ {
m_imp_ptr->m_what.clear(); m_imp_ptr->m_what.clear();
} }
return system::system_error::what(); return system::system_error::what();
} }
BOOST_FILESYSTEM_DECL const path& filesystem_error::get_empty_path() BOOST_NOEXCEPT BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() BOOST_NOEXCEPT
{ {
static const path empty_path; static const path empty_path;
return empty_path; return empty_path;
} }
// error handling helpers declared in error_handling.hpp -----------------------------------------------------// // error handling helpers declared in error_handling.hpp -----------------------------------------------------//
void emit_error(err_t error_num, system::error_code* ec, const char* message) void emit_error(err_t error_num, system::error_code* ec, const char* message)
{ {
if (!ec) if (!ec)
BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category()))); BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
else else
ec->assign(error_num, system::system_category()); ec->assign(error_num, system::system_category());
} }
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message) void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{ {
if (!ec) if (!ec)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category()))); BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
else else
ec->assign(error_num, system::system_category()); ec->assign(error_num, system::system_category());
} }
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message) void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{ {
if (ec == 0) if (ec == 0)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category()))); BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
else else
ec->assign(error_num, system::system_category()); ec->assign(error_num, system::system_category());
} }
} // namespace filesystem } // namespace filesystem

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,12 +11,16 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp> #include <boost/filesystem/path_traits.hpp>
#include <boost/system/system_error.hpp> #include <boost/system/system_error.hpp>
#include <boost/scoped_array.hpp> #include <boost/smart_ptr/scoped_array.hpp>
#include <locale> // for codecvt_base::result #include <boost/assert.hpp>
#include <cstring> // for strlen #include <string>
#include <cwchar> // for wcslen #include <locale> // for codecvt_base::result
#include <cstring> // for strlen
#include <cwchar> // for wcslen
#include <cstddef>
namespace pt = boost::filesystem::path_traits; namespace pt = boost::filesystem::path_traits;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -27,13 +31,12 @@ namespace bs = boost::system;
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE #ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
# define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256 #define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#endif #endif
namespace { namespace {
const std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE; BOOST_CONSTEXPR_OR_CONST std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -46,13 +49,13 @@ namespace {
// convert_aux const char* to wstring // // convert_aux const char* to wstring //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
void convert_aux( void convert_aux(
const char* from, const char* from,
const char* from_end, const char* from_end,
wchar_t* to, wchar_t* to_end, wchar_t* to, wchar_t* to_end,
std::wstring & target, std::wstring& target,
const pt::codecvt_type & cvt) pt::codecvt_type const& cvt)
{ {
//std::cout << std::hex //std::cout << std::hex
// << " from=" << std::size_t(from) // << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end) // << " from_end=" << std::size_t(from_end)
@ -60,33 +63,31 @@ namespace {
// << " to_end=" << std::size_t(to_end) // << " to_end=" << std::size_t(to_end)
// << std::endl; // << std::endl;
std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports
const char* from_next; const char* from_next;
wchar_t* to_next; wchar_t* to_next;
std::codecvt_base::result res; std::codecvt_base::result res;
if ((res=cvt.in(state, from, from_end, from_next, if ((res = cvt.in(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
to, to_end, to_next)) != std::codecvt_base::ok)
{ {
//std::cout << " result is " << static_cast<int>(res) << std::endl; //std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to wstring"));
"boost::filesystem::path codecvt to wstring"));
} }
target.append(to, to_next); target.append(to, to_next);
} }
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// convert_aux const wchar_t* to string // // convert_aux const wchar_t* to string //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
void convert_aux( void convert_aux(
const wchar_t* from, const wchar_t* from,
const wchar_t* from_end, const wchar_t* from_end,
char* to, char* to_end, char* to, char* to_end,
std::string & target, std::string& target,
const pt::codecvt_type & cvt) pt::codecvt_type const& cvt)
{ {
//std::cout << std::hex //std::cout << std::hex
// << " from=" << std::size_t(from) // << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end) // << " from_end=" << std::size_t(from_end)
@ -94,100 +95,103 @@ namespace {
// << " to_end=" << std::size_t(to_end) // << " to_end=" << std::size_t(to_end)
// << std::endl; // << std::endl;
std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports
const wchar_t* from_next; const wchar_t* from_next;
char* to_next; char* to_next;
std::codecvt_base::result res; std::codecvt_base::result res;
if ((res=cvt.out(state, from, from_end, from_next, if ((res = cvt.out(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
to, to_end, to_next)) != std::codecvt_base::ok)
{ {
//std::cout << " result is " << static_cast<int>(res) << std::endl; //std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to string"));
"boost::filesystem::path codecvt to string"));
} }
target.append(to, to_next); target.append(to, to_next);
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// path_traits // // path_traits //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace boost { namespace filesystem { namespace path_traits { namespace boost {
namespace filesystem {
namespace path_traits {
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// convert const char* to wstring // // convert const char* to wstring //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const char* from, void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
std::wstring & to, std::wstring& to, codecvt_type const& cvt)
const codecvt_type & cvt) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
if (!from_end) // null terminated if (!from_end) // null terminated
{ {
from_end = from + std::strlen(from); from_end = from + std::strlen(from);
} }
if (from == from_end) return; if (from == from_end)
return;
std::size_t buf_size = (from_end - from) * 3; // perhaps too large, but that's OK std::size_t buf_size = (from_end - from) * 3; // perhaps too large, but that's OK
// dynamically allocate a buffer only if source is unusually large // dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size) if (buf_size > default_codecvt_buf_size)
{ {
boost::scoped_array< wchar_t > buf(new wchar_t [buf_size]); boost::scoped_array< wchar_t > buf(new wchar_t[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt); convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
} }
else else
{ {
wchar_t buf[default_codecvt_buf_size]; wchar_t buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt); convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
} }
} }
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// convert const wchar_t* to string // // convert const wchar_t* to string //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to, std::string& to, codecvt_type const& cvt)
const codecvt_type & cvt) {
{
BOOST_ASSERT(from); BOOST_ASSERT(from);
if (!from_end) // null terminated if (!from_end) // null terminated
{ {
from_end = from + std::wcslen(from); from_end = from + std::wcslen(from);
} }
if (from == from_end) return; if (from == from_end)
return;
// The codecvt length functions may not be implemented, and I don't really // The codecvt length functions may not be implemented, and I don't really
// understand them either. Thus this code is just a guess; if it turns // understand them either. Thus this code is just a guess; if it turns
// out the buffer is too small then an error will be reported and the code // out the buffer is too small then an error will be reported and the code
// will have to be fixed. // will have to be fixed.
std::size_t buf_size = (from_end - from) * 4; // perhaps too large, but that's OK std::size_t buf_size = (from_end - from) * 4; // perhaps too large, but that's OK
buf_size += 4; // encodings like shift-JIS need some prefix space buf_size += 4; // encodings like shift-JIS need some prefix space
// dynamically allocate a buffer only if source is unusually large // dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size) if (buf_size > default_codecvt_buf_size)
{ {
boost::scoped_array< char > buf(new char [buf_size]); boost::scoped_array< char > buf(new char[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt); convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
} }
else else
{ {
char buf[default_codecvt_buf_size]; char buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt); convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
} }
} }
}}} // namespace boost::filesystem::path_traits
} // namespace path_traits
} // namespace filesystem
} // namespace boost

View File

@ -59,7 +59,7 @@
#endif #endif
#ifndef _POSIX_PTHREAD_SEMANTICS #ifndef _POSIX_PTHREAD_SEMANTICS
#define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this #define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this
#endif #endif
#if !defined(_INCLUDE_STDCSOURCE_199901) && (defined(hpux) || defined(_hpux) || defined(__hpux)) #if !defined(_INCLUDE_STDCSOURCE_199901) && (defined(hpux) || defined(_hpux) || defined(__hpux))
@ -68,7 +68,7 @@
#define _INCLUDE_STDCSOURCE_199901 #define _INCLUDE_STDCSOURCE_199901
#endif #endif
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) ||\ #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || \
defined(__CYGWIN__) defined(__CYGWIN__)
// Define target Windows version macros before including any other headers // Define target Windows version macros before including any other headers
#include <boost/winapi/config.hpp> #include <boost/winapi/config.hpp>

View File

@ -11,100 +11,79 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
#include <cstring> // SGI MIPSpro compilers need this #include <cstring> // SGI MIPSpro compilers need this
#include <string>
# ifdef BOOST_NO_STDC_NAMESPACE #ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::strerror; } namespace std {
# endif using ::strerror;
}
#endif
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace namespace {
{
const char invalid_chars[] = BOOST_CONSTEXPR_OR_CONST char invalid_chars[] =
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
"<>:\"/\\|"; "<>:\"/\\|";
// note that the terminating '\0' is part of the string - thus the size below // note that the terminating '\0' is part of the string - thus the size below
// is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I // is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars)); const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
const std::string valid_posix( const std::string valid_posix(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
} // unnamed namespace } // unnamed namespace
namespace boost namespace boost {
namespace filesystem {
// name_check functions ----------------------------------------------//
#ifdef BOOST_WINDOWS
BOOST_FILESYSTEM_DECL bool native(const std::string& name)
{ {
namespace filesystem return windows_name(name);
{ }
#else
BOOST_FILESYSTEM_DECL bool native(const std::string& name)
{
return !name.empty() && name[0] != ' ' && name.find('/') == std::string::npos;
}
#endif
// name_check functions ----------------------------------------------// BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string& name)
{
return !name.empty() && name.find_first_not_of(valid_posix) == std::string::npos;
}
# ifdef BOOST_WINDOWS BOOST_FILESYSTEM_DECL bool windows_name(const std::string& name)
BOOST_FILESYSTEM_DECL bool native(const std::string & name) {
{ return !name.empty() && name[0] != ' ' && name.find_first_of(windows_invalid_chars) == std::string::npos && *(name.end() - 1) != ' ' && (*(name.end() - 1) != '.' || name.size() == 1 || name == "..");
return windows_name(name); }
}
# else
BOOST_FILESYSTEM_DECL bool native(const std::string & name)
{
return !name.empty()
&& name[0] != ' '
&& name.find('/') == std::string::npos;
}
# endif
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name) BOOST_FILESYSTEM_DECL bool portable_name(const std::string& name)
{ {
return !name.empty() return !name.empty() && (name == "." || name == ".." || (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-'));
&& name.find_first_not_of(valid_posix) == std::string::npos; }
}
BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name) BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string& name)
{ {
return !name.empty() return name == "." || name == ".." || (portable_name(name) && name.find('.') == std::string::npos);
&& name[0] != ' ' }
&& name.find_first_of(windows_invalid_chars) == std::string::npos
&& *(name.end()-1) != ' '
&& (*(name.end()-1) != '.'
|| name.size() == 1 || name == "..");
}
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name) BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string& name)
{ {
return !name.empty() std::string::size_type pos;
&& (name == "." return portable_name(name) && name != "." && name != ".." && ((pos = name.find('.')) == std::string::npos || (name.find('.', pos + 1) == std::string::npos && (pos + 5) > name.size()));
|| name == ".." }
|| (windows_name(name)
&& portable_posix_name(name)
&& name[0] != '.' && name[0] != '-'));
}
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name) } // namespace filesystem
{
return
name == "."
|| name == ".."
|| (portable_name(name)
&& name.find('.') == std::string::npos);
}
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name)
{
std::string::size_type pos;
return
portable_name(name)
&& name != "."
&& name != ".."
&& ((pos = name.find('.')) == std::string::npos
|| (name.find('.', pos+1) == std::string::npos
&& (pos + 5) > name.size()));
}
} // namespace filesystem
} // namespace boost } // namespace boost

View File

@ -17,62 +17,73 @@
#include <boost/predef/os/bsd/free.h> #include <boost/predef/os/bsd/free.h>
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
# include <cerrno>
# include <stddef.h> #include <cerrno>
# include <fcntl.h> #include <stddef.h>
# ifdef BOOST_HAS_UNISTD_H #include <fcntl.h>
# include <unistd.h> #ifdef BOOST_HAS_UNISTD_H
# endif #include <unistd.h>
# if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || BOOST_LIB_C_CLOUDABI
# include <stdlib.h>
# define BOOST_FILESYSTEM_HAS_ARC4RANDOM
# endif
# if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
# include <sys/syscall.h>
# if defined(SYS_getrandom)
# define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM
# endif // defined(SYS_getrandom)
# if defined(__has_include)
# if __has_include(<sys/random.h>)
# define BOOST_FILESYSTEM_HAS_GETRANDOM
# endif
# elif defined(__GLIBC__)
# if __GLIBC_PREREQ(2, 25)
# define BOOST_FILESYSTEM_HAS_GETRANDOM
# endif
# endif
# if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
# include <sys/random.h>
# endif
# endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#else // BOOST_WINDOWS_API
// We use auto-linking below to help users of static builds of Boost.Filesystem to link to whatever Windows SDK library we selected.
// The dependency information is currently not exposed in CMake config files generated by Boost.Build (https://github.com/boostorg/boost_install/issues/18),
// which makes it non-trivial for users to discover the libraries they need. This feature is deprecated and may be removed in the future,
// when the situation with CMake config files improves.
// Note that the library build system is the principal source of linking the library, which must work regardless of auto-linking.
# include <boost/predef/platform.h>
# include <boost/winapi/basic_types.hpp>
# if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project
# include <boost/winapi/error_codes.hpp>
# include <boost/winapi/bcrypt.hpp>
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# pragma comment(lib, "bcrypt.lib")
# endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
# include <boost/winapi/crypt.hpp>
# include <boost/winapi/get_last_error.hpp>
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# if !defined(_WIN32_WCE)
# pragma comment(lib, "advapi32.lib")
# else
# pragma comment(lib, "coredll.lib")
# endif
# endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#endif #endif
#if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || \
BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || \
BOOST_LIB_C_CLOUDABI
#include <stdlib.h>
#define BOOST_FILESYSTEM_HAS_ARC4RANDOM
#endif
#if (defined(__linux__) || defined(__linux) || defined(linux)) && \
(!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#include <sys/syscall.h>
#if defined(SYS_getrandom)
#define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM
#endif // defined(SYS_getrandom)
#if defined(__has_include)
#if __has_include(<sys/random.h>)
#define BOOST_FILESYSTEM_HAS_GETRANDOM
#endif
#elif defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 25)
#define BOOST_FILESYSTEM_HAS_GETRANDOM
#endif
#endif // BOOST_FILESYSTEM_HAS_GETRANDOM definition
#if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
#include <sys/random.h>
#endif
#endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#else // BOOST_WINDOWS_API
// We use auto-linking below to help users of static builds of Boost.Filesystem to link to whatever Windows SDK library we selected.
// The dependency information is currently not exposed in CMake config files generated by Boost.Build (https://github.com/boostorg/boost_install/issues/18),
// which makes it non-trivial for users to discover the libraries they need. This feature is deprecated and may be removed in the future,
// when the situation with CMake config files improves.
// Note that the library build system is the principal source of linking the library, which must work regardless of auto-linking.
#include <boost/predef/platform.h>
#include <boost/winapi/basic_types.hpp>
#if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project
#include <boost/winapi/error_codes.hpp>
#include <boost/winapi/bcrypt.hpp>
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#pragma comment(lib, "bcrypt.lib")
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#include <boost/winapi/crypt.hpp>
#include <boost/winapi/get_last_error.hpp>
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#if !defined(_WIN32_WCE)
#pragma comment(lib, "advapi32.lib")
#else
#pragma comment(lib, "coredll.lib")
#endif
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#endif // BOOST_POSIX_API
#include <cstddef> #include <cstddef>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include "error_handling.hpp" #include "error_handling.hpp"
@ -83,7 +94,9 @@
#endif #endif
#endif // defined(BOOST_POSIX_API) #endif // defined(BOOST_POSIX_API)
namespace boost { namespace filesystem { namespace detail { namespace boost {
namespace filesystem {
namespace detail {
namespace { namespace {
@ -91,20 +104,20 @@ namespace {
//! Converts NTSTATUS error codes to Win32 error codes for reporting //! Converts NTSTATUS error codes to Win32 error codes for reporting
inline boost::winapi::DWORD_ translate_ntstatus(boost::winapi::NTSTATUS_ status) inline boost::winapi::DWORD_ translate_ntstatus(boost::winapi::NTSTATUS_ status)
{ {
// Note: Legacy MinGW doesn't have ntstatus.h and doesn't define NTSTATUS error codes other than STATUS_SUCCESS. // Note: Legacy MinGW doesn't have ntstatus.h and doesn't define NTSTATUS error codes other than STATUS_SUCCESS.
// Because of this we have to use hardcoded integer literals here. Also, we have to cast to unsigned // Because of this we have to use hardcoded integer literals here. Also, we have to cast to unsigned
// integral type to avoid signed overflow and narrowing conversion in the constants. // integral type to avoid signed overflow and narrowing conversion in the constants.
switch (static_cast< boost::winapi::ULONG_ >(status)) switch (static_cast< boost::winapi::ULONG_ >(status))
{ {
case 0xC0000017ul: // STATUS_NO_MEMORY case 0xC0000017ul: // STATUS_NO_MEMORY
return boost::winapi::ERROR_OUTOFMEMORY_; return boost::winapi::ERROR_OUTOFMEMORY_;
case 0xC0000008ul: // STATUS_INVALID_HANDLE case 0xC0000008ul: // STATUS_INVALID_HANDLE
return boost::winapi::ERROR_INVALID_HANDLE_; return boost::winapi::ERROR_INVALID_HANDLE_;
case 0xC000000Dul: // STATUS_INVALID_PARAMETER case 0xC000000Dul: // STATUS_INVALID_PARAMETER
return boost::winapi::ERROR_INVALID_PARAMETER_; return boost::winapi::ERROR_INVALID_PARAMETER_;
default: default:
return boost::winapi::ERROR_NOT_SUPPORTED_; return boost::winapi::ERROR_NOT_SUPPORTED_;
} }
} }
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT) #endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
@ -114,62 +127,62 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
#if defined(BOOST_FILESYSTEM_HAS_GETRANDOM) || defined(BOOST_FILESYSTEM_HAS_SYS_GETRANDOM) #if defined(BOOST_FILESYSTEM_HAS_GETRANDOM) || defined(BOOST_FILESYSTEM_HAS_SYS_GETRANDOM)
std::size_t bytes_read = 0; std::size_t bytes_read = 0;
while (bytes_read < len) while (bytes_read < len)
{
#if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
ssize_t n = ::getrandom(buf, len - bytes_read, 0u);
#else
ssize_t n = ::syscall(SYS_getrandom, buf, len - bytes_read, 0u);
#endif
if (BOOST_UNLIKELY(n < 0))
{ {
int err = errno; #if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
if (err == EINTR) ssize_t n = ::getrandom(buf, len - bytes_read, 0u);
continue; #else
emit_error(err, ec, "boost::filesystem::unique_path"); ssize_t n = ::syscall(SYS_getrandom, buf, len - bytes_read, 0u);
return; #endif
} if (BOOST_UNLIKELY(n < 0))
{
int err = errno;
if (err == EINTR)
continue;
emit_error(err, ec, "boost::filesystem::unique_path");
return;
}
bytes_read += n; bytes_read += n;
buf = static_cast<char*>(buf) + n; buf = static_cast< char* >(buf) + n;
} }
#elif defined(BOOST_FILESYSTEM_HAS_ARC4RANDOM) #elif defined(BOOST_FILESYSTEM_HAS_ARC4RANDOM)
arc4random_buf(buf, len); arc4random_buf(buf, len);
#else #else
int file = open("/dev/urandom", O_RDONLY | O_CLOEXEC); int file = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (file == -1)
{
file = open("/dev/random", O_RDONLY | O_CLOEXEC);
if (file == -1) if (file == -1)
{ {
emit_error(errno, ec, "boost::filesystem::unique_path"); file = open("/dev/random", O_RDONLY | O_CLOEXEC);
return; if (file == -1)
{
emit_error(errno, ec, "boost::filesystem::unique_path");
return;
}
} }
}
std::size_t bytes_read = 0; std::size_t bytes_read = 0;
while (bytes_read < len) while (bytes_read < len)
{
ssize_t n = read(file, buf, len - bytes_read);
if (BOOST_UNLIKELY(n == -1))
{ {
int err = errno; ssize_t n = read(file, buf, len - bytes_read);
if (err == EINTR) if (BOOST_UNLIKELY(n == -1))
continue; {
close(file); int err = errno;
emit_error(err, ec, "boost::filesystem::unique_path"); if (err == EINTR)
return; continue;
close(file);
emit_error(err, ec, "boost::filesystem::unique_path");
return;
}
bytes_read += n;
buf = static_cast< char* >(buf) + n;
} }
bytes_read += n;
buf = static_cast<char*>(buf) + n;
}
close(file); close(file);
#endif #endif
@ -177,44 +190,44 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
#if defined(BOOST_FILESYSTEM_HAS_BCRYPT) #if defined(BOOST_FILESYSTEM_HAS_BCRYPT)
boost::winapi::BCRYPT_ALG_HANDLE_ handle; boost::winapi::BCRYPT_ALG_HANDLE_ handle;
boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0); boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
if (BOOST_UNLIKELY(status != 0)) if (BOOST_UNLIKELY(status != 0))
{ {
fail: fail:
emit_error(translate_ntstatus(status), ec, "boost::filesystem::unique_path"); emit_error(translate_ntstatus(status), ec, "boost::filesystem::unique_path");
return; return;
} }
status = boost::winapi::BCryptGenRandom(handle, static_cast<boost::winapi::PUCHAR_>(buf), static_cast<boost::winapi::ULONG_>(len), 0); status = boost::winapi::BCryptGenRandom(handle, static_cast< boost::winapi::PUCHAR_ >(buf), static_cast< boost::winapi::ULONG_ >(len), 0);
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0); boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
if (BOOST_UNLIKELY(status != 0)) if (BOOST_UNLIKELY(status != 0))
goto fail; goto fail;
#else // defined(BOOST_FILESYSTEM_HAS_BCRYPT) #else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
boost::winapi::HCRYPTPROV_ handle; boost::winapi::HCRYPTPROV_ handle;
boost::winapi::DWORD_ err = 0u; boost::winapi::DWORD_ err = 0u;
if (BOOST_UNLIKELY(!boost::winapi::CryptAcquireContextW(&handle, NULL, NULL, boost::winapi::PROV_RSA_FULL_, boost::winapi::CRYPT_VERIFYCONTEXT_ | boost::winapi::CRYPT_SILENT_))) if (BOOST_UNLIKELY(!boost::winapi::CryptAcquireContextW(&handle, NULL, NULL, boost::winapi::PROV_RSA_FULL_, boost::winapi::CRYPT_VERIFYCONTEXT_ | boost::winapi::CRYPT_SILENT_)))
{ {
err = boost::winapi::GetLastError(); err = boost::winapi::GetLastError();
fail: fail:
emit_error(err, ec, "boost::filesystem::unique_path"); emit_error(err, ec, "boost::filesystem::unique_path");
return; return;
} }
boost::winapi::BOOL_ gen_ok = boost::winapi::CryptGenRandom(handle, static_cast<boost::winapi::DWORD_>(len), static_cast<boost::winapi::BYTE_*>(buf)); boost::winapi::BOOL_ gen_ok = boost::winapi::CryptGenRandom(handle, static_cast< boost::winapi::DWORD_ >(len), static_cast< boost::winapi::BYTE_* >(buf));
if (BOOST_UNLIKELY(!gen_ok)) if (BOOST_UNLIKELY(!gen_ok))
err = boost::winapi::GetLastError(); err = boost::winapi::GetLastError();
boost::winapi::CryptReleaseContext(handle, 0); boost::winapi::CryptReleaseContext(handle, 0);
if (BOOST_UNLIKELY(!gen_ok)) if (BOOST_UNLIKELY(!gen_ok))
goto fail; goto fail;
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT) #endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
@ -229,44 +242,47 @@ BOOST_CONSTEXPR_OR_CONST char hex[] = "0123456789abcdef";
BOOST_CONSTEXPR_OR_CONST char percent = '%'; BOOST_CONSTEXPR_OR_CONST char percent = '%';
#endif #endif
} // unnamed namespace } // unnamed namespace
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path unique_path(const path& model, system::error_code* ec) path unique_path(const path& model, system::error_code* ec)
{ {
// This function used wstring for fear of misidentifying // This function used wstring for fear of misidentifying
// a part of a multibyte character as a percent sign. // a part of a multibyte character as a percent sign.
// However, double byte encodings only have 80-FF as lead // However, double byte encodings only have 80-FF as lead
// bytes and 40-7F as trailing bytes, whereas % is 25. // bytes and 40-7F as trailing bytes, whereas % is 25.
// So, use string on POSIX and avoid conversions. // So, use string on POSIX and avoid conversions.
path::string_type s( model.native() ); path::string_type s(model.native());
char ran[16] = {}; // init to avoid clang static analyzer message char ran[16] = {}; // init to avoid clang static analyzer message
// see ticket #8954 // see ticket #8954
BOOST_CONSTEXPR_OR_CONST unsigned int max_nibbles = 2u * sizeof(ran); // 4-bits per nibble BOOST_CONSTEXPR_OR_CONST unsigned int max_nibbles = 2u * sizeof(ran); // 4-bits per nibble
unsigned int nibbles_used = max_nibbles; unsigned int nibbles_used = max_nibbles;
for (path::string_type::size_type i = 0, n = s.size(); i < n; ++i) for (path::string_type::size_type i = 0, n = s.size(); i < n; ++i)
{
if (s[i] == percent) // digit request
{ {
if (nibbles_used == max_nibbles) if (s[i] == percent) // digit request
{ {
system_crypt_random(ran, sizeof(ran), ec); if (nibbles_used == max_nibbles)
if (ec != 0 && *ec) {
return path(); system_crypt_random(ran, sizeof(ran), ec);
nibbles_used = 0; if (ec != 0 && *ec)
} return path();
unsigned int c = ran[nibbles_used / 2u]; nibbles_used = 0;
c >>= 4u * (nibbles_used++ & 1u); // if odd, shift right 1 nibble }
s[i] = hex[c & 0xf]; // convert to hex digit and replace unsigned int c = ran[nibbles_used / 2u];
c >>= 4u * (nibbles_used++ & 1u); // if odd, shift right 1 nibble
s[i] = hex[c & 0xf]; // convert to hex digit and replace
}
} }
}
if (ec != 0) ec->clear(); if (ec != 0)
ec->clear();
return s; return s;
} }
}}} } // namespace detail
} // namespace filesystem
} // namespace boost

View File

@ -5,10 +5,17 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#define BOOST_UTF8_BEGIN_NAMESPACE \ #include <boost/filesystem/config.hpp>
namespace boost { namespace filesystem { namespace detail {
#define BOOST_UTF8_END_NAMESPACE }}} #define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { \
namespace filesystem { \
namespace detail {
#define BOOST_UTF8_END_NAMESPACE \
} \
} \
}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL #define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.ipp> #include <boost/detail/utf8_codecvt_facet.ipp>

View File

@ -11,7 +11,7 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <cwchar> // for mbstate_t #include <cwchar> // for mbstate_t
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
@ -20,43 +20,41 @@
#include <windows.h> #include <windows.h>
std::codecvt_base::result windows_file_codecvt::do_in( std::codecvt_base::result windows_file_codecvt::do_in(
std::mbstate_t &, std::mbstate_t&,
const char* from, const char* from_end, const char*& from_next, const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{ {
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count; int count;
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0)
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0) {
{ return error; // conversion failed
return error; // conversion failed }
}
from_next = from_end; from_next = from_end;
to_next = to + count; to_next = to + count;
*to_next = L'\0'; *to_next = L'\0';
return ok; return ok;
} }
std::codecvt_base::result windows_file_codecvt::do_out( std::codecvt_base::result windows_file_codecvt::do_out(
std::mbstate_t &, std::mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char* & to_next) const char* to, char* to_end, char*& to_next) const
{ {
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count; int count;
if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to), 0, 0)) == 0)
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0) {
{ return error; // conversion failed
return error; // conversion failed }
}
from_next = from_end; from_next = from_end;
to_next = to + count; to_next = to + count;
*to_next = '\0'; *to_next = '\0';
return ok; return ok;
} }
#endif // BOOST_WINDOWS_API #endif // BOOST_WINDOWS_API

View File

@ -23,35 +23,26 @@
// // // //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class BOOST_SYMBOL_VISIBLE windows_file_codecvt class BOOST_SYMBOL_VISIBLE windows_file_codecvt :
: public std::codecvt< wchar_t, char, std::mbstate_t > public std::codecvt< wchar_t, char, std::mbstate_t >
{ {
public: public:
explicit windows_file_codecvt(std::size_t refs = 0) explicit windows_file_codecvt(std::size_t refs = 0) :
: std::codecvt<wchar_t, char, std::mbstate_t>(refs) {} std::codecvt< wchar_t, char, std::mbstate_t >(refs)
{
}
protected: protected:
virtual bool do_always_noconv() const throw() { return false; }
virtual bool do_always_noconv() const throw() { return false; } // seems safest to assume variable number of characters since we don't
// actually know what codepage is active
// seems safest to assume variable number of characters since we don't virtual int do_encoding() const throw() { return 0; }
// actually know what codepage is active virtual std::codecvt_base::result do_in(std::mbstate_t& state, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const;
virtual int do_encoding() const throw() { return 0; } virtual std::codecvt_base::result do_out(std::mbstate_t& state, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const;
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
virtual std::codecvt_base::result do_in(std::mbstate_t& state, virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
const char* from, const char* from_end, const char*& from_next, virtual int do_max_length() const throw() { return 0; }
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const;
virtual std::codecvt_base::result do_out(std::mbstate_t & state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const;
virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&,
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw () { return 0; }
}; };
#endif // BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP #endif // BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP

View File

@ -24,27 +24,23 @@ namespace detail {
inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5]) inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5])
{ {
return return (p[0] == x1[0] || p[0] == x2[0]) &&
(p[0] == x1[0] || p[0] == x2[0]) && (p[1] == x1[1] || p[1] == x2[1]) &&
(p[1] == x1[1] || p[1] == x2[1]) && (p[2] == x1[2] || p[2] == x2[2]) &&
(p[2] == x1[2] || p[2] == x2[2]) && (p[3] == x1[3] || p[3] == x2[3]) &&
(p[3] == x1[3] || p[3] == x2[3]) && p[4] == 0;
p[4] == 0;
} }
inline boost::filesystem::perms make_permissions(const boost::filesystem::path& p, DWORD attr) inline boost::filesystem::perms make_permissions(const boost::filesystem::path& p, DWORD attr)
{ {
boost::filesystem::perms prms = boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read; boost::filesystem::perms prms = boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read;
if ((attr & FILE_ATTRIBUTE_READONLY) == 0u) if ((attr & FILE_ATTRIBUTE_READONLY) == 0u)
prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write; prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
boost::filesystem::path ext = p.extension(); boost::filesystem::path ext = p.extension();
wchar_t const* q = ext.c_str(); wchar_t const* q = ext.c_str();
if (equal_extension(q, L".exe", L".EXE") if (equal_extension(q, L".exe", L".EXE") || equal_extension(q, L".com", L".COM") || equal_extension(q, L".bat", L".BAT") || equal_extension(q, L".cmd", L".CMD"))
|| equal_extension(q, L".com", L".COM") prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
|| equal_extension(q, L".bat", L".BAT") return prms;
|| equal_extension(q, L".cmd", L".CMD"))
prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
return prms;
} }
} // namespace detail } // namespace detail

View File

@ -16,37 +16,35 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
int main() int main()
{ {
cout << "Verify macro reporting works correctly\n"; cout << "Verify macro reporting works correctly\n";
cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl; cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl;
# define SUCHAMACRO #define SUCHAMACRO
cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl; cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl;
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl; cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
cout << "Report macro values that may be useful in debugging various test programs\n"; cout << "Report macro values that may be useful in debugging various test programs\n";
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl; cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
cout << " BOOST_FILESYSTEM_VERSION: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_VERSION) << endl; cout << " BOOST_FILESYSTEM_VERSION: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_VERSION) << endl;
cout << " BOOST_FILESYSTEM_DEPRECATED: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DEPRECATED) << endl; cout << " BOOST_FILESYSTEM_DEPRECATED: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DEPRECATED) << endl;
cout << " BOOST_FILESYSTEM_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << endl; cout << " BOOST_FILESYSTEM_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << endl;
cout << " BOOST_FILESYSTEM_DYN_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DYN_LINK) << endl; cout << " BOOST_FILESYSTEM_DYN_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DYN_LINK) << endl;
cout << " BOOST_FILESYSTEM_STATIC_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_STATIC_LINK) << endl; cout << " BOOST_FILESYSTEM_STATIC_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_STATIC_LINK) << endl;
cout << " BOOST_ALL_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_ALL_NO_LIB) << endl; cout << " BOOST_ALL_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_ALL_NO_LIB) << endl;
cout << " BOOST_FILESYSTEM_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_NO_LIB) << endl; cout << " BOOST_FILESYSTEM_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_NO_LIB) << endl;
cout << " BOOST_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl; cout << " BOOST_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl;
cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl; cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl;
cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl; cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl;
cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << endl; cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << endl;
cout << " __MINGW32__: " << BOOST_MACRO_VALUE(__MINGW32__) << endl; cout << " __MINGW32__: " << BOOST_MACRO_VALUE(__MINGW32__) << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
return 0;
return 0;
} }

View File

@ -12,10 +12,10 @@
// See deprecated_test for tests of deprecated features // See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
@ -23,9 +23,9 @@
#include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
@ -37,143 +37,146 @@ namespace fs = boost::filesystem;
using fs::path; using fs::path;
namespace sys = boost::system; namespace sys = boost::system;
namespace namespace {
template< typename F >
bool throws_fs_error(F func)
{ {
template< typename F > try
bool throws_fs_error(F func)
{
try { func(); }
catch (const fs::filesystem_error &)
{ {
return true; func();
}
catch (const fs::filesystem_error&)
{
return true;
} }
return false; return false;
}
void create_recursive_iterator(const fs::path & ph)
{
fs::recursive_directory_iterator it(ph);
}
} }
void create_recursive_iterator(const fs::path& ph)
{
fs::recursive_directory_iterator it(ph);
}
} // namespace
// ------------------------------------------------------------------------------------// // ------------------------------------------------------------------------------------//
int cpp_main(int, char*[]) int cpp_main(int, char*[])
{ {
// create_directories() tests --------------------------------------------------------// // create_directories() tests --------------------------------------------------------//
BOOST_TEST(!fs::create_directories("/")); // should be harmless BOOST_TEST(!fs::create_directories("/")); // should be harmless
path unique_dir = fs::unique_path(); // unique name in case tests running in parallel path unique_dir = fs::unique_path(); // unique name in case tests running in parallel
path unique_yy = unique_dir / "yy"; path unique_yy = unique_dir / "yy";
path unique_yya = unique_dir / "yya"; path unique_yya = unique_dir / "yya";
path unique_yy_zz = unique_dir / "yy" / "zz"; path unique_yy_zz = unique_dir / "yy" / "zz";
fs::remove_all(unique_dir); // make sure slate is blank fs::remove_all(unique_dir); // make sure slate is blank
BOOST_TEST(!fs::exists(unique_dir)); // reality check BOOST_TEST(!fs::exists(unique_dir)); // reality check
BOOST_TEST(fs::create_directories(unique_dir)); BOOST_TEST(fs::create_directories(unique_dir));
BOOST_TEST(fs::exists(unique_dir)); BOOST_TEST(fs::exists(unique_dir));
BOOST_TEST(fs::is_directory(unique_dir)); BOOST_TEST(fs::is_directory(unique_dir));
BOOST_TEST(fs::create_directories(unique_yy_zz)); BOOST_TEST(fs::create_directories(unique_yy_zz));
BOOST_TEST(fs::exists(unique_dir)); BOOST_TEST(fs::exists(unique_dir));
BOOST_TEST(fs::exists(unique_yy)); BOOST_TEST(fs::exists(unique_yy));
BOOST_TEST(fs::exists(unique_yy_zz)); BOOST_TEST(fs::exists(unique_yy_zz));
BOOST_TEST(fs::is_directory(unique_dir)); BOOST_TEST(fs::is_directory(unique_dir));
BOOST_TEST(fs::is_directory(unique_yy)); BOOST_TEST(fs::is_directory(unique_yy));
BOOST_TEST(fs::is_directory(unique_yy_zz)); BOOST_TEST(fs::is_directory(unique_yy_zz));
path is_a_file(unique_dir / "uu"); path is_a_file(unique_dir / "uu");
{ {
std::ofstream f(is_a_file.string().c_str()); std::ofstream f(is_a_file.string().c_str());
BOOST_TEST(!!f); BOOST_TEST(!!f);
} }
BOOST_TEST(throws_fs_error( BOOST_TEST(throws_fs_error(
boost::bind(fs::create_directories, is_a_file))); boost::bind(fs::create_directories, is_a_file)));
BOOST_TEST(throws_fs_error( BOOST_TEST(throws_fs_error(
boost::bind(fs::create_directories, is_a_file / "aa"))); boost::bind(fs::create_directories, is_a_file / "aa")));
// recursive_directory_iterator tests ----------------------------------------// // recursive_directory_iterator tests ----------------------------------------//
sys::error_code ec; sys::error_code ec;
fs::recursive_directory_iterator it("/no-such-path", ec); fs::recursive_directory_iterator it("/no-such-path", ec);
BOOST_TEST(ec); BOOST_TEST(ec);
BOOST_TEST(throws_fs_error( BOOST_TEST(throws_fs_error(
boost::bind(create_recursive_iterator, "/no-such-path"))); boost::bind(create_recursive_iterator, "/no-such-path")));
fs::remove(unique_dir / "uu"); fs::remove(unique_dir / "uu");
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
// These tests depends on ordering of directory entries, and that's guaranteed // These tests depends on ordering of directory entries, and that's guaranteed
// on Windows but not necessarily on other operating systems // on Windows but not necessarily on other operating systems
{ {
std::ofstream f(unique_yya.string().c_str()); std::ofstream f(unique_yya.string().c_str());
BOOST_TEST(!!f); BOOST_TEST(!!f);
} }
for (it = fs::recursive_directory_iterator(unique_dir); for (it = fs::recursive_directory_iterator(unique_dir);
it != fs::recursive_directory_iterator(); ++it) it != fs::recursive_directory_iterator(); ++it)
{ std::cout << it->path() << '\n'; } {
std::cout << it->path() << '\n';
}
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
BOOST_TEST(it.depth() == 0); BOOST_TEST(it.depth() == 0);
++it; ++it;
BOOST_TEST(it->path() == unique_yy_zz); BOOST_TEST(it->path() == unique_yy_zz);
BOOST_TEST(it.depth() == 1); BOOST_TEST(it.depth() == 1);
it.pop(); it.pop();
BOOST_TEST(it->path() == unique_yya); BOOST_TEST(it->path() == unique_yya);
BOOST_TEST(it.depth() == 0); BOOST_TEST(it.depth() == 0);
it++; it++;
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
it.disable_recursion_pending(); it.disable_recursion_pending();
++it; ++it;
BOOST_TEST(it->path() == unique_yya); BOOST_TEST(it->path() == unique_yya);
++it; ++it;
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
fs::remove(unique_yya); fs::remove(unique_yya);
#endif #endif
it = fs::recursive_directory_iterator(unique_yy_zz); it = fs::recursive_directory_iterator(unique_yy_zz);
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
BOOST_TEST(it.depth() == 0); BOOST_TEST(it.depth() == 0);
++it; ++it;
BOOST_TEST(it->path() == unique_yy_zz); BOOST_TEST(it->path() == unique_yy_zz);
BOOST_TEST(it.depth() == 1); BOOST_TEST(it.depth() == 1);
it++; it++;
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
it.disable_recursion_pending(); it.disable_recursion_pending();
++it; ++it;
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
++it; ++it;
it.pop(); it.pop();
BOOST_TEST(it == fs::recursive_directory_iterator()); BOOST_TEST(it == fs::recursive_directory_iterator());
ec.clear(); ec.clear();
BOOST_TEST(!ec); BOOST_TEST(!ec);
// check that two argument failed constructor creates the end iterator // check that two argument failed constructor creates the end iterator
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator());
== fs::recursive_directory_iterator()); BOOST_TEST(ec);
BOOST_TEST(ec);
fs::remove_all(unique_dir); // clean up behind ourselves fs::remove_all(unique_dir); // clean up behind ourselves
return ::boost::report_errors(); return ::boost::report_errors();
} }

View File

@ -25,11 +25,10 @@
// on Windows, except for standard libaries known to have wchar_t overloads for // on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str() // file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \ #if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads #define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
# define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available #else // use the native c_str, which will be narrow on POSIX, wide on Windows
#else // use the native c_str, which will be narrow on POSIX, wide on Windows #define BOOST_FILESYSTEM_C_STR c_str()
# define BOOST_FILESYSTEM_C_STR c_str()
#endif #endif
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -55,7 +54,7 @@ void verify_file(fs::path const& ph, std::string const& expected)
BOOST_TEST_EQ(contents, expected); BOOST_TEST_EQ(contents, expected);
if (contents != expected) if (contents != expected)
{ {
BOOST_THROW_EXCEPTION(std::runtime_error("verify_file failed: contents \"" + contents + "\" != \"" + expected + "\" in " + ph.string())); BOOST_THROW_EXCEPTION(std::runtime_error("verify_file failed: contents \"" + contents + "\" != \"" + expected + "\" in " + ph.string()));
} }
} }
@ -88,7 +87,9 @@ directory_tree collect_directory_tree(fs::path const& root_dir)
std::cout << "Collecting directory tree in: " << root_dir << '\n'; std::cout << "Collecting directory tree in: " << root_dir << '\n';
directory_tree tree; directory_tree tree;
fs::recursive_directory_iterator it(root_dir, fs::directory_options::skip_permission_denied | fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks), end; fs::recursive_directory_iterator it(root_dir, fs::directory_options::skip_permission_denied |
fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks);
fs::recursive_directory_iterator end;
while (it != end) while (it != end)
{ {
fs::path p = fs::relative(it->path(), root_dir); fs::path p = fs::relative(it->path(), root_dir);
@ -312,17 +313,18 @@ int main()
{ {
fs::create_symlink("f1", root_dir / "s1"); fs::create_symlink("f1", root_dir / "s1");
symlinks_supported = true; symlinks_supported = true;
std::cout << std::cout << " *** For information only ***\n"
" *** For information only ***\n" " create_symlink() attempt succeeded"
" create_symlink() attempt succeeded" << std::endl; << std::endl;
} }
catch (fs::filesystem_error& e) catch (fs::filesystem_error& e)
{ {
std::cout << std::cout << " *** For information only ***\n"
" *** For information only ***\n" " create_symlink() attempt failed\n"
" create_symlink() attempt failed\n" " filesystem_error.what() reports: "
" filesystem_error.what() reports: " << e.what() << "\n" << e.what() << "\n"
" create_symlink() may not be supported on this operating system or file system" << std::endl; " create_symlink() may not be supported on this operating system or file system"
<< std::endl;
} }
if (symlinks_supported) if (symlinks_supported)

View File

@ -16,9 +16,9 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
@ -28,24 +28,23 @@ using boost::filesystem::path;
#define PATH_CHECK(a, b) check(a, b, __LINE__) #define PATH_CHECK(a, b) check(a, b, __LINE__)
namespace namespace {
{ std::string platform(BOOST_PLATFORM);
std::string platform(BOOST_PLATFORM);
void check(const fs::path & source, void check(const fs::path& source, const std::string& expected, int line)
const std::string & expected, int line) {
{ if (source.generic_string() == expected)
if (source.generic_string()== expected) return; return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
std::cout << '(' << line << ") source.string(): \"" << source.string() std::cout << '(' << line << ") source.string(): \"" << source.string()
<< "\" != expected: \"" << expected << "\" != expected: \"" << expected
<< "\"" << std::endl; << "\"" << std::endl;
} }
void normalize_test() void normalize_test()
{ {
PATH_CHECK(path("").normalize(), ""); PATH_CHECK(path("").normalize(), "");
PATH_CHECK(path("/").normalize(), "/"); PATH_CHECK(path("/").normalize(), "/");
PATH_CHECK(path("//").normalize(), "//"); PATH_CHECK(path("//").normalize(), "//");
@ -63,14 +62,14 @@ namespace
PATH_CHECK(path("../foo").normalize(), "../foo"); PATH_CHECK(path("../foo").normalize(), "../foo");
PATH_CHECK(path("foo/..").normalize(), "."); PATH_CHECK(path("foo/..").normalize(), ".");
PATH_CHECK(path("foo/../").normalize(), "./."); PATH_CHECK(path("foo/../").normalize(), "./.");
PATH_CHECK((path("foo") / "..").normalize() , "."); PATH_CHECK((path("foo") / "..").normalize(), ".");
PATH_CHECK(path("foo/...").normalize(), "foo/..."); PATH_CHECK(path("foo/...").normalize(), "foo/...");
PATH_CHECK(path("foo/.../").normalize(), "foo/.../."); PATH_CHECK(path("foo/.../").normalize(), "foo/.../.");
PATH_CHECK(path("foo/..bar").normalize(), "foo/..bar"); PATH_CHECK(path("foo/..bar").normalize(), "foo/..bar");
PATH_CHECK(path("../f").normalize(), "../f"); PATH_CHECK(path("../f").normalize(), "../f");
PATH_CHECK(path("/../f").normalize(), "/../f"); PATH_CHECK(path("/../f").normalize(), "/../f");
PATH_CHECK(path("f/..").normalize(), "."); PATH_CHECK(path("f/..").normalize(), ".");
PATH_CHECK((path("f") / "..").normalize() , "."); PATH_CHECK((path("f") / "..").normalize(), ".");
PATH_CHECK(path("foo/../..").normalize(), ".."); PATH_CHECK(path("foo/../..").normalize(), "..");
PATH_CHECK(path("foo/../../").normalize(), "../."); PATH_CHECK(path("foo/../../").normalize(), "../.");
PATH_CHECK(path("foo/../../..").normalize(), "../.."); PATH_CHECK(path("foo/../../..").normalize(), "../..");
@ -114,59 +113,59 @@ namespace
if (platform == "Windows") if (platform == "Windows")
{ {
PATH_CHECK(path("c:..").normalize(), "c:.."); PATH_CHECK(path("c:..").normalize(), "c:..");
PATH_CHECK(path("c:foo/..").normalize(), "c:"); PATH_CHECK(path("c:foo/..").normalize(), "c:");
PATH_CHECK(path("c:foo/../").normalize(), "c:."); PATH_CHECK(path("c:foo/../").normalize(), "c:.");
PATH_CHECK(path("c:/foo/..").normalize(), "c:/"); PATH_CHECK(path("c:/foo/..").normalize(), "c:/");
PATH_CHECK(path("c:/foo/../").normalize(), "c:/."); PATH_CHECK(path("c:/foo/../").normalize(), "c:/.");
PATH_CHECK(path("c:/..").normalize(), "c:/.."); PATH_CHECK(path("c:/..").normalize(), "c:/..");
PATH_CHECK(path("c:/../").normalize(), "c:/../."); PATH_CHECK(path("c:/../").normalize(), "c:/../.");
PATH_CHECK(path("c:/../..").normalize(), "c:/../.."); PATH_CHECK(path("c:/../..").normalize(), "c:/../..");
PATH_CHECK(path("c:/../../").normalize(), "c:/../../."); PATH_CHECK(path("c:/../../").normalize(), "c:/../../.");
PATH_CHECK(path("c:/../foo").normalize(), "c:/../foo"); PATH_CHECK(path("c:/../foo").normalize(), "c:/../foo");
PATH_CHECK(path("c:/../foo/").normalize(), "c:/../foo/."); PATH_CHECK(path("c:/../foo/").normalize(), "c:/../foo/.");
PATH_CHECK(path("c:/../../foo").normalize(), "c:/../../foo"); PATH_CHECK(path("c:/../../foo").normalize(), "c:/../../foo");
PATH_CHECK(path("c:/../../foo/").normalize(), "c:/../../foo/."); PATH_CHECK(path("c:/../../foo/").normalize(), "c:/../../foo/.");
PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo"); PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo");
} }
else // POSIX else // POSIX
{ {
PATH_CHECK(path("c:..").normalize(), "c:.."); PATH_CHECK(path("c:..").normalize(), "c:..");
PATH_CHECK(path("c:foo/..").normalize(), "."); PATH_CHECK(path("c:foo/..").normalize(), ".");
PATH_CHECK(path("c:foo/../").normalize(), "./."); PATH_CHECK(path("c:foo/../").normalize(), "./.");
PATH_CHECK(path("c:/foo/..").normalize(), "c:"); PATH_CHECK(path("c:/foo/..").normalize(), "c:");
PATH_CHECK(path("c:/foo/../").normalize(), "c:/."); PATH_CHECK(path("c:/foo/../").normalize(), "c:/.");
PATH_CHECK(path("c:/..").normalize(), "."); PATH_CHECK(path("c:/..").normalize(), ".");
PATH_CHECK(path("c:/../").normalize(), "./."); PATH_CHECK(path("c:/../").normalize(), "./.");
PATH_CHECK(path("c:/../..").normalize(), ".."); PATH_CHECK(path("c:/../..").normalize(), "..");
PATH_CHECK(path("c:/../../").normalize(), "../."); PATH_CHECK(path("c:/../../").normalize(), "../.");
PATH_CHECK(path("c:/../foo").normalize(), "foo"); PATH_CHECK(path("c:/../foo").normalize(), "foo");
PATH_CHECK(path("c:/../foo/").normalize(), "foo/."); PATH_CHECK(path("c:/../foo/").normalize(), "foo/.");
PATH_CHECK(path("c:/../../foo").normalize(), "../foo"); PATH_CHECK(path("c:/../../foo").normalize(), "../foo");
PATH_CHECK(path("c:/../../foo/").normalize(), "../foo/."); PATH_CHECK(path("c:/../../foo/").normalize(), "../foo/.");
PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo"); PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo");
} }
} }
// misc_test ------------------------------------------------------------------------// // misc_test ------------------------------------------------------------------------//
void misc_test() void misc_test()
{ {
fs::path p; fs::path p;
fs::initial_path<fs::path>(); fs::initial_path< fs::path >();
fs::initial_path<fs::wpath>(); fs::initial_path< fs::wpath >();
p.file_string(); p.file_string();
p.directory_string(); p.directory_string();
} }
// path_rename_test -----------------------------------------------------------------// // path_rename_test -----------------------------------------------------------------//
void path_rename_test() void path_rename_test()
{ {
fs::path p("foo/bar/blah"); fs::path p("foo/bar/blah");
BOOST_TEST_EQ(path("foo/bar/blah").remove_leaf(), "foo/bar"); BOOST_TEST_EQ(path("foo/bar/blah").remove_leaf(), "foo/bar");
@ -178,74 +177,71 @@ namespace
if (platform == "Windows") if (platform == "Windows")
{ {
BOOST_TEST_EQ(path("foo\\bar\\blah").remove_leaf(), "foo\\bar"); BOOST_TEST_EQ(path("foo\\bar\\blah").remove_leaf(), "foo\\bar");
p = "foo\\bar\\blah"; p = "foo\\bar\\blah";
BOOST_TEST_EQ(p.branch_path(), "foo\\bar"); BOOST_TEST_EQ(p.branch_path(), "foo\\bar");
} }
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
int cpp_main(int /*argc*/, char* /*argv*/[]) int cpp_main(int /*argc*/, char* /*argv*/[])
{ {
// The choice of platform is make at runtime rather than compile-time // The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though // so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested. // only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
? "Windows" std::cout << "Platform is " << platform << '\n';
: "POSIX";
std::cout << "Platform is " << platform << '\n';
BOOST_TEST(fs::initial_path() == fs::current_path()); BOOST_TEST(fs::initial_path() == fs::current_path());
//path::default_name_check(fs::no_check); //path::default_name_check(fs::no_check);
fs::directory_entry de("foo/bar"); fs::directory_entry de("foo/bar");
de.replace_leaf("", fs::file_status(), fs::file_status()); de.replace_leaf("", fs::file_status(), fs::file_status());
//de.leaf(); //de.leaf();
//de.string(); //de.string();
fs::path ng(" no-way, Jose"); fs::path ng(" no-way, Jose");
BOOST_TEST(!fs::is_regular(ng)); // verify deprecated name still works BOOST_TEST(!fs::is_regular(ng)); // verify deprecated name still works
BOOST_TEST(!fs::symbolic_link_exists("nosuchfileordirectory")); BOOST_TEST(!fs::symbolic_link_exists("nosuchfileordirectory"));
misc_test(); misc_test();
path_rename_test(); path_rename_test();
normalize_test(); normalize_test();
BOOST_TEST(fs::path("foo/bar").generic() == fs::path("foo/bar")); BOOST_TEST(fs::path("foo/bar").generic() == fs::path("foo/bar"));
// extension() tests ---------------------------------------------------------// // extension() tests ---------------------------------------------------------//
BOOST_TEST(fs::extension("a/b") == ""); BOOST_TEST(fs::extension("a/b") == "");
BOOST_TEST(fs::extension("a/b.txt") == ".txt"); BOOST_TEST(fs::extension("a/b.txt") == ".txt");
BOOST_TEST(fs::extension("a/b.") == "."); BOOST_TEST(fs::extension("a/b.") == ".");
BOOST_TEST(fs::extension("a.b.c") == ".c"); BOOST_TEST(fs::extension("a.b.c") == ".c");
BOOST_TEST(fs::extension("a.b.c.") == "."); BOOST_TEST(fs::extension("a.b.c.") == ".");
BOOST_TEST(fs::extension("") == ""); BOOST_TEST(fs::extension("") == "");
BOOST_TEST(fs::extension("a/") == ""); BOOST_TEST(fs::extension("a/") == "");
// basename() tests ----------------------------------------------------------// // basename() tests ----------------------------------------------------------//
BOOST_TEST(fs::basename("b") == "b"); BOOST_TEST(fs::basename("b") == "b");
BOOST_TEST(fs::basename("a/b.txt") == "b"); BOOST_TEST(fs::basename("a/b.txt") == "b");
BOOST_TEST(fs::basename("a/b.") == "b"); BOOST_TEST(fs::basename("a/b.") == "b");
BOOST_TEST(fs::basename("a.b.c") == "a.b"); BOOST_TEST(fs::basename("a.b.c") == "a.b");
BOOST_TEST(fs::basename("a.b.c.") == "a.b.c"); BOOST_TEST(fs::basename("a.b.c.") == "a.b.c");
BOOST_TEST(fs::basename("") == ""); BOOST_TEST(fs::basename("") == "");
// change_extension tests ---------------------------------------------------// // change_extension tests ---------------------------------------------------//
BOOST_TEST(fs::change_extension("a.txt", ".tex").string() == "a.tex"); BOOST_TEST(fs::change_extension("a.txt", ".tex").string() == "a.tex");
BOOST_TEST(fs::change_extension("a.", ".tex").string() == "a.tex"); BOOST_TEST(fs::change_extension("a.", ".tex").string() == "a.tex");
BOOST_TEST(fs::change_extension("a", ".txt").string() == "a.txt"); BOOST_TEST(fs::change_extension("a", ".txt").string() == "a.txt");
BOOST_TEST(fs::change_extension("a.b.txt", ".tex").string() == "a.b.tex"); BOOST_TEST(fs::change_extension("a.b.txt", ".tex").string() == "a.b.tex");
// see the rationale in html docs for explanation why this works // see the rationale in html docs for explanation why this works
BOOST_TEST(fs::change_extension("", ".png").string() == ".png"); BOOST_TEST(fs::change_extension("", ".png").string() == ".png");
return ::boost::report_errors(); return ::boost::report_errors();
} }

View File

@ -6,76 +6,76 @@
class path class path
{ {
public: public:
path( const char * ) path(const char*)
{ {
std::cout << "path( const char * )\n"; std::cout << "path( const char * )\n";
} }
path( const std::string & ) path(const std::string&)
{ {
std::cout << "path( std::string & )\n"; std::cout << "path( std::string & )\n";
} }
// for maximum efficiency, either signature must work // for maximum efficiency, either signature must work
# ifdef BY_VALUE #ifdef BY_VALUE
operator const std::string() const operator const std::string() const
# else #else
operator const std::string&() const operator const std::string&() const
# endif #endif
{ {
std::cout << "operator string\n"; std::cout << "operator string\n";
return m_path; return m_path;
} }
#ifdef NAMED_CONVERSION #ifdef NAMED_CONVERSION
std::string string() const std::string string() const
{ {
std::cout << "std::string string() const\n"; std::cout << "std::string string() const\n";
return m_path; return m_path;
} }
#endif #endif
private: private:
std::string m_path; std::string m_path;
}; };
bool operator==( const path &, const path & ) bool operator==(const path&, const path&)
{ {
std::cout << "operator==( const path &, const path & )\n"; std::cout << "operator==( const path &, const path & )\n";
return true; return true;
} }
// These are the critical use cases. If any of these don't compile, usability // These are the critical use cases. If any of these don't compile, usability
// is unacceptably degraded. // is unacceptably degraded.
void f( const path & ) void f(const path&)
{ {
std::cout << "f( const path & )\n"; std::cout << "f( const path & )\n";
} }
int main() int main()
{ {
f( "foo" ); f("foo");
f( std::string( "foo" ) ); f(std::string("foo"));
f( path( "foo" ) ); f(path("foo"));
std::cout << '\n'; std::cout << '\n';
std::string s1( path( "foo" ) ); std::string s1(path("foo"));
std::string s2 = path( "foo" ); std::string s2 = path("foo");
s2 = path( "foo" ); s2 = path("foo");
#ifdef NAMED_CONVERSION #ifdef NAMED_CONVERSION
s2 = path( "foo" ).string(); s2 = path("foo").string();
#endif #endif
std::cout << '\n'; std::cout << '\n';
// these must call bool path( const path &, const path & ); // these must call bool path( const path &, const path & );
path( "foo" ) == path( "foo" ); path("foo") == path("foo");
path( "foo" ) == "foo"; path("foo") == "foo";
path( "foo" ) == std::string( "foo" ); path("foo") == std::string("foo");
"foo" == path( "foo" ); "foo" == path("foo");
std::string( "foo" ) == path( "foo" ); std::string("foo") == path("foo");
return 0; return 0;
} }

View File

@ -14,26 +14,26 @@
#include <iostream> #include <iostream>
#include <exception> #include <exception>
int main( int argc, char * argv[] ) int main(int argc, char* argv[])
{ {
boost::filesystem::path::default_name_check( boost::filesystem::native ); boost::filesystem::path::default_name_check(boost::filesystem::native);
if ( argc != 3 ) if (argc != 3)
{ {
std::cout << "Usage: equivalent path1 path2\n"; std::cout << "Usage: equivalent path1 path2\n";
return 2; return 2;
} }
bool eq; bool eq;
try try
{ {
eq = boost::filesystem::equivalent( argv[1], argv[2] ); eq = boost::filesystem::equivalent(argv[1], argv[2]);
} }
catch ( const std::exception & ex ) catch (const std::exception& ex)
{ {
std::cout << ex.what() << "\n"; std::cout << ex.what() << "\n";
return 3; return 3;
} }
std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n"); std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n");
return !eq; return !eq;
} }

View File

@ -19,7 +19,7 @@ int main()
{ {
fs::directory_iterator const it; fs::directory_iterator const it;
BOOST_FOREACH( fs::path const& p, it ) BOOST_FOREACH(fs::path const& p, it)
{ {
p.string(); p.string();
} }
@ -30,7 +30,7 @@ int main()
{ {
fs::directory_iterator const it; fs::directory_iterator const it;
for( fs::path const& p: it ) for (fs::path const& p : it)
{ {
p.string(); p.string();
} }
@ -41,7 +41,7 @@ int main()
{ {
fs::recursive_directory_iterator it; fs::recursive_directory_iterator it;
BOOST_FOREACH( fs::path const& p, it ) BOOST_FOREACH(fs::path const& p, it)
{ {
p.string(); p.string();
} }
@ -52,7 +52,7 @@ int main()
{ {
fs::recursive_directory_iterator const it; fs::recursive_directory_iterator const it;
for( fs::path const& p: it ) for (fs::path const& p : it)
{ {
p.string(); p.string();
} }

View File

@ -11,18 +11,18 @@
// See deprecated_test for tests of deprecated features // See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <string> #include <string>
@ -35,135 +35,136 @@ namespace fs = boost::filesystem;
#include <boost/config.hpp> #include <boost/config.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE #ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::remove; } namespace std {
using ::remove;
}
#endif #endif
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
namespace namespace {
{ bool cleanup = true;
bool cleanup = true;
void test(const fs::path & p) void test(const fs::path& p)
{ {
fs::remove(p); fs::remove(p);
{ {
std::cout << " in test 1\n"; std::cout << " in test 1\n";
fs::filebuf fb1; fs::filebuf fb1;
fb1.open(p, std::ios_base::out); fb1.open(p, std::ios_base::out);
BOOST_TEST(fb1.is_open()); BOOST_TEST(fb1.is_open());
} }
{ {
std::cout << " in test 2\n"; std::cout << " in test 2\n";
fs::filebuf fb2; fs::filebuf fb2;
fb2.open(p, std::ios_base::in); fb2.open(p, std::ios_base::in);
BOOST_TEST(fb2.is_open()); BOOST_TEST(fb2.is_open());
} }
{ {
std::cout << " in test 3\n"; std::cout << " in test 3\n";
fs::ifstream tfs(p); fs::ifstream tfs(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 4\n"; std::cout << " in test 4\n";
fs::ifstream tfs(p / p.filename()); // should fail fs::ifstream tfs(p / p.filename()); // should fail
BOOST_TEST(!tfs.is_open()); BOOST_TEST(!tfs.is_open());
} }
{ {
std::cout << " in test 5\n"; std::cout << " in test 5\n";
fs::ifstream tfs(p, std::ios_base::in); fs::ifstream tfs(p, std::ios_base::in);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 6\n"; std::cout << " in test 6\n";
fs::ifstream tfs; fs::ifstream tfs;
tfs.open(p); tfs.open(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 7\n"; std::cout << " in test 7\n";
fs::ifstream tfs; fs::ifstream tfs;
tfs.open(p, std::ios_base::in); tfs.open(p, std::ios_base::in);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 8\n"; std::cout << " in test 8\n";
fs::ofstream tfs(p); fs::ofstream tfs(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 9\n"; std::cout << " in test 9\n";
fs::ofstream tfs(p, std::ios_base::out); fs::ofstream tfs(p, std::ios_base::out);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 10\n"; std::cout << " in test 10\n";
fs::ofstream tfs; fs::ofstream tfs;
tfs.open(p); tfs.open(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 11\n"; std::cout << " in test 11\n";
fs::ofstream tfs; fs::ofstream tfs;
tfs.open(p, std::ios_base::out); tfs.open(p, std::ios_base::out);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 12\n"; std::cout << " in test 12\n";
fs::fstream tfs(p); fs::fstream tfs(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 13\n"; std::cout << " in test 13\n";
fs::fstream tfs(p, std::ios_base::in|std::ios_base::out); fs::fstream tfs(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 14\n"; std::cout << " in test 14\n";
fs::fstream tfs; fs::fstream tfs;
tfs.open(p); tfs.open(p);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
{ {
std::cout << " in test 15\n"; std::cout << " in test 15\n";
fs::fstream tfs; fs::fstream tfs;
tfs.open(p, std::ios_base::in|std::ios_base::out); tfs.open(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open()); BOOST_TEST(tfs.is_open());
} }
if (cleanup) if (cleanup)
fs::remove(p); fs::remove(p);
} // test } // test
} // unnamed namespace } // unnamed namespace
int cpp_main(int argc, char*[]) int cpp_main(int argc, char*[])
{ {
if (argc > 1) cleanup = false; if (argc > 1)
cleanup = false;
std::cout << "BOOST_FILESYSTEM_C_STR defined as \"" std::cout << "BOOST_FILESYSTEM_C_STR defined as \""
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n"; << BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n";
// test narrow characters // test narrow characters
std::cout << "narrow character tests:\n"; std::cout << "narrow character tests:\n";
test("narrow_fstream_test"); test("narrow_fstream_test");
// So that tests are run with known encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);
fs::path::imbue(loc);
// So that tests are run with known encoding, use Boost UTF-8 codecvt // test with some wide characters
std::locale global_loc = std::locale(); // \u2780 is circled 1 against white background == e2 9e 80 in UTF-8
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet); // \u2781 is circled 2 against white background == e2 9e 81 in UTF-8
fs::path::imbue(loc); // \u263A is a white smiling face
std::cout << "\nwide character tests:\n";
std::wstring ws(L"wide_fstream_test_");
ws += 0x2780;
ws += 0x263A;
test(ws);
// test with some wide characters return ::boost::report_errors();
// \u2780 is circled 1 against white background == e2 9e 80 in UTF-8
// \u2781 is circled 2 against white background == e2 9e 81 in UTF-8
// \u263A is a white smiling face
std::cout << "\nwide character tests:\n";
std::wstring ws(L"wide_fstream_test_");
ws += 0x2780;
ws += 0x263A;
test(ws);
return ::boost::report_errors();
} }

View File

@ -5,4 +5,3 @@ int main(void)
boost::filesystem::copy_file("a", "b"); boost::filesystem::copy_file("a", "b");
return 0; return 0;
} }

View File

@ -7,11 +7,11 @@
int main() int main()
{ {
std::string pathname = "/some/filesystem/path/%%%%"; std::string pathname = "/some/filesystem/path/%%%%";
boost::filesystem::path path(pathname); boost::filesystem::path path(pathname);
std::wcout << path.wstring() << std::endl; std::wcout << path.wstring() << std::endl;
return 0; return 0;
} }

View File

@ -8,7 +8,7 @@
int main() int main()
{ {
boost::filesystem::path dir("/"); boost::filesystem::path dir("/");
for (char c : dir.filename().string()) for (char c : dir.filename().string())
printf("%c\n", c); printf("%c\n", c);
} }

View File

@ -5,16 +5,18 @@ namespace fs = boost::filesystem;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
try try
{ {
fs::path my_path("test/test.txt"); fs::path my_path("test/test.txt");
cout << "current path is " << my_path << endl; cout << "current path is " << my_path << endl;
cout << "parent path is " << my_path.parent_path() << endl; cout << "parent path is " << my_path.parent_path() << endl;
} }
catch(std::exception& e) { catch (std::exception& e)
cerr << endl << "Error during execution: " << e.what() << endl << endl; {
return EXIT_FAILURE; cerr << endl
} << "Error during execution: " << e.what() << endl
return EXIT_SUCCESS; << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} }

View File

@ -8,7 +8,7 @@ boost::mutex mut;
#define FNAME ("remove-test") #define FNAME ("remove-test")
void remover() void remover()
{ {
while(1) while (1)
{ {
boost::filesystem::remove(FNAME); boost::filesystem::remove(FNAME);
} }
@ -16,7 +16,8 @@ void remover()
void creater() void creater()
{ {
for(int i=0; i<100000; i++) std::fstream(FNAME, std::fstream::out); for (int i = 0; i < 100000; i++)
std::fstream(FNAME, std::fstream::out);
} }
int main() int main()
@ -24,15 +25,16 @@ int main()
boost::filesystem::remove(FNAME); boost::filesystem::remove(FNAME);
boost::filesystem::remove(FNAME); boost::filesystem::remove(FNAME);
std::cout << std::cout << "If you got this far, it's OK to remove a file that doesn't exist\n"
"If you got this far, it's OK to remove a file that doesn't exist\n" "Now trying with one creator thread and two remover threads.\n"
"Now trying with one creator thread and two remover threads.\n" "This is likely to crash after just a few seconds at most."
"This is likely to crash after just a few seconds at most." << << std::endl;
std::endl;
boost::thread c(creater), r1(remover), r2(remover); boost::thread c(creater), r1(remover), r2(remover);
c.join(); c.join();
r1.interrupt(); r1.join(); r1.interrupt();
r2.interrupt(); r2.join(); r1.join();
r2.interrupt();
r2.join();
} }

View File

@ -8,18 +8,17 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
using namespace boost::adaptors; using namespace boost::adaptors;
int main() { int main()
{
fs::recursive_directory_iterator beg("."), end; fs::recursive_directory_iterator beg("."), end;
auto fileFilter = [](fs::path const & path) auto fileFilter = [](fs::path const& path) {
{ return is_regular_file(path);
return is_regular_file(path);
}; };
std::vector<fs::path> paths; std::vector< fs::path > paths;
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), std::back_inserter(paths));
std::back_inserter(paths));
for(auto& p : paths) for (auto& p : paths)
std::cout << p << "\n"; std::cout << p << "\n";
} }

View File

@ -6,32 +6,32 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main(void) { int main(void)
{
std::locale global_loc = std::locale(); std::locale global_loc = std::locale();
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950<wchar_t>); std::locale loc(global_loc, new stdext::cvt::codecvt_cp950< wchar_t >);
fs::path::imbue(loc); fs::path::imbue(loc);
std::cout << std::cout << "HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
"HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n" "WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n"
"WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n" "EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW."
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW." << std::endl; << std::endl;
fs::recursive_directory_iterator end; fs::recursive_directory_iterator end;
fs::recursive_directory_iterator iter fs::recursive_directory_iterator iter("C:/boost/test-files/utf-8");
("C:/boost/test-files/utf-8");
while (iter != end) while (iter != end)
{
if (fs::is_directory(*iter))
{ {
std::cout << "[directory] " << iter->path().generic_string() << std::endl; if (fs::is_directory(*iter))
{
std::cout << "[directory] " << iter->path().generic_string() << std::endl;
}
else if (fs::is_regular(*iter))
{
std::cout << " [file] " << iter->path().generic_string() << std::endl;
}
++iter;
} }
else if (fs::is_regular(*iter)) return 0;
{
std::cout << " [file] " << iter->path().generic_string() << std::endl;
}
++iter;
}
return 0;
} }

View File

@ -4,17 +4,15 @@ using boost::filesystem::path;
int main() int main()
{ {
std::cout << path("a").stem() << std::endl; std::cout << path("a").stem() << std::endl;
std::cout << path("a/").stem() << std::endl; std::cout << path("a/").stem() << std::endl;
std::cout << path("a/b").stem() << std::endl; std::cout << path("a/b").stem() << std::endl;
std::cout << path("a/b/").stem() << std::endl; std::cout << path("a/b/").stem() << std::endl;
std::cout << path("a/b/c").stem() << std::endl; std::cout << path("a/b/c").stem() << std::endl;
std::cout << path("a/b/c/").stem() << std::endl; std::cout << path("a/b/c/").stem() << std::endl;
std::cout << path("a/b/c/d").stem() << std::endl; std::cout << path("a/b/c/d").stem() << std::endl;
std::cout << path("a/b/c/d/").stem() << std::endl; std::cout << path("a/b/c/d/").stem() << std::endl;
std::cout << path("a/b/c/d/e").stem() << std::endl; std::cout << path("a/b/c/d/e").stem() << std::endl;
std::cout << path("a/b/c/d/e/").stem() << std::endl; std::cout << path("a/b/c/d/e/").stem() << std::endl;
return 0; return 0;
} }

View File

@ -14,11 +14,11 @@ using namespace boost::filesystem;
class Test class Test
{ {
public: public:
~Test() ~Test()
{ {
path p(L"C:\\TEMP\\"); path p(L"C:\\TEMP\\");
path r(p / "narrow"); path r(p / "narrow");
} }
}; };
// path p("narrow"); // path p("narrow");
@ -30,7 +30,7 @@ public:
Test test1; Test test1;
Test test2; Test test2;
int cpp_main(int, char* []) int cpp_main(int, char*[])
{ {
return 0; return 0;
} }

View File

@ -15,6 +15,6 @@ namespace fs = boost::filesystem;
int main() int main()
{ {
BOOST_TEST_THROWS( fs::copy( "/tmp/non-existent-a", "/tmp/non-existent-b" ), std::exception ); BOOST_TEST_THROWS(fs::copy("/tmp/non-existent-a", "/tmp/non-existent-b"), std::exception);
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,7 +1,7 @@
// Before running this test: export LANG=foo // Before running this test: export LANG=foo
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
int main() { int main()
boost::filesystem::path("/abc").root_directory(); {
boost::filesystem::path("/abc").root_directory();
} }

View File

@ -1,10 +1,9 @@
#include "boost/filesystem.hpp" #include "boost/filesystem.hpp"
static const boost::filesystem::path::codecvt_type &dummy = static const boost::filesystem::path::codecvt_type& dummy =
boost::filesystem::path::codecvt(); boost::filesystem::path::codecvt();
int main() int main()
{ {
return 0; return 0;
} }

View File

@ -31,10 +31,10 @@ namespace fs = boost::filesystem;
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
cout << "Hello, 9219" << endl; cout << "Hello, 9219" << endl;
cout << "This is a test for non-Windows systems" << endl; cout << "This is a test for non-Windows systems" << endl;
BOOST_TEST(fs::exists(const_cast<char*>("."))); BOOST_TEST(fs::exists(const_cast< char* >(".")));
return ::boost::report_errors(); return ::boost::report_errors();
} // cpp_main } // cpp_main

View File

@ -21,16 +21,17 @@ namespace fs = boost::filesystem;
struct TmpDir struct TmpDir
{ {
fs::path path; fs::path path;
TmpDir(const fs::path& base): path(fs::absolute(base) / fs::unique_path()) TmpDir(const fs::path& base) :
{ path(fs::absolute(base) / fs::unique_path())
fs::create_directories(path); {
} fs::create_directories(path);
~TmpDir() }
{ ~TmpDir()
boost::system::error_code ec; {
fs::remove_all(path, ec); boost::system::error_code ec;
} fs::remove_all(path, ec);
}
}; };
// Test fs::canonical for various path in a Windows directory junction point // Test fs::canonical for various path in a Windows directory junction point
@ -38,48 +39,47 @@ struct TmpDir
int main() int main()
{ {
const fs::path cwd = fs::current_path(); const fs::path cwd = fs::current_path();
const TmpDir tmp(cwd); const TmpDir tmp(cwd);
const fs::path junction = tmp.path / "junction"; const fs::path junction = tmp.path / "junction";
const fs::path real = tmp.path / "real"; const fs::path real = tmp.path / "real";
const fs::path subDir = "sub"; const fs::path subDir = "sub";
fs::create_directories(real / subDir); fs::create_directories(real / subDir);
fs::current_path(tmp.path); fs::current_path(tmp.path);
BOOST_TEST(std::system("mklink /j junction real") == 0); BOOST_TEST(std::system("mklink /j junction real") == 0);
BOOST_TEST(fs::exists(junction)); BOOST_TEST(fs::exists(junction));
// Due to a bug there was a dependency on the current path so try the below for all: // Due to a bug there was a dependency on the current path so try the below for all:
std::vector<fs::path> paths; std::vector< fs::path > paths;
paths.push_back(cwd); paths.push_back(cwd);
paths.push_back(junction); paths.push_back(junction);
paths.push_back(real); paths.push_back(real);
paths.push_back(junction / subDir); paths.push_back(junction / subDir);
paths.push_back(real / subDir); paths.push_back(real / subDir);
for (std::vector<fs::path>::iterator it = paths.begin(); it != paths.end(); ++it) for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it)
{ {
std::cout << "Testing in " << *it << std::endl; std::cout << "Testing in " << *it << std::endl;
fs::current_path(*it); fs::current_path(*it);
// Used by canonical, must work too // Used by canonical, must work too
BOOST_TEST(fs::read_symlink(junction) == real); BOOST_TEST(fs::read_symlink(junction) == real);
BOOST_TEST(fs::canonical(junction) == real); BOOST_TEST(fs::canonical(junction) == real);
BOOST_TEST(fs::canonical(junction / subDir) == real / subDir); BOOST_TEST(fs::canonical(junction / subDir) == real / subDir);
} }
// Restore the original current directory so that temp directory can be removed // Restore the original current directory so that temp directory can be removed
fs::current_path(cwd); fs::current_path(cwd);
return boost::report_errors(); return boost::report_errors();
} }
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK) #else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
int main() int main()
{ {
std::cout << "Skipping test as the target system does not support mklink." << std::endl; std::cout << "Skipping test as the target system does not support mklink." << std::endl;
return 0; return 0;
} }
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK) #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@ -5,10 +5,10 @@
void myFunc() void myFunc()
{ {
using namespace boost::filesystem; using namespace boost::filesystem;
copy_options opt(copy_options::overwrite_existing); copy_options opt(copy_options::overwrite_existing);
copy_file(path("p1"),path("p2"),copy_options::overwrite_existing); copy_file(path("p1"), path("p2"), copy_options::overwrite_existing);
// copy_file(path("p1"),path("p2"),opt); // copy_file(path("p1"),path("p2"),opt);
} }

View File

@ -19,12 +19,15 @@
#include <cerrno> #include <cerrno>
#ifdef NDEBUG #ifdef NDEBUG
# error This program depends on assert() so makes no sense if NDEBUG is defined #error This program depends on assert() so makes no sense if NDEBUG is defined
#endif #endif
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
{ std::ofstream file("out"); file << "contents"; } {
std::ofstream file("out");
file << "contents";
}
assert(!::symlink("out", "sym")); assert(!::symlink("out", "sym"));

View File

@ -31,9 +31,9 @@ namespace fs = boost::filesystem;
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
cout << "Hello, filesystem world" << endl; cout << "Hello, filesystem world" << endl;
BOOST_TEST(fs::exists(".")); BOOST_TEST(fs::exists("."));
return ::boost::report_errors(); return ::boost::report_errors();
} // cpp_main } // cpp_main

View File

@ -11,18 +11,18 @@
// See deprecated_test for tests of deprecated features // See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/cerrno.hpp> #include <boost/cerrno.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@ -39,16 +39,15 @@ using std::cout;
using std::endl; using std::endl;
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
# include <windows.h> #include <windows.h>
#endif #endif
namespace namespace {
{ typedef int errno_t;
typedef int errno_t; std::string platform(BOOST_PLATFORM);
std::string platform(BOOST_PLATFORM); bool report_throws = false;
bool report_throws = false; bool cleanup = true;
bool cleanup = true; bool skip_long_windows_tests = false;
bool skip_long_windows_tests = false; unsigned short language_id; // 0 except for Windows
unsigned short language_id; // 0 except for Windows
} // unnamed namespace } // unnamed namespace
@ -60,73 +59,73 @@ namespace
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
// document state of critical macros // document state of critical macros
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API is defined\n"; cout << "BOOST_POSIX_API is defined\n";
#endif #endif
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API is defined\n"; cout << "BOOST_WINDOWS_API is defined\n";
#endif #endif
for (; argc > 1; --argc, ++argv) for (; argc > 1; --argc, ++argv)
{
//if (*argv[1]=='-' && *(argv[1]+1)=='t')
// report_throws = true;
//else if (*argv[1]=='-' && *(argv[1]+1)=='x')
// cleanup = false;
//else if (*argv[1]=='-' && *(argv[1]+1)=='w')
// skip_long_windows_tests = true;
}
// The choice of platform to test is made at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
# if defined(BOOST_POSIX_API)
platform = "POSIX";
# elif defined(BOOST_WINDOWS_API)
platform = "Windows";
# if !defined(__MINGW32__) && !defined(__CYGWIN__)
language_id = ::GetUserDefaultUILanguage();
# else
language_id = 0x0409; // Assume US English
# endif
# else
# error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
# endif
cout << "API is " << platform << endl;
cout << "initial_path() is " << fs::initial_path() << endl;
fs::path ip = fs::initial_path();
for (fs::path::const_iterator it = ip.begin(); it != ip.end(); ++it)
{
if (it != ip.begin())
cout << ", ";
cout << *it;
}
cout << endl;
// From the root, walk the directory tree looking for a permissions error
fs::recursive_directory_iterator it("/");
fs::recursive_directory_iterator end_it;
// The increment function has an invarient that it always makes progress,
// so even if an error occurs this loop will eventually terminate.
while (it != end_it)
{
error_code ec;
fs::path init_path = it->path();
it.increment(ec);
if (ec)
{ {
cout << "initial path: " << init_path << endl; //if (*argv[1]=='-' && *(argv[1]+1)=='t')
cout << "error_code: " << ec.value() << " with msg: " << ec.message() << endl; // report_throws = true;
if (it != end_it) //else if (*argv[1]=='-' && *(argv[1]+1)=='x')
cout << "post-increment path: " << it->path() << endl; // cleanup = false;
//else if (*argv[1]=='-' && *(argv[1]+1)=='w')
// skip_long_windows_tests = true;
} }
}
cout << "returning from main()" << endl; // The choice of platform to test is made at runtime rather than compile-time
return ::boost::report_errors(); // so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
#if defined(BOOST_POSIX_API)
platform = "POSIX";
#elif defined(BOOST_WINDOWS_API)
platform = "Windows";
#if !defined(__MINGW32__) && !defined(__CYGWIN__)
language_id = ::GetUserDefaultUILanguage();
#else
language_id = 0x0409; // Assume US English
#endif
#else
#error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
#endif
cout << "API is " << platform << endl;
cout << "initial_path() is " << fs::initial_path() << endl;
fs::path ip = fs::initial_path();
for (fs::path::const_iterator it = ip.begin(); it != ip.end(); ++it)
{
if (it != ip.begin())
cout << ", ";
cout << *it;
}
cout << endl;
// From the root, walk the directory tree looking for a permissions error
fs::recursive_directory_iterator it("/");
fs::recursive_directory_iterator end_it;
// The increment function has an invarient that it always makes progress,
// so even if an error occurs this loop will eventually terminate.
while (it != end_it)
{
error_code ec;
fs::path init_path = it->path();
it.increment(ec);
if (ec)
{
cout << "initial path: " << init_path << endl;
cout << "error_code: " << ec.value() << " with msg: " << ec.message() << endl;
if (it != end_it)
cout << "post-increment path: " << it->path() << endl;
}
}
cout << "returning from main()" << endl;
return ::boost::report_errors();
} // main } // main

View File

@ -16,140 +16,141 @@
#include <cstddef> #include <cstddef>
# include <windows.h> #include <windows.h>
# include <winnt.h> #include <winnt.h>
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma comment(lib, "Advapi32.lib") #pragma comment(lib, "Advapi32.lib")
#endif #endif
// Test correct boost::filesystem::status when reparse point ReparseTag set to IO_REPARSE_TAG_FILE_PLACEHOLDER // Test correct boost::filesystem::status when reparse point ReparseTag set to IO_REPARSE_TAG_FILE_PLACEHOLDER
// https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN // https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN
#if !defined(__MINGW32__) || defined(__MINGW64__) #if !defined(__MINGW32__) || defined(__MINGW64__)
typedef struct _REPARSE_DATA_BUFFER { typedef struct _REPARSE_DATA_BUFFER
ULONG ReparseTag; {
USHORT ReparseDataLength; ULONG ReparseTag;
USHORT Reserved; USHORT ReparseDataLength;
union { USHORT Reserved;
struct { union
USHORT SubstituteNameOffset; {
USHORT SubstituteNameLength; struct
USHORT PrintNameOffset; {
USHORT PrintNameLength; USHORT SubstituteNameOffset;
ULONG Flags; USHORT SubstituteNameLength;
WCHAR PathBuffer[1]; USHORT PrintNameOffset;
} SymbolicLinkReparseBuffer; USHORT PrintNameLength;
struct { ULONG Flags;
USHORT SubstituteNameOffset; WCHAR PathBuffer[1];
USHORT SubstituteNameLength; } SymbolicLinkReparseBuffer;
USHORT PrintNameOffset; struct
USHORT PrintNameLength; {
WCHAR PathBuffer[1]; USHORT SubstituteNameOffset;
} MountPointReparseBuffer; USHORT SubstituteNameLength;
struct { USHORT PrintNameOffset;
UCHAR DataBuffer[1]; USHORT PrintNameLength;
} GenericReparseBuffer; WCHAR PathBuffer[1];
}; } MountPointReparseBuffer;
struct
{
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
#endif #endif
#ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER #ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER
# define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L) #define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
#endif #endif
#ifndef FSCTL_SET_REPARSE_POINT #ifndef FSCTL_SET_REPARSE_POINT
# define FSCTL_SET_REPARSE_POINT (0x000900a4) #define FSCTL_SET_REPARSE_POINT (0x000900a4)
#endif #endif
#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE #ifndef REPARSE_DATA_BUFFER_HEADER_SIZE
# define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer) #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
#endif #endif
bool obtain_restore_privilege() bool obtain_restore_privilege()
{ {
HANDLE hToken; HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{ {
std::cout << "OpenProcessToken() failed with: " << GetLastError() << std::endl; std::cout << "OpenProcessToken() failed with: " << GetLastError() << std::endl;
return false; return false;
} }
TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid))
{
CloseHandle(hToken);
std::cout << "LookupPrivilegeValue() failed with: " << GetLastError() << std::endl;
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
CloseHandle(hToken);
std::cout << "AdjustTokenPrivileges() failed with: " << GetLastError() << std::endl;
return false;
}
TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid))
{
CloseHandle(hToken); CloseHandle(hToken);
std::cout << "LookupPrivilegeValue() failed with: " << GetLastError() << std::endl; return true;
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
CloseHandle(hToken);
std::cout << "AdjustTokenPrivileges() failed with: " << GetLastError() << std::endl;
return false;
}
CloseHandle(hToken);
return true;
} }
bool create_io_reparse_file_placeholder(const wchar_t* name) bool create_io_reparse_file_placeholder(const wchar_t* name)
{ {
if (!obtain_restore_privilege()) if (!obtain_restore_privilege())
{ {
return false; return false;
} }
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0);
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
FILE_FLAG_OPEN_REPARSE_POINT, 0);
if (hHandle == INVALID_HANDLE_VALUE) if (hHandle == INVALID_HANDLE_VALUE)
{ {
std::cout << "CreateFile() failed with: " << GetLastError() << std::endl; std::cout << "CreateFile() failed with: " << GetLastError() << std::endl;
return false; return false;
} }
PREPARSE_DATA_BUFFER pReparse = reinterpret_cast<PREPARSE_DATA_BUFFER>(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE)); PREPARSE_DATA_BUFFER pReparse = reinterpret_cast< PREPARSE_DATA_BUFFER >(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE));
//note: IO_REPARSE_TAG_FILE_PLACEHOLDER - just to show that reparse point could be not only symlink or junction //note: IO_REPARSE_TAG_FILE_PLACEHOLDER - just to show that reparse point could be not only symlink or junction
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER; pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
DWORD dwLen; DWORD dwLen;
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, NULL, 0, &dwLen, NULL) != 0;
pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE,
NULL, 0, &dwLen, NULL) != 0;
if (!ret) if (!ret)
{ {
std::cout << "DeviceIoControl() failed with: " << GetLastError() << std::endl; std::cout << "DeviceIoControl() failed with: " << GetLastError() << std::endl;
} }
CloseHandle(hHandle); CloseHandle(hHandle);
GlobalFree(pReparse); GlobalFree(pReparse);
return ret; return ret;
} }
int main() int main()
{ {
boost::filesystem::path rpt = boost::filesystem::temp_directory_path() / "reparse_point_test.txt"; boost::filesystem::path rpt = boost::filesystem::temp_directory_path() / "reparse_point_test.txt";
BOOST_TEST(create_io_reparse_file_placeholder(rpt.native().c_str())); BOOST_TEST(create_io_reparse_file_placeholder(rpt.native().c_str()));
BOOST_TEST(boost::filesystem::status(rpt).type() == boost::filesystem::reparse_file); BOOST_TEST(boost::filesystem::status(rpt).type() == boost::filesystem::reparse_file);
BOOST_TEST(boost::filesystem::remove(rpt)); BOOST_TEST(boost::filesystem::remove(rpt));
return boost::report_errors(); return boost::report_errors();
} }
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK) #else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
int main() int main()
{ {
std::cout << "Skipping test as the target system does not support mklink." << std::endl; std::cout << "Skipping test as the target system does not support mklink." << std::endl;
return 0; return 0;
} }
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK) #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@ -14,9 +14,9 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -24,19 +24,19 @@ namespace fs = boost::filesystem;
int main() int main()
{ {
if ( fs::detail::possible_large_file_size_support() ) if (fs::detail::possible_large_file_size_support())
{ {
std::cout << "It appears that file sizes greater that 2 gigabytes are possible\n" std::cout << "It appears that file sizes greater that 2 gigabytes are possible\n"
"for this configuration on this platform since the operating system\n" "for this configuration on this platform since the operating system\n"
"does use a large enough integer type to report large file sizes.\n\n" "does use a large enough integer type to report large file sizes.\n\n"
"Whether or not such support is actually present depends on the OS\n"; "Whether or not such support is actually present depends on the OS\n";
return 0; return 0;
} }
std::cout << "The operating system is using an integer type to report file sizes\n" std::cout << "The operating system is using an integer type to report file sizes\n"
"that can not represent file sizes greater that 2 gigabytes (31-bits).\n" "that can not represent file sizes greater that 2 gigabytes (31-bits).\n"
"Thus the Filesystem Library will not correctly deal with such large\n" "Thus the Filesystem Library will not correctly deal with such large\n"
"files. If you think that this operatiing system should be able to\n" "files. If you think that this operatiing system should be able to\n"
"support large files, please report the problem to the Boost developers\n" "support large files, please report the problem to the Boost developers\n"
"mailing list.\n"; "mailing list.\n";
return 1; return 1;
} }

View File

@ -12,77 +12,74 @@
using namespace std; using namespace std;
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable: 4996) // ... Function call with parameters that may be unsafe #pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe
#endif #endif
namespace namespace {
void facet_info(const locale& loc, const char* msg)
{ {
void facet_info(const locale& loc, const char* msg)
{
cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(" cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
<< msg << ") is " << msg << ") is "
<< (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc) << (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "true\n" : "false\n");
? "true\n"
: "false\n");
}
void default_info()
{
try
{
locale loc;
cout << "\nlocale default construction OK" << endl;
facet_info(loc, "locale()");
}
catch (const exception& ex)
{
cout << "\nlocale default construction threw: " << ex.what() << endl;
}
}
void null_string_info()
{
try
{
locale loc("");
cout << "\nlocale(\"\") construction OK" << endl;
facet_info(loc, "locale(\"\")");
}
catch (const exception& ex)
{
cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
}
}
void classic_info()
{
try
{
locale loc(locale::classic());
cout << "\nlocale(locale::classic()) copy construction OK" << endl;
facet_info(loc, "locale::classic()");
}
catch (const exception& ex)
{
cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
}
}
} }
void default_info()
{
try
{
locale loc;
cout << "\nlocale default construction OK" << endl;
facet_info(loc, "locale()");
}
catch (const exception& ex)
{
cout << "\nlocale default construction threw: " << ex.what() << endl;
}
}
void null_string_info()
{
try
{
locale loc("");
cout << "\nlocale(\"\") construction OK" << endl;
facet_info(loc, "locale(\"\")");
}
catch (const exception& ex)
{
cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
}
}
void classic_info()
{
try
{
locale loc(locale::classic());
cout << "\nlocale(locale::classic()) copy construction OK" << endl;
facet_info(loc, "locale::classic()");
}
catch (const exception& ex)
{
cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
}
}
} // namespace
int main() int main()
{ {
const char* lang = getenv("LANG"); const char* lang = getenv("LANG");
cout << "\nLANG environmental variable is " cout << "\nLANG environmental variable is "
<< (lang ? lang : "not present") << endl; << (lang ? lang : "not present") << endl;
default_info(); default_info();
null_string_info(); null_string_info();
classic_info(); classic_info();
return 0; return 0;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif

View File

@ -20,40 +20,38 @@ using namespace boost::filesystem;
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
namespace namespace {
{ } // unnamed namespace
} // unnamed namespace
int cpp_main(int, char*[]) int cpp_main(int, char*[])
{ {
std::string prefix("d:\\temp\\"); std::string prefix("d:\\temp\\");
std::cout << "prefix is " << prefix << '\n'; std::cout << "prefix is " << prefix << '\n';
const std::size_t safe_size const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260
= 260 - prefix.size() - 100; // Windows MAX_PATH is 260
std::string safe_x_string(safe_size, 'x'); std::string safe_x_string(safe_size, 'x');
std::string safe_y_string(safe_size, 'y'); std::string safe_y_string(safe_size, 'y');
std::string path_escape("\\\\?\\"); std::string path_escape("\\\\?\\");
path x_p(prefix + safe_x_string); path x_p(prefix + safe_x_string);
path y_p(path_escape + prefix + safe_x_string + "\\" + safe_y_string); path y_p(path_escape + prefix + safe_x_string + "\\" + safe_y_string);
std::cout << "x_p.native().size() is " << x_p.native().size() << '\n'; std::cout << "x_p.native().size() is " << x_p.native().size() << '\n';
std::cout << "y_p.native().size() is " << y_p.native().size() << '\n'; std::cout << "y_p.native().size() is " << y_p.native().size() << '\n';
create_directory(x_p); create_directory(x_p);
BOOST_TEST(exists(x_p)); BOOST_TEST(exists(x_p));
create_directory(y_p); create_directory(y_p);
BOOST_TEST(exists(y_p)); BOOST_TEST(exists(y_p));
//std::cout << "directory x.../y... ready for testing, where ... is " << safe_size //std::cout << "directory x.../y... ready for testing, where ... is " << safe_size
// << " repeats of x and y, respectively\n"; // << " repeats of x and y, respectively\n";
BOOST_TEST(exists(x_p)); BOOST_TEST(exists(x_p));
//remove_all(x_p); //remove_all(x_p);
return ::boost::report_errors(); return ::boost::report_errors();
} }

View File

@ -15,22 +15,21 @@
#undef BOOST_SYSTEM_STATIC_LINK #undef BOOST_SYSTEM_STATIC_LINK
#ifndef BOOST_ALL_NO_LIB #ifndef BOOST_ALL_NO_LIB
# define BOOST_ALL_NO_LIB #define BOOST_ALL_NO_LIB
#endif #endif
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <boost/system/config.hpp> #include <boost/system/config.hpp>
#ifndef BOOST_FILESYSTEM_STATIC_LINK #ifndef BOOST_FILESYSTEM_STATIC_LINK
# error BOOST_FILESYSTEM_STATIC_LINK not set by default #error BOOST_FILESYSTEM_STATIC_LINK not set by default
#endif #endif
#ifndef BOOST_SYSTEM_STATIC_LINK #ifndef BOOST_SYSTEM_STATIC_LINK
# error BOOST_SYSTEM_STATIC_LINK not set by default #error BOOST_SYSTEM_STATIC_LINK not set by default
#endif #endif
int main() int main()
{ {
return 0; return 0;
} }

View File

@ -9,16 +9,14 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem void tu2();
{
void tu2();
}
} }
} // namespace boost
int main() int main()
{ {
boost::filesystem::tu2(); boost::filesystem::tu2();
return 0; return 0;
} }

View File

@ -9,10 +9,12 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace boost namespace boost {
namespace filesystem {
void tu2()
{ {
namespace filesystem
{
void tu2() {}
}
} }
} // namespace filesystem
} // namespace boost

File diff suppressed because it is too large Load Diff

View File

@ -13,23 +13,22 @@
// ------------------------------------------------------------------------------------// // ------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features // See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/filesystem.hpp> // make sure filesystem.hpp works #include <boost/filesystem.hpp> // make sure filesystem.hpp works
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@ -44,47 +43,47 @@ using std::string;
#define CHECK(x) check(x, __FILE__, __LINE__) #define CHECK(x) check(x, __FILE__, __LINE__)
namespace namespace {
{ bool cleanup = true;
bool cleanup = true;
void check(bool ok, const char* file, int line) void check(bool ok, const char* file, int line)
{ {
if (ok) return; if (ok)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
cout << file << '(' << line << "): test failed\n"; cout << file << '(' << line << "): test failed\n";
} }
// file_status_test ----------------------------------------------------------------// // file_status_test ----------------------------------------------------------------//
void file_status_test() void file_status_test()
{ {
cout << "file_status test..." << endl; cout << "file_status test..." << endl;
file_status s = status("."); file_status s = status(".");
int v = s.permissions(); int v = s.permissions();
cout << " status(\".\") permissions are " cout << " status(\".\") permissions are "
<< std::oct << (v & 0777) << std::dec << endl; << std::oct << (v & 0777) << std::dec << endl;
CHECK((v & 0400) == 0400); CHECK((v & 0400) == 0400);
s = symlink_status("."); s = symlink_status(".");
v = s.permissions(); v = s.permissions();
cout << " symlink_status(\".\") permissions are " cout << " symlink_status(\".\") permissions are "
<< std::oct << (v & 0777) << std::dec << endl; << std::oct << (v & 0777) << std::dec << endl;
CHECK((v & 0400) == 0400); CHECK((v & 0400) == 0400);
} }
// query_test ----------------------------------------------------------------------// // query_test ----------------------------------------------------------------------//
void query_test() void query_test()
{ {
cout << "query test..." << endl; cout << "query test..." << endl;
error_code ec; error_code ec;
CHECK(file_size("no-such-file", ec) == static_cast<boost::uintmax_t>(-1)); CHECK(file_size("no-such-file", ec) == static_cast< boost::uintmax_t >(-1));
CHECK(ec == errc::no_such_file_or_directory); CHECK(ec == errc::no_such_file_or_directory);
CHECK(status("no-such-file") == file_status(file_not_found, no_perms)); CHECK(status("no-such-file") == file_status(file_not_found, no_perms));
@ -96,8 +95,8 @@ namespace
exists("/", ec); exists("/", ec);
if (ec) if (ec)
{ {
cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl; cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl;
cout << "ec value: " << ec.value() << ", message: "<< ec.message() << endl; cout << "ec value: " << ec.value() << ", message: " << ec.message() << endl;
} }
CHECK(!ec); CHECK(!ec);
@ -106,12 +105,12 @@ namespace
CHECK(!is_regular_file("/")); CHECK(!is_regular_file("/"));
CHECK(!boost::filesystem::is_empty("/")); CHECK(!boost::filesystem::is_empty("/"));
CHECK(!is_other("/")); CHECK(!is_other("/"));
} }
// directory_iterator_test -----------------------------------------------// // directory_iterator_test -----------------------------------------------//
void directory_iterator_test() void directory_iterator_test()
{ {
cout << "directory_iterator_test..." << endl; cout << "directory_iterator_test..." << endl;
directory_iterator end; directory_iterator end;
@ -122,25 +121,25 @@ namespace
if (is_regular_file(it->status())) if (is_regular_file(it->status()))
{ {
CHECK(is_regular_file(it->symlink_status())); CHECK(is_regular_file(it->symlink_status()));
CHECK(!is_directory(it->status())); CHECK(!is_directory(it->status()));
CHECK(!is_symlink(it->status())); CHECK(!is_symlink(it->status()));
CHECK(!is_directory(it->symlink_status())); CHECK(!is_directory(it->symlink_status()));
CHECK(!is_symlink(it->symlink_status())); CHECK(!is_symlink(it->symlink_status()));
} }
else else
{ {
CHECK(is_directory(it->status())); CHECK(is_directory(it->status()));
CHECK(is_directory(it->symlink_status())); CHECK(is_directory(it->symlink_status()));
CHECK(!is_regular_file(it->status())); CHECK(!is_regular_file(it->status()));
CHECK(!is_regular_file(it->symlink_status())); CHECK(!is_regular_file(it->symlink_status()));
CHECK(!is_symlink(it->status())); CHECK(!is_symlink(it->status()));
CHECK(!is_symlink(it->symlink_status())); CHECK(!is_symlink(it->symlink_status()));
} }
for (; it != end; ++it) for (; it != end; ++it)
{ {
//cout << " " << it->path() << "\n"; //cout << " " << it->path() << "\n";
} }
CHECK(directory_iterator(".") != directory_iterator()); CHECK(directory_iterator(".") != directory_iterator());
@ -149,30 +148,30 @@ namespace
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR #ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
for (directory_entry& x : directory_iterator(".")) for (directory_entry& x : directory_iterator("."))
{ {
CHECK(!x.path().empty()); CHECK(!x.path().empty());
//cout << " " << x.path() << "\n"; //cout << " " << x.path() << "\n";
} }
const directory_iterator dir_itr("."); const directory_iterator dir_itr(".");
for (directory_entry& x : dir_itr) for (directory_entry& x : dir_itr)
{ {
CHECK(!x.path().empty()); CHECK(!x.path().empty());
//cout << " " << x.path() << "\n"; //cout << " " << x.path() << "\n";
} }
#endif #endif
for (directory_iterator itr("."); itr != directory_iterator(); ++itr) for (directory_iterator itr("."); itr != directory_iterator(); ++itr)
{ {
CHECK(!itr->path().empty()); CHECK(!itr->path().empty());
//cout << " " << itr->path() << "\n"; //cout << " " << itr->path() << "\n";
} }
cout << "directory_iterator_test complete" << endl; cout << "directory_iterator_test complete" << endl;
} }
// recursive_directory_iterator_test -----------------------------------------------// // recursive_directory_iterator_test -----------------------------------------------//
void recursive_directory_iterator_test() void recursive_directory_iterator_test()
{ {
cout << "recursive_directory_iterator_test..." << endl; cout << "recursive_directory_iterator_test..." << endl;
recursive_directory_iterator end; recursive_directory_iterator end;
@ -183,25 +182,25 @@ namespace
if (is_regular_file(it->status())) if (is_regular_file(it->status()))
{ {
CHECK(is_regular_file(it->symlink_status())); CHECK(is_regular_file(it->symlink_status()));
CHECK(!is_directory(it->status())); CHECK(!is_directory(it->status()));
CHECK(!is_symlink(it->status())); CHECK(!is_symlink(it->status()));
CHECK(!is_directory(it->symlink_status())); CHECK(!is_directory(it->symlink_status()));
CHECK(!is_symlink(it->symlink_status())); CHECK(!is_symlink(it->symlink_status()));
} }
else else
{ {
CHECK(is_directory(it->status())); CHECK(is_directory(it->status()));
CHECK(is_directory(it->symlink_status())); CHECK(is_directory(it->symlink_status()));
CHECK(!is_regular_file(it->status())); CHECK(!is_regular_file(it->status()));
CHECK(!is_regular_file(it->symlink_status())); CHECK(!is_regular_file(it->symlink_status()));
CHECK(!is_symlink(it->status())); CHECK(!is_symlink(it->status()));
CHECK(!is_symlink(it->symlink_status())); CHECK(!is_symlink(it->symlink_status()));
} }
for (; it != end; ++it) for (; it != end; ++it)
{ {
//cout << " " << it->path() << "\n"; //cout << " " << it->path() << "\n";
} }
CHECK(recursive_directory_iterator(".") != recursive_directory_iterator()); CHECK(recursive_directory_iterator(".") != recursive_directory_iterator());
@ -210,31 +209,31 @@ namespace
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR #ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
for (directory_entry& x : recursive_directory_iterator(".")) for (directory_entry& x : recursive_directory_iterator("."))
{ {
CHECK(!x.path().empty()); CHECK(!x.path().empty());
//cout << " " << x.path() << "\n"; //cout << " " << x.path() << "\n";
} }
const recursive_directory_iterator dir_itr("."); const recursive_directory_iterator dir_itr(".");
for (directory_entry& x : dir_itr) for (directory_entry& x : dir_itr)
{ {
CHECK(!x.path().empty()); CHECK(!x.path().empty());
//cout << " " << x.path() << "\n"; //cout << " " << x.path() << "\n";
} }
#endif #endif
for (recursive_directory_iterator itr("."); for (recursive_directory_iterator itr(".");
itr != recursive_directory_iterator(); ++itr) itr != recursive_directory_iterator(); ++itr)
{ {
CHECK(!itr->path().empty()); CHECK(!itr->path().empty());
//cout << " " << itr->path() << "\n"; //cout << " " << itr->path() << "\n";
} }
cout << "recursive_directory_iterator_test complete" << endl; cout << "recursive_directory_iterator_test complete" << endl;
} }
// operations_test -------------------------------------------------------// // operations_test -------------------------------------------------------//
void operations_test() void operations_test()
{ {
cout << "operations test..." << endl; cout << "operations test..." << endl;
error_code ec; error_code ec;
@ -254,16 +253,15 @@ namespace
std::time_t ft = last_write_time("."); std::time_t ft = last_write_time(".");
ft = -1; ft = -1;
last_write_time(".", ft, ec); last_write_time(".", ft, ec);
} }
// directory_entry_test ------------------------------------------------------------// // directory_entry_test ------------------------------------------------------------//
void directory_entry_test() void directory_entry_test()
{ {
cout << "directory_entry test..." << endl; cout << "directory_entry test..." << endl;
directory_entry de("foo.bar", directory_entry de("foo.bar", file_status(regular_file, owner_all), file_status(directory_file, group_all));
file_status(regular_file, owner_all), file_status(directory_file, group_all));
CHECK(de.path() == "foo.bar"); CHECK(de.path() == "foo.bar");
CHECK(de.status() == file_status(regular_file, owner_all)); CHECK(de.status() == file_status(regular_file, owner_all));
@ -273,50 +271,51 @@ namespace
CHECK(de != directory_entry("goo.bar")); CHECK(de != directory_entry("goo.bar"));
de.replace_filename("bar.foo"); de.replace_filename("bar.foo");
CHECK(de.path() == "bar.foo"); CHECK(de.path() == "bar.foo");
} }
// directory_entry_overload_test ---------------------------------------------------// // directory_entry_overload_test ---------------------------------------------------//
void directory_entry_overload_test() void directory_entry_overload_test()
{ {
cout << "directory_entry overload test..." << endl; cout << "directory_entry overload test..." << endl;
directory_iterator it("."); directory_iterator it(".");
path p(*it); path p(*it);
} }
// error_handling_test -------------------------------------------------------------// // error_handling_test -------------------------------------------------------------//
void error_handling_test() void error_handling_test()
{ {
cout << "error handling test..." << endl; cout << "error handling test..." << endl;
bool threw(false); bool threw(false);
try try
{ {
file_size("no-such-file"); file_size("no-such-file");
} }
catch (const boost::filesystem::filesystem_error & ex) catch (const boost::filesystem::filesystem_error& ex)
{ {
threw = true; threw = true;
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n" cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
"what() returns " << ex.what() << "\n"; "what() returns "
<< ex.what() << "\n";
} }
catch (...) catch (...)
{ {
cout << "\nunexpected exception type caught" << endl; cout << "\nunexpected exception type caught" << endl;
} }
CHECK(threw); CHECK(threw);
error_code ec; error_code ec;
CHECK(!create_directory("/", ec)); CHECK(!create_directory("/", ec));
} }
// string_file_tests ---------------------------------------------------------------// // string_file_tests ---------------------------------------------------------------//
void string_file_tests(const path& temp_dir) void string_file_tests(const path& temp_dir)
{ {
cout << "string_file_tests..." << endl; cout << "string_file_tests..." << endl;
std::string contents("0123456789"); std::string contents("0123456789");
path p(temp_dir / "string_file"); path p(temp_dir / "string_file");
@ -326,9 +325,9 @@ namespace
std::string round_trip; std::string round_trip;
load_string_file(p, round_trip); load_string_file(p, round_trip);
BOOST_TEST_EQ(contents, round_trip); BOOST_TEST_EQ(contents, round_trip);
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -340,63 +339,63 @@ int cpp_main(int argc, char* argv[])
{ {
// document state of critical macros // document state of critical macros
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API is defined\n"; cout << "BOOST_POSIX_API is defined\n";
#endif #endif
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API is defined\n"; cout << "BOOST_WINDOWS_API is defined\n";
#endif #endif
cout << "BOOST_FILESYSTEM_DECL" << BOOST_STRINGIZE(=BOOST_FILESYSTEM_DECL) << "\n"; cout << "BOOST_FILESYSTEM_DECL" << BOOST_STRINGIZE(=BOOST_FILESYSTEM_DECL) << "\n";
cout << "BOOST_SYMBOL_VISIBLE" << BOOST_STRINGIZE(=BOOST_SYMBOL_VISIBLE) << "\n"; cout << "BOOST_SYMBOL_VISIBLE" << BOOST_STRINGIZE(=BOOST_SYMBOL_VISIBLE) << "\n";
cout << "current_path() is " << current_path().string() << endl;
if (argc >= 2)
{
cout << "argv[1] is '" << argv[1] << "', changing current_path() to it" << endl;
error_code ec;
current_path( argv[1], ec );
if (ec)
{
cout << "current_path('" << argv[1] << "') failed: " << ec << ": " << ec.message() << endl;
}
cout << "current_path() is " << current_path().string() << endl; cout << "current_path() is " << current_path().string() << endl;
}
const path temp_dir(current_path() / ".." / unique_path("op-unit_test-%%%%-%%%%-%%%%")); if (argc >= 2)
cout << "temp_dir is " << temp_dir.string() << endl; {
cout << "argv[1] is '" << argv[1] << "', changing current_path() to it" << endl;
create_directory(temp_dir); error_code ec;
current_path(argv[1], ec);
file_status_test(); if (ec)
query_test(); {
directory_iterator_test(); cout << "current_path('" << argv[1] << "') failed: " << ec << ": " << ec.message() << endl;
recursive_directory_iterator_test(); }
operations_test();
directory_entry_test();
directory_entry_overload_test();
error_handling_test();
string_file_tests(temp_dir);
cout << unique_path() << endl; cout << "current_path() is " << current_path().string() << endl;
cout << unique_path("foo-%%%%%-%%%%%-bar") << endl; }
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%-bar") << endl;
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-bar") << endl;
cout << "testing complete" << endl; const path temp_dir(current_path() / ".." / unique_path("op-unit_test-%%%%-%%%%-%%%%"));
cout << "temp_dir is " << temp_dir.string() << endl;
// post-test cleanup create_directory(temp_dir);
if (cleanup)
{
cout << "post-test removal of " << temp_dir << endl;
BOOST_TEST(remove_all(temp_dir) != 0);
// above was added just to simplify testing, but it ended up detecting
// a bug (failure to close an internal search handle).
cout << "post-test removal complete" << endl;
// BOOST_TEST(!fs::exists(dir)); // nice test, but doesn't play well with TortoiseGit cache
}
return ::boost::report_errors(); file_status_test();
query_test();
directory_iterator_test();
recursive_directory_iterator_test();
operations_test();
directory_entry_test();
directory_entry_overload_test();
error_handling_test();
string_file_tests(temp_dir);
cout << unique_path() << endl;
cout << unique_path("foo-%%%%%-%%%%%-bar") << endl;
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%-bar") << endl;
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-bar") << endl;
cout << "testing complete" << endl;
// post-test cleanup
if (cleanup)
{
cout << "post-test removal of " << temp_dir << endl;
BOOST_TEST(remove_all(temp_dir) != 0);
// above was added just to simplify testing, but it ended up detecting
// a bug (failure to close an internal search handle).
cout << "post-test removal complete" << endl;
// BOOST_TEST(!fs::exists(dir)); // nice test, but doesn't play well with TortoiseGit cache
}
return ::boost::report_errors();
} }

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,10 @@
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED #define BOOST_FILESYSTEM_NO_DEPRECATED
#endif #endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED #ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED #define BOOST_SYSTEM_NO_DEPRECATED
#endif #endif
#include <boost/timer/timer.hpp> #include <boost/timer/timer.hpp>
@ -21,9 +21,9 @@
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING ) #if defined(BOOST_NO_STD_WSTRING)
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif #endif
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
@ -36,38 +36,37 @@ using namespace boost::timer;
using std::cout; using std::cout;
using std::endl; using std::endl;
namespace namespace {
boost::int64_t max_cycles;
template< class STD_STRING >
nanosecond_type time_ctor(const STD_STRING& s)
{ {
boost::int64_t max_cycles;
template <class STD_STRING>
nanosecond_type time_ctor(const STD_STRING& s)
{
boost::timer::auto_cpu_timer tmr; boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0; boost::int64_t count = 0;
do do
{ {
fs::path p(s); fs::path p(s);
++count; ++count;
} while (count < max_cycles); } while (count < max_cycles);
boost::timer::cpu_times elapsed = tmr.elapsed(); boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system; return elapsed.user + elapsed.system;
} }
nanosecond_type time_loop() nanosecond_type time_loop()
{ {
boost::timer::auto_cpu_timer tmr; boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0; boost::int64_t count = 0;
do do
{ {
++count; ++count;
} while (count < max_cycles); } while (count < max_cycles);
boost::timer::cpu_times elapsed = tmr.elapsed(); boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system; return elapsed.user + elapsed.system;
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// main // // main //
@ -75,29 +74,29 @@ namespace
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
if (argc != 2) if (argc != 2)
{ {
cout << "Usage: path_times <cycles-in-millions>\n"; cout << "Usage: path_times <cycles-in-millions>\n";
return 1; return 1;
} }
max_cycles = std::atoi(argv[1]) * 1000000LL; max_cycles = std::atoi(argv[1]) * 1000000LL;
cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl; cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
cout << "time_loop" << endl; cout << "time_loop" << endl;
nanosecond_type x = time_loop(); nanosecond_type x = time_loop();
cout << "time_ctor with string" << endl; cout << "time_ctor with string" << endl;
nanosecond_type s = time_ctor(std::string("/foo/bar/baz")); nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
cout << "time_ctor with wstring" << endl; cout << "time_ctor with wstring" << endl;
nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz")); nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
if (s > w) if (s > w)
cout << "narrow/wide CPU-time ratio = " << long double(s)/w << endl; cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
else else
cout << "wide/narrow CPU-time ratio = " << long double(w)/s << endl; cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;
cout << "returning from main()" << endl; cout << "returning from main()" << endl;
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -15,10 +15,10 @@ namespace fs = boost::filesystem;
int main() int main()
{ {
fs::path p1( "a" ); fs::path p1("a");
fs::path p2 = p1 / "b"; fs::path p2 = p1 / "b";
BOOST_TEST_EQ( p2, "a/b" ); BOOST_TEST_EQ(p2, "a/b");
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -22,10 +22,10 @@ using boost::filesystem::path;
using std::cout; using std::cout;
using std::endl; using std::endl;
namespace namespace {
void lexically_relative_test()
{ {
void lexically_relative_test()
{
cout << "lexically_relative_test..." << endl; cout << "lexically_relative_test..." << endl;
BOOST_TEST(path("").lexically_relative("") == ""); BOOST_TEST(path("").lexically_relative("") == "");
@ -76,24 +76,25 @@ namespace
// Some tests from Jamie Allsop's paper // Some tests from Jamie Allsop's paper
BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d"); BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d");
BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c"); BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c");
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y"); BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y");
#else #else
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == ""); BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "");
#endif #endif
BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == ""); BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == "");
// From issue #1976 // From issue #1976
BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new"); BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new");
} }
void lexically_proximate_test() void lexically_proximate_test()
{ {
cout << "lexically_proximate_test..." << endl; cout << "lexically_proximate_test..." << endl;
// paths unrelated // paths unrelated
BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c"); BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c");
} }
} // unnamed namespace
} // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -105,14 +106,14 @@ int test_main(int, char*[])
{ {
// document state of critical macros // document state of critical macros
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API" << endl; cout << "BOOST_POSIX_API" << endl;
#endif #endif
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API" << endl; cout << "BOOST_WINDOWS_API" << endl;
#endif #endif
lexically_relative_test(); lexically_relative_test();
lexically_proximate_test(); lexically_proximate_test();
return ::boost::report_errors(); return ::boost::report_errors();
} }

View File

@ -18,9 +18,9 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#ifndef BOOST_LIGHTWEIGHT_MAIN #ifndef BOOST_LIGHTWEIGHT_MAIN
# include <boost/test/prg_exec_monitor.hpp> #include <boost/test/prg_exec_monitor.hpp>
#else #else
# include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
#endif #endif
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -30,34 +30,33 @@ using std::endl;
using std::string; using std::string;
using std::wstring; using std::wstring;
namespace namespace {
{ bool cleanup = true;
bool cleanup = true;
} }
// cpp_main ----------------------------------------------------------------// // cpp_main ----------------------------------------------------------------//
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0) if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0)
cleanup = false; cleanup = false;
// Test cases go after this block of comments // Test cases go after this block of comments
// Use test case macros from boost/core/lightweight_test.hpp: // Use test case macros from boost/core/lightweight_test.hpp:
// //
// BOOST_TEST(predicate); // test passes if predicate evaluates to true // BOOST_TEST(predicate); // test passes if predicate evaluates to true
// BOOST_TEST_EQ(x, y); // test passes if x == y // BOOST_TEST_EQ(x, y); // test passes if x == y
// BOOST_TEST_NE(x, y); // test passes if x != y // BOOST_TEST_NE(x, y); // test passes if x != y
// BOOST_ERROR(msg); // test fails, outputs msg // BOOST_ERROR(msg); // test fails, outputs msg
// Examples: // Examples:
// BOOST_TEST(path("f00").size() == 3); // test passes // BOOST_TEST(path("f00").size() == 3); // test passes
// BOOST_TEST_EQ(path("f00").size(), 3); // test passes // BOOST_TEST_EQ(path("f00").size(), 3); // test passes
// BOOST_MSG("Oops!"); // test fails, outputs "Oops!" // BOOST_MSG("Oops!"); // test fails, outputs "Oops!"
if (cleanup) if (cleanup)
{ {
// Remove any test files or directories here // Remove any test files or directories here
} }
return ::boost::report_errors(); return ::boost::report_errors();
} }

View File

@ -12,68 +12,61 @@
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <locale> #include <locale>
#include <cwchar> // for mbstate_t #include <cwchar> // for mbstate_t
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// // // //
// class test_codecvt // // class test_codecvt //
// // // //
// Warning: partial implementation; even do_in and do_out only partially meet the // // Warning: partial implementation; even do_in and do_out only partially meet the //
// standard library specifications as the "to" buffer must hold the entire result. // // standard library specifications as the "to" buffer must hold the entire result. //
// // // //
// The value of a wide character is the value of the corresponding narrow character // // The value of a wide character is the value of the corresponding narrow character //
// plus 1. This ensures that compares against expected values will fail if the // // plus 1. This ensures that compares against expected values will fail if the //
// code conversion did not occur as expected. // // code conversion did not occur as expected. //
// // // //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class test_codecvt class test_codecvt :
: public std::codecvt< wchar_t, char, std::mbstate_t > public std::codecvt< wchar_t, char, std::mbstate_t >
{ {
public: public:
explicit test_codecvt() explicit test_codecvt() :
: std::codecvt<wchar_t, char, std::mbstate_t>() {} std::codecvt< wchar_t, char, std::mbstate_t >()
protected:
virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{ {
for (; from != from_end && to != to_end; ++from, ++to)
*to = wchar_t(*from + 1);
if (to == to_end)
return error;
*to = L'\0';
from_next = from;
to_next = to;
return ok;
}
virtual std::codecvt_base::result do_out(std::mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const
{
for (; from != from_end && to != to_end; ++from, ++to)
*to = static_cast<char>(*from - 1);
if (to == to_end)
return error;
*to = '\0';
from_next = from;
to_next = to;
return ok;
} }
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, protected:
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; } virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; }
virtual int do_length(std::mbstate_t&, virtual std::codecvt_base::result do_in(std::mbstate_t&, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; } {
for (; from != from_end && to != to_end; ++from, ++to)
*to = wchar_t(*from + 1);
if (to == to_end)
return error;
*to = L'\0';
from_next = from;
to_next = to;
return ok;
}
virtual int do_max_length() const throw () { return 0; } virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const
}; {
for (; from != from_end && to != to_end; ++from, ++to)
*to = static_cast< char >(*from - 1);
if (to == to_end)
return error;
*to = '\0';
from_next = from;
to_next = to;
return ok;
}
#endif // BOOST_FILESYSTEM3_TEST_CODECVT_HPP virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw() { return 0; }
};
#endif // BOOST_FILESYSTEM3_TEST_CODECVT_HPP

View File

@ -24,85 +24,85 @@
using std::make_pair; using std::make_pair;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int cpp_main( int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {
typedef std::map<DWORD, std::string> decode_type; typedef std::map< DWORD, std::string > decode_type;
decode_type table; decode_type table;
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL")); table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
if (argc < 2) if (argc < 2)
{
std::cout << "Usage: windows_attributes path\n";
return 1;
}
// report Win32 ::GetFileAttributesA()
DWORD at(::GetFileAttributesA(argv[1]));
if (at == INVALID_FILE_ATTRIBUTES)
{
std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned INVALID_FILE_ATTRIBUTES\n";
return 0;
}
std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned ";
bool bar = false;
for (decode_type::iterator it = table.begin(); it != table.end(); ++it)
{
if (!(it->first & at))
continue;
if (bar)
std::cout << " | ";
bar = true;
std::cout << it->second;
at &= ~it->first;
}
std::cout << std::endl;
if (at)
std::cout << "plus unknown attributes " << at << std::endl;
// report Boost Filesystem file_type
fs::file_status stat = fs::status(argv[1]);
const char* types[] =
{ {
"status_error", std::cout << "Usage: windows_attributes path\n";
"file_not_found", return 1;
"regular_file", }
"directory_file",
// the following may not apply to some operating systems or file systems
"symlink_file",
"block_file",
"character_file",
"fifo_file",
"socket_file",
"reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
"type_unknown", // file does exist", but isn't one of the above types or
// we don't have strong enough permission to find its type
"_detail_directory_symlink" // internal use only; never exposed to users // report Win32 ::GetFileAttributesA()
};
std::cout << "boost::filesystem::status().type() is " << types[stat.type()] << std::endl; DWORD at(::GetFileAttributesA(argv[1]));
if (at == INVALID_FILE_ATTRIBUTES)
{
std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned INVALID_FILE_ATTRIBUTES\n";
return 0;
}
return 0; std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned ";
bool bar = false;
for (decode_type::iterator it = table.begin(); it != table.end(); ++it)
{
if (!(it->first & at))
continue;
if (bar)
std::cout << " | ";
bar = true;
std::cout << it->second;
at &= ~it->first;
}
std::cout << std::endl;
if (at)
std::cout << "plus unknown attributes " << at << std::endl;
// report Boost Filesystem file_type
fs::file_status stat = fs::status(argv[1]);
const char* types[] =
{
"status_error",
"file_not_found",
"regular_file",
"directory_file",
// the following may not apply to some operating systems or file systems
"symlink_file",
"block_file",
"character_file",
"fifo_file",
"socket_file",
"reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
"type_unknown", // file does exist", but isn't one of the above types or
// we don't have strong enough permission to find its type
"_detail_directory_symlink" // internal use only; never exposed to users
};
std::cout << "boost::filesystem::status().type() is " << types[stat.type()] << std::endl;
return 0;
} }