mirror of
https://github.com/boostorg/filesystem.git
synced 2025-05-11 05:07:55 +00:00
Reformatted code for more consistent look and better readability.
This commit is contained in:
parent
83429c9bfd
commit
c03249c375
10
bug/bug.cpp
10
bug/bug.cpp
@ -5,13 +5,13 @@
|
||||
|
||||
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_EQ(4 + 4, 9); // two EqualityComparible arguments
|
||||
BOOST_TEST(fs::exists(".")); // should pass, so nothing reported
|
||||
BOOST_TEST(2 + 2 == 5); // one convertible-to-bool argument
|
||||
BOOST_TEST_EQ(4 + 4, 9); // two EqualityComparible arguments
|
||||
BOOST_TEST(fs::exists(".")); // should pass, so nothing reported
|
||||
|
||||
return ::boost::report_errors(); // required
|
||||
return ::boost::report_errors(); // required
|
||||
}
|
||||
|
||||
// Copyright Beman Dawes 2014
|
||||
|
@ -26,9 +26,9 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char buf[16] = {};
|
||||
boost::winapi::BCRYPT_ALG_HANDLE_ handle;
|
||||
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);
|
||||
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
|
||||
unsigned char buf[16] = {};
|
||||
boost::winapi::BCRYPT_ALG_HANDLE_ handle;
|
||||
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);
|
||||
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
|
||||
}
|
||||
|
@ -17,156 +17,154 @@ using boost::filesystem::path;
|
||||
using std::string;
|
||||
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 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 cell_value( const path & p ) const { return p.string(); }
|
||||
} o0;
|
||||
string cell_value(const path& p) const { return p.string(); }
|
||||
} o0;
|
||||
|
||||
struct c1 : public column_base
|
||||
{
|
||||
struct c1 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>generic_<br>string()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.generic_string(); }
|
||||
} o1;
|
||||
string cell_value(const path& p) const { return p.generic_string(); }
|
||||
} o1;
|
||||
|
||||
struct c2 : public column_base
|
||||
{
|
||||
struct c2 : public column_base
|
||||
{
|
||||
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;
|
||||
for( path::iterator i(p.begin()); i != p.end(); ++i )
|
||||
{
|
||||
if ( i != p.begin() ) s += ',';
|
||||
s += (*i).string();
|
||||
}
|
||||
return s;
|
||||
string s;
|
||||
for (path::iterator i(p.begin()); i != p.end(); ++i)
|
||||
{
|
||||
if (i != p.begin())
|
||||
s += ',';
|
||||
s += (*i).string();
|
||||
}
|
||||
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 cell_value( const path & p ) const { return p.root_path().string(); }
|
||||
} o3;
|
||||
string cell_value(const path& p) const { return p.root_path().string(); }
|
||||
} o3;
|
||||
|
||||
struct c4 : public column_base
|
||||
{
|
||||
struct c4 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>root_<br>name()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.root_name().string(); }
|
||||
} o4;
|
||||
string cell_value(const path& p) const { return p.root_name().string(); }
|
||||
} o4;
|
||||
|
||||
struct c5 : public column_base
|
||||
{
|
||||
struct c5 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>root_<br>directory()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.root_directory().string(); }
|
||||
} o5;
|
||||
string cell_value(const path& p) const { return p.root_directory().string(); }
|
||||
} o5;
|
||||
|
||||
struct c6 : public column_base
|
||||
{
|
||||
struct c6 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>relative_<br>path()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.relative_path().string(); }
|
||||
} o6;
|
||||
string cell_value(const path& p) const { return p.relative_path().string(); }
|
||||
} o6;
|
||||
|
||||
struct c7 : public column_base
|
||||
{
|
||||
struct c7 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>parent_<br>path()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.parent_path().string(); }
|
||||
} o7;
|
||||
string cell_value(const path& p) const { return p.parent_path().string(); }
|
||||
} o7;
|
||||
|
||||
struct c8 : public column_base
|
||||
{
|
||||
struct c8 : public column_base
|
||||
{
|
||||
string heading() const { return string("<code>filename()</code>"); }
|
||||
string cell_value( const path & p ) const { return p.filename().string(); }
|
||||
} o8;
|
||||
string cell_value(const path& p) const { return p.filename().string(); }
|
||||
} 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 value;
|
||||
outfile << "<td>";
|
||||
if (temp.empty())
|
||||
value = "<font size=\"-1\"><i>empty</i></font>";
|
||||
value = "<font size=\"-1\"><i>empty</i></font>";
|
||||
else
|
||||
value = string("<code>") + temp + "</code>";
|
||||
value = string("<code>") + temp + "</code>";
|
||||
|
||||
if (posix)
|
||||
posix_outfile << value << '\n';
|
||||
posix_outfile << value << '\n';
|
||||
else
|
||||
{
|
||||
std::getline(posix_infile, temp);
|
||||
if (value != temp) // POSIX and Windows differ
|
||||
{
|
||||
value.insert(0, "<br>");
|
||||
value.insert(0, temp);
|
||||
value.insert(0, "<span style=\"background-color: #CCFFCC\">");
|
||||
value += "</span>";
|
||||
}
|
||||
outfile << value;
|
||||
std::getline(posix_infile, temp);
|
||||
if (value != temp) // POSIX and Windows differ
|
||||
{
|
||||
value.insert(0, "<br>");
|
||||
value.insert(0, temp);
|
||||
value.insert(0, "<span style=\"background-color: #CCFFCC\">");
|
||||
value += "</span>";
|
||||
}
|
||||
outfile << value;
|
||||
}
|
||||
outfile << "</td>\n";
|
||||
}
|
||||
}
|
||||
|
||||
// do_row ------------------------------------------------------------------//
|
||||
|
||||
void do_row( const string & test_case )
|
||||
{
|
||||
void do_row(const string& test_case)
|
||||
{
|
||||
outfile << "<tr>\n";
|
||||
|
||||
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
|
||||
outfile << "<td><code>" << test_case << "</code></td>\n";
|
||||
|
||||
for ( int i = 0; i < sizeof(column)/sizeof(column_base&); ++i )
|
||||
outfile << "<td><code>" << test_case << "</code></td>\n";
|
||||
|
||||
for (int i = 0; i < sizeof(column) / sizeof(column_base&); ++i)
|
||||
{
|
||||
do_cell( test_case, i );
|
||||
do_cell(test_case, i);
|
||||
}
|
||||
|
||||
outfile << "</tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
// do_table ----------------------------------------------------------------//
|
||||
|
||||
void do_table()
|
||||
{
|
||||
outfile <<
|
||||
"<h1>Path Decomposition Table</h1>\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"
|
||||
"<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n"
|
||||
"<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
|
||||
"<p>\n"
|
||||
;
|
||||
void do_table()
|
||||
{
|
||||
outfile << "<h1>Path Decomposition Table</h1>\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"
|
||||
"<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n"
|
||||
"<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
|
||||
"<p>\n";
|
||||
|
||||
// generate the column headings
|
||||
|
||||
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";
|
||||
@ -174,16 +172,16 @@ namespace
|
||||
// generate a row for each input line
|
||||
|
||||
string test_case;
|
||||
while ( std::getline( infile, test_case ) )
|
||||
while (std::getline(infile, test_case))
|
||||
{
|
||||
if (!test_case.empty() && *--test_case.end() == '\r')
|
||||
test_case.erase(test_case.size()-1);
|
||||
if (test_case.empty() || test_case[0] != '#')
|
||||
do_row( test_case );
|
||||
if (!test_case.empty() && *--test_case.end() == '\r')
|
||||
test_case.erase(test_case.size() - 1);
|
||||
if (test_case.empty() || test_case[0] != '#')
|
||||
do_row(test_case);
|
||||
}
|
||||
|
||||
outfile << "</table>\n";
|
||||
}
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
@ -192,69 +190,65 @@ namespace
|
||||
#define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
|
||||
#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 )
|
||||
{
|
||||
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 )
|
||||
if (argc != 5)
|
||||
{
|
||||
std::cerr << "Could not open POSIX output file: " << argv[3] << std::endl;
|
||||
return 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
posix = false;
|
||||
posix_infile.open( argv[3] );
|
||||
if ( !posix_infile )
|
||||
|
||||
infile.open(argv[2]);
|
||||
if (!infile)
|
||||
{
|
||||
std::cerr << "Could not open POSIX input file: " << argv[3] << std::endl;
|
||||
return 1;
|
||||
std::cerr << "Could not open input file: " << argv[2] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
outfile.open( argv[4] );
|
||||
if ( !outfile )
|
||||
{
|
||||
std::cerr << "Could not open output 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;
|
||||
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"
|
||||
"<head>\n"
|
||||
"<title>Path Decomposition Table</title>\n"
|
||||
"</head>\n"
|
||||
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
|
||||
;
|
||||
outfile.open(argv[4]);
|
||||
if (!outfile)
|
||||
{
|
||||
std::cerr << "Could not open output file: " << argv[2] << std::endl;
|
||||
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"
|
||||
"</html>\n"
|
||||
;
|
||||
do_table();
|
||||
|
||||
return 0;
|
||||
outfile << "</body>\n"
|
||||
"</html>\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -12,30 +12,31 @@
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int cpp_main(int argc, char* argv[])
|
||||
{
|
||||
# ifdef BOOST_WINDOWS_API
|
||||
cout << "BOOST_WINDOWS_API" << endl;
|
||||
# else
|
||||
cout << "BOOST_POSIX_API" << endl;
|
||||
# endif
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
cout << "BOOST_WINDOWS_API" << endl;
|
||||
#else
|
||||
cout << "BOOST_POSIX_API" << endl;
|
||||
#endif
|
||||
|
||||
path test_dir(current_path() / "dspr_demo");
|
||||
path test_dir(current_path() / "dspr_demo");
|
||||
|
||||
remove_all(test_dir);
|
||||
create_directories(test_dir / "a/c/d");
|
||||
current_path(test_dir / "a");
|
||||
create_directory_symlink("c/d", "b");
|
||||
save_string_file("name.txt", "Windows");
|
||||
save_string_file("c/name.txt", "POSIX");
|
||||
current_path(test_dir);
|
||||
std::string s;
|
||||
load_string_file("a/b/../name.txt", s);
|
||||
cout << s << endl;
|
||||
remove_all(test_dir);
|
||||
create_directories(test_dir / "a/c/d");
|
||||
current_path(test_dir / "a");
|
||||
create_directory_symlink("c/d", "b");
|
||||
save_string_file("name.txt", "Windows");
|
||||
save_string_file("c/name.txt", "POSIX");
|
||||
current_path(test_dir);
|
||||
std::string s;
|
||||
load_string_file("a/b/../name.txt", s);
|
||||
cout << s << endl;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,162 +24,177 @@ using boost::system::error_code;
|
||||
using boost::system::system_error;
|
||||
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"
|
||||
<< " ex.code().value() is " << ex.code().value() << '\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"
|
||||
<< " ex.code().value() is " << ex.code().value() << '\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 ";
|
||||
switch (s.type())
|
||||
{
|
||||
case fs::status_error:
|
||||
cout << "status_error\n"; break;
|
||||
cout << "status_error\n";
|
||||
break;
|
||||
case fs::file_not_found:
|
||||
cout << "file_not_found\n"; break;
|
||||
cout << "file_not_found\n";
|
||||
break;
|
||||
case fs::regular_file:
|
||||
cout << "regular_file\n"; break;
|
||||
cout << "regular_file\n";
|
||||
break;
|
||||
case fs::directory_file:
|
||||
cout << "directory_file\n"; break;
|
||||
cout << "directory_file\n";
|
||||
break;
|
||||
case fs::symlink_file:
|
||||
cout << "symlink_file\n"; break;
|
||||
cout << "symlink_file\n";
|
||||
break;
|
||||
case fs::block_file:
|
||||
cout << "block_file\n"; break;
|
||||
cout << "block_file\n";
|
||||
break;
|
||||
case fs::character_file:
|
||||
cout << "character_file\n"; break;
|
||||
cout << "character_file\n";
|
||||
break;
|
||||
case fs::fifo_file:
|
||||
cout << "fifo_file\n"; break;
|
||||
cout << "fifo_file\n";
|
||||
break;
|
||||
case fs::socket_file:
|
||||
cout << "socket_file\n"; break;
|
||||
cout << "socket_file\n";
|
||||
break;
|
||||
case fs::type_unknown:
|
||||
cout << "type_unknown\n"; break;
|
||||
cout << "type_unknown\n";
|
||||
break;
|
||||
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"
|
||||
<< " value() is " << ec.value() << '\n'
|
||||
<< " category().name() is " << ec.category().name() << '\n'
|
||||
<< " message() is " << ec.message() << '\n'
|
||||
;
|
||||
}
|
||||
|
||||
bool threw_exception;
|
||||
|
||||
<< " message() is " << ec.message() << '\n';
|
||||
}
|
||||
|
||||
bool threw_exception;
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: error_demo path\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: error_demo path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
error_code ec;
|
||||
error_code ec;
|
||||
|
||||
//// construct path - no error_code
|
||||
//// construct path - no error_code
|
||||
|
||||
//try { path p1(argv[1]); }
|
||||
//catch (const system_error& ex)
|
||||
//{
|
||||
// cout << "construct path without error_code";
|
||||
// report_system_error(ex);
|
||||
//}
|
||||
//try { path p1(argv[1]); }
|
||||
//catch (const system_error& ex)
|
||||
//{
|
||||
// cout << "construct path without error_code";
|
||||
// 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;
|
||||
bool b (false);
|
||||
fs::directory_iterator di;
|
||||
fs::file_status s;
|
||||
bool b(false);
|
||||
fs::directory_iterator di;
|
||||
|
||||
// get status - no error_code
|
||||
// get status - no error_code
|
||||
|
||||
cout << "\nstatus(\"" << p.string() << "\");\n";
|
||||
threw_exception = false;
|
||||
cout << "\nstatus(\"" << p.string() << "\");\n";
|
||||
threw_exception = false;
|
||||
|
||||
try { s = fs::status(p); }
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
if (!threw_exception)
|
||||
cout << " Did not throw exception\n";
|
||||
report_status(s);
|
||||
try
|
||||
{
|
||||
s = fs::status(p);
|
||||
}
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
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";
|
||||
s = fs::status(p, ec);
|
||||
report_status(s);
|
||||
report_error_code(ec);
|
||||
cout << "\nstatus(\"" << p.string() << "\", ec);\n";
|
||||
s = fs::status(p, ec);
|
||||
report_status(s);
|
||||
report_error_code(ec);
|
||||
|
||||
// query existence - no error_code
|
||||
// query existence - no error_code
|
||||
|
||||
cout << "\nexists(\"" << p.string() << "\");\n";
|
||||
threw_exception = false;
|
||||
cout << "\nexists(\"" << p.string() << "\");\n";
|
||||
threw_exception = false;
|
||||
|
||||
try { b = fs::exists(p); }
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
if (!threw_exception)
|
||||
{
|
||||
cout << " Did not throw exception\n"
|
||||
<< " Returns: " << (b ? "true" : "false") << '\n';
|
||||
}
|
||||
try
|
||||
{
|
||||
b = fs::exists(p);
|
||||
}
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
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";
|
||||
threw_exception = false;
|
||||
cout << "\ndirectory_iterator(\"" << p.string() << "\");\n";
|
||||
threw_exception = false;
|
||||
|
||||
try { di = fs::directory_iterator(p); }
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
if (!threw_exception)
|
||||
{
|
||||
cout << " Did not throw exception\n"
|
||||
<< (di == fs::directory_iterator() ? " Equal" : " Not equal")
|
||||
<< " to the end iterator\n";
|
||||
}
|
||||
try
|
||||
{
|
||||
di = fs::directory_iterator(p);
|
||||
}
|
||||
catch (const system_error& ex)
|
||||
{
|
||||
report_filesystem_error(ex);
|
||||
threw_exception = true;
|
||||
}
|
||||
if (!threw_exception)
|
||||
{
|
||||
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";
|
||||
di = fs::directory_iterator(p, ec);
|
||||
cout << (di == fs::directory_iterator() ? " Equal" : " Not equal")
|
||||
<< " to the end iterator\n";
|
||||
report_error_code(ec);
|
||||
cout << "\ndirectory_iterator(\"" << p.string() << "\", ec);\n";
|
||||
di = fs::directory_iterator(p, ec);
|
||||
cout << (di == fs::directory_iterator() ? " Equal" : " Not equal")
|
||||
<< " to the end iterator\n";
|
||||
report_error_code(ec);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,32 +13,32 @@
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
if ( argc != 2 )
|
||||
{
|
||||
std::cout << "Usage: file_size path\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "Usage: file_size path\n";
|
||||
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 ) )
|
||||
{
|
||||
std::cout << "not found: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (!fs::exists(p))
|
||||
{
|
||||
std::cout << "not found: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( !fs::is_regular( p ) )
|
||||
{
|
||||
std::cout << "not a regular file: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "size of " << argv[1] << " is " << fs::file_size( p )
|
||||
<< std::endl;
|
||||
return 0;
|
||||
if (!fs::is_regular(p))
|
||||
{
|
||||
std::cout << "not a regular file: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "size of " << argv[1] << " is " << fs::file_size(p)
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,55 +13,54 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
|
||||
using std::cout; using std::endl;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
|
||||
path p;
|
||||
|
||||
void print_boost_macros()
|
||||
{
|
||||
path p;
|
||||
|
||||
void print_boost_macros()
|
||||
{
|
||||
std::cout << "Boost "
|
||||
<< BOOST_VERSION / 100000 << '.'
|
||||
<< BOOST_VERSION / 100 % 1000 << '.'
|
||||
<< BOOST_VERSION % 100 << ", "
|
||||
# ifndef _WIN64
|
||||
#ifndef _WIN64
|
||||
<< BOOST_COMPILER << ", "
|
||||
# else
|
||||
#else
|
||||
<< BOOST_COMPILER << " with _WIN64 defined, "
|
||||
# endif
|
||||
#endif
|
||||
<< BOOST_STDLIB << ", "
|
||||
<< BOOST_PLATFORM
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const char* file_type_tab[] =
|
||||
{ "status_error", "file_not_found", "regular_file", "directory_file",
|
||||
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
|
||||
"type_unknown"
|
||||
};
|
||||
const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file",
|
||||
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
|
||||
"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];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (ec)
|
||||
{
|
||||
econd = ec.default_error_condition();
|
||||
cout << "sets ec to indicate an error:\n"
|
||||
<< " ec.value() is " << ec.value() << '\n'
|
||||
<< " ec.message() is \"" << ec.message() << "\"\n"
|
||||
<< " ec.default_error_condition().value() is " << econd.value() << '\n'
|
||||
<< " ec.default_error_condition().message() is \"" << econd.message() << "\"\n";
|
||||
econd = ec.default_error_condition();
|
||||
cout << "sets ec to indicate an error:\n"
|
||||
<< " ec.value() is " << ec.value() << '\n'
|
||||
<< " ec.message() is \"" << ec.message() << "\"\n"
|
||||
<< " ec.default_error_condition().value() is " << econd.value() << '\n'
|
||||
<< " ec.default_error_condition().message() is \"" << econd.message() << "\"\n";
|
||||
}
|
||||
else
|
||||
cout << "clears ec.\n";
|
||||
cout << "clears ec.\n";
|
||||
|
||||
cout << "s.type() is " << s.type()
|
||||
<< ", 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_other(s) is " << (is_other(s) ? "true" : "false") << "\n";
|
||||
cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void try_exists()
|
||||
{
|
||||
void try_exists()
|
||||
{
|
||||
cout << "\nexists(" << p << ") ";
|
||||
try
|
||||
{
|
||||
bool result = exists(p);
|
||||
cout << "is " << (result ? "true" : "false") << "\n";
|
||||
bool result = exists(p);
|
||||
cout << "is " << (result ? "true" : "false") << "\n";
|
||||
}
|
||||
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[])
|
||||
{
|
||||
print_boost_macros();
|
||||
print_boost_macros();
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: file_status <path>\n";
|
||||
p = argv[0];
|
||||
}
|
||||
else
|
||||
p = argv[1];
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: file_status <path>\n";
|
||||
p = argv[0];
|
||||
}
|
||||
else
|
||||
p = argv[1];
|
||||
|
||||
boost::system::error_code ec;
|
||||
file_status s = status(p, ec);
|
||||
cout << "\nfile_status s = status(" << p << ", ec) ";
|
||||
show_status(s, ec);
|
||||
boost::system::error_code ec;
|
||||
file_status s = status(p, ec);
|
||||
cout << "\nfile_status s = status(" << p << ", ec) ";
|
||||
show_status(s, ec);
|
||||
|
||||
s = symlink_status(p, ec);
|
||||
cout << "\nfile_status s = symlink_status(" << p << ", ec) ";
|
||||
show_status(s, ec);
|
||||
s = symlink_status(p, ec);
|
||||
cout << "\nfile_status s = symlink_status(" << p << ", ec) ";
|
||||
show_status(s, ec);
|
||||
|
||||
try_exists();
|
||||
try_exists();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,9 +13,9 @@
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
# ifdef BOOST_FILESYSTEM_NARROW_ONLY
|
||||
# error This compiler or standard library does not support wide-character strings or paths
|
||||
# endif
|
||||
#ifdef BOOST_FILESYSTEM_NARROW_ONLY
|
||||
#error This compiler or standard library does not support wide-character strings or paths
|
||||
#endif
|
||||
|
||||
#include "mbpath.hpp"
|
||||
#include <iostream>
|
||||
@ -25,66 +25,76 @@
|
||||
|
||||
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
|
||||
// differ, so provide a not-very-smart replacement.
|
||||
fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary);
|
||||
if (!from_file)
|
||||
{
|
||||
std::cout << "input open failed\n";
|
||||
return;
|
||||
}
|
||||
|
||||
void copy_file( const fs::wpath & from, const user::mbpath & to )
|
||||
{
|
||||
fs::ifstream from_file( from, std::ios_base::in | std::ios_base::binary );
|
||||
if ( !from_file ) { std::cout << "input 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; }
|
||||
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;
|
||||
while ( from_file.get(c) )
|
||||
while (from_file.get(c))
|
||||
{
|
||||
to_file.put(c);
|
||||
if ( to_file.fail() ) { std::cout << "write error\n"; return; }
|
||||
to_file.put(c);
|
||||
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 )
|
||||
{
|
||||
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()) )
|
||||
if (argc != 2)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
// See Boost.Filesystem home page at http://www.boost.org/libs/filesystem
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
# ifdef BOOST_FILESYSTEM_NARROW_ONLY
|
||||
# error This compiler or standard library does not support wide-character strings or paths
|
||||
# endif
|
||||
#ifdef BOOST_FILESYSTEM_NARROW_ONLY
|
||||
#error This compiler or standard library does not support wide-character strings or paths
|
||||
#endif
|
||||
|
||||
#include "mbpath.hpp"
|
||||
#include <boost/system/system_error.hpp>
|
||||
@ -19,62 +19,60 @@
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
// ISO C calls this "the locale-specific native environment":
|
||||
std::locale loc("");
|
||||
namespace {
|
||||
|
||||
const std::codecvt<wchar_t, char, std::mbstate_t> *
|
||||
cvt( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >
|
||||
( loc ) );
|
||||
// ISO C calls this "the locale-specific native environment":
|
||||
std::locale 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
|
||||
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::size_t work_size(src.size() + 1);
|
||||
boost::scoped_array< wchar_t > work(new wchar_t[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() );
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
mbpath_traits::internal_string_type
|
||||
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 )
|
||||
{
|
||||
void mbpath_traits::imbue(const std::locale& new_loc)
|
||||
{
|
||||
loc = new_loc;
|
||||
cvt = &std::use_facet
|
||||
<std::codecvt<wchar_t, char, std::mbstate_t> >( loc );
|
||||
}
|
||||
cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc);
|
||||
}
|
||||
|
||||
} // namespace user
|
||||
|
@ -10,35 +10,38 @@
|
||||
// See http://../doc/path.htm#mbpath for more information
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <cwchar> // for std::mbstate_t
|
||||
#include <cwchar> // for std::mbstate_t
|
||||
#include <string>
|
||||
#include <locale>
|
||||
|
||||
namespace user
|
||||
{
|
||||
struct mbpath_traits;
|
||||
|
||||
typedef boost::filesystem::basic_path<std::wstring, mbpath_traits> mbpath;
|
||||
namespace user {
|
||||
|
||||
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::string external_string_type;
|
||||
|
||||
static external_string_type to_external( const mbpath & ph,
|
||||
const internal_string_type & src );
|
||||
static external_string_type to_external(const mbpath& ph, 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 boost
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
|
||||
template<>
|
||||
struct is_basic_path< user::mbpath >
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
template<> struct is_basic_path<user::mbpath>
|
||||
{ static const bool value = true; };
|
||||
}
|
||||
}
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
@ -9,74 +9,78 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace std;
|
||||
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[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: path_info path-element [path-element...]\n"
|
||||
"Composes a path via operator/= from one or more path-element arguments\n"
|
||||
"Example: path_info foo/bar baz\n"
|
||||
# ifdef BOOST_POSIX_API
|
||||
" would report info about the composed path foo/bar/baz\n";
|
||||
# else // BOOST_WINDOWS_API
|
||||
" would report info about the composed path foo/bar\\baz\n";
|
||||
# endif
|
||||
return 1;
|
||||
}
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: path_info path-element [path-element...]\n"
|
||||
"Composes a path via operator/= from one or more path-element arguments\n"
|
||||
"Example: path_info foo/bar baz\n"
|
||||
#ifdef BOOST_POSIX_API
|
||||
" would report info about the composed path foo/bar/baz\n";
|
||||
#else // BOOST_WINDOWS_API
|
||||
" would report info about the composed path foo/bar\\baz\n";
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
path p;
|
||||
for (; argc > 1; --argc, ++argv)
|
||||
p /= argv[1]; // compose path p from the command line arguments
|
||||
path p;
|
||||
for (; argc > 1; --argc, ++argv)
|
||||
p /= argv[1]; // compose path p from the command line arguments
|
||||
|
||||
cout << "\ncomposed path:\n";
|
||||
cout << " operator<<()---------: " << p << "\n";
|
||||
cout << " make_preferred()-----: " << p.make_preferred() << "\n";
|
||||
cout << "\ncomposed path:\n";
|
||||
cout << " operator<<()---------: " << p << "\n";
|
||||
cout << " make_preferred()-----: " << p.make_preferred() << "\n";
|
||||
|
||||
cout << "\nelements:\n";
|
||||
for (auto element : p)
|
||||
cout << " " << element << '\n';
|
||||
cout << "\nelements:\n";
|
||||
for (auto element : p)
|
||||
cout << " " << element << '\n';
|
||||
|
||||
cout << "\nobservers, native format:" << endl;
|
||||
# ifdef BOOST_POSIX_API
|
||||
cout << " native()-------------: " << p.native() << endl;
|
||||
cout << " c_str()--------------: " << p.c_str() << endl;
|
||||
# else // BOOST_WINDOWS_API
|
||||
wcout << L" native()-------------: " << p.native() << endl;
|
||||
wcout << L" c_str()--------------: " << p.c_str() << endl;
|
||||
# endif
|
||||
cout << " string()-------------: " << p.string() << endl;
|
||||
wcout << L" wstring()------------: " << p.wstring() << endl;
|
||||
cout << "\nobservers, native format:" << endl;
|
||||
#ifdef BOOST_POSIX_API
|
||||
cout << " native()-------------: " << p.native() << endl;
|
||||
cout << " c_str()--------------: " << p.c_str() << endl;
|
||||
#else // BOOST_WINDOWS_API
|
||||
wcout << L" native()-------------: " << p.native() << endl;
|
||||
wcout << L" c_str()--------------: " << p.c_str() << endl;
|
||||
#endif
|
||||
cout << " string()-------------: " << p.string() << endl;
|
||||
wcout << L" wstring()------------: " << p.wstring() << endl;
|
||||
|
||||
cout << "\nobservers, generic format:\n";
|
||||
cout << " generic_string()-----: " << p.generic_string() << endl;
|
||||
wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
|
||||
cout << "\nobservers, generic format:\n";
|
||||
cout << " generic_string()-----: " << p.generic_string() << endl;
|
||||
wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
|
||||
|
||||
cout << "\ndecomposition:\n";
|
||||
cout << " root_name()----------: " << p.root_name() << '\n';
|
||||
cout << " root_directory()-----: " << p.root_directory() << '\n';
|
||||
cout << " root_path()----------: " << p.root_path() << '\n';
|
||||
cout << " relative_path()------: " << p.relative_path() << '\n';
|
||||
cout << " parent_path()--------: " << p.parent_path() << '\n';
|
||||
cout << " filename()-----------: " << p.filename() << '\n';
|
||||
cout << " stem()---------------: " << p.stem() << '\n';
|
||||
cout << " extension()----------: " << p.extension() << '\n';
|
||||
cout << "\ndecomposition:\n";
|
||||
cout << " root_name()----------: " << p.root_name() << '\n';
|
||||
cout << " root_directory()-----: " << p.root_directory() << '\n';
|
||||
cout << " root_path()----------: " << p.root_path() << '\n';
|
||||
cout << " relative_path()------: " << p.relative_path() << '\n';
|
||||
cout << " parent_path()--------: " << p.parent_path() << '\n';
|
||||
cout << " filename()-----------: " << p.filename() << '\n';
|
||||
cout << " stem()---------------: " << p.stem() << '\n';
|
||||
cout << " extension()----------: " << p.extension() << '\n';
|
||||
|
||||
cout << "\nquery:\n";
|
||||
cout << " empty()--------------: " << say_what(p.empty()) << '\n';
|
||||
cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\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_path()------: " << say_what(p.has_root_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_filename()-------: " << say_what(p.has_filename()) << '\n';
|
||||
cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
|
||||
cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
|
||||
cout << "\nquery:\n";
|
||||
cout << " empty()--------------: " << say_what(p.empty()) << '\n';
|
||||
cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\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_path()------: " << say_what(p.has_root_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_filename()-------: " << say_what(p.has_filename()) << '\n';
|
||||
cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
|
||||
cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,11 +11,11 @@
|
||||
#define BOOST_FILESYSTEM_VERSION 3
|
||||
|
||||
// As an example program, we don't want to use any deprecated features
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
@ -27,66 +27,66 @@ namespace fs = boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fs::path p(fs::current_path());
|
||||
fs::path p(fs::current_path());
|
||||
|
||||
if (argc > 1)
|
||||
p = fs::system_complete(argv[1]);
|
||||
else
|
||||
std::cout << "\nusage: simple_ls [path]" << std::endl;
|
||||
if (argc > 1)
|
||||
p = fs::system_complete(argv[1]);
|
||||
else
|
||||
std::cout << "\nusage: simple_ls [path]" << std::endl;
|
||||
|
||||
unsigned long file_count = 0;
|
||||
unsigned long dir_count = 0;
|
||||
unsigned long other_count = 0;
|
||||
unsigned long err_count = 0;
|
||||
unsigned long file_count = 0;
|
||||
unsigned long dir_count = 0;
|
||||
unsigned long other_count = 0;
|
||||
unsigned long err_count = 0;
|
||||
|
||||
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)
|
||||
if (!fs::exists(p))
|
||||
{
|
||||
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 << "\nNot found: " << p << std::endl;
|
||||
return 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -12,20 +12,20 @@
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: stems <path>\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: stems <path>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path p(argv[1]), name(p.filename());
|
||||
boost::filesystem::path p(argv[1]), name(p.filename());
|
||||
|
||||
for(;;)
|
||||
{
|
||||
std::cout << "filename " << name << " has stem " << name.stem()
|
||||
<< " and extension " << name.extension() << "\n";
|
||||
if (name.stem().empty() || name.extension().empty())
|
||||
return 0;
|
||||
name = name.stem();
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
std::cout << "filename " << name << " has stem " << name.stem()
|
||||
<< " and extension " << name.extension() << "\n";
|
||||
if (name.stem().empty() || name.extension().empty())
|
||||
return 0;
|
||||
name = name.stem();
|
||||
}
|
||||
}
|
||||
|
@ -14,26 +14,26 @@
|
||||
|
||||
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()
|
||||
{
|
||||
// get a path that is known to exist
|
||||
fs::path cp = fs::current_path();
|
||||
// get a path that is known to exist
|
||||
fs::path cp = fs::current_path();
|
||||
|
||||
// demo: get tstring from the path
|
||||
tstring cp_as_tstring = cp.string<tstring>();
|
||||
// demo: get tstring from the path
|
||||
tstring cp_as_tstring = cp.string< tstring >();
|
||||
|
||||
// demo: pass tstring to filesystem function taking path
|
||||
assert( fs::exists( cp_as_tstring ) );
|
||||
// demo: pass tstring to filesystem function taking path
|
||||
assert(fs::exists(cp_as_tstring));
|
||||
|
||||
// demo: pass tstring to user function taking path
|
||||
func( cp_as_tstring );
|
||||
// demo: pass tstring to user function taking path
|
||||
func(cp_as_tstring);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,15 +9,16 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut0 path\n";
|
||||
return 1;
|
||||
}
|
||||
std::cout << argv[1] << '\n';
|
||||
return 0;
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut0 path\n";
|
||||
return 1;
|
||||
}
|
||||
std::cout << argv[1] << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,15 +9,16 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut1 path\n";
|
||||
return 1;
|
||||
}
|
||||
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
|
||||
return 0;
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut1 path\n";
|
||||
return 1;
|
||||
}
|
||||
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,32 +9,31 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: tut2 path\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: tut2 path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
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";
|
||||
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";
|
||||
else
|
||||
cout << p << " exists, but is not a regular file or directory\n";
|
||||
}
|
||||
else
|
||||
cout << p << " exists, but is not a regular file or directory\n";
|
||||
}
|
||||
else
|
||||
cout << p << " does not exist\n";
|
||||
cout << p << " does not exist\n";
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,44 +9,45 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using std::cout;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: tut3 path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
path p (argv[1]);
|
||||
|
||||
try
|
||||
{
|
||||
if (exists(p))
|
||||
if (argc < 2)
|
||||
{
|
||||
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 (const directory_entry& x : directory_iterator(p))
|
||||
cout << " " << x.path() << '\n';
|
||||
}
|
||||
else
|
||||
cout << p << " exists, but is not a regular file or directory\n";
|
||||
cout << "Usage: tut3 path\n";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
cout << p << " does not exist\n";
|
||||
}
|
||||
|
||||
catch (const filesystem_error& ex)
|
||||
{
|
||||
cout << ex.what() << '\n';
|
||||
}
|
||||
path p(argv[1]);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -11,51 +11,52 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using std::cout;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: tut4 path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
path p (argv[1]);
|
||||
|
||||
try
|
||||
{
|
||||
if (exists(p))
|
||||
if (argc < 2)
|
||||
{
|
||||
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";
|
||||
cout << "Usage: tut4 path\n";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
cout << p << " does not exist\n";
|
||||
}
|
||||
|
||||
catch (const filesystem_error& ex)
|
||||
{
|
||||
cout << ex.what() << '\n';
|
||||
}
|
||||
path p(argv[1]);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -10,43 +10,60 @@
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main()
|
||||
{
|
||||
// \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
|
||||
std::string narrow_string ("smile2");
|
||||
std::wstring wide_string (L"smile2\u263A");
|
||||
std::list<char> narrow_list;
|
||||
narrow_list.push_back('s');
|
||||
narrow_list.push_back('m');
|
||||
narrow_list.push_back('i');
|
||||
narrow_list.push_back('l');
|
||||
narrow_list.push_back('e');
|
||||
narrow_list.push_back('3');
|
||||
std::list<wchar_t> wide_list;
|
||||
wide_list.push_back(L's');
|
||||
wide_list.push_back(L'm');
|
||||
wide_list.push_back(L'i');
|
||||
wide_list.push_back(L'l');
|
||||
wide_list.push_back(L'e');
|
||||
wide_list.push_back(L'3');
|
||||
wide_list.push_back(L'\u263A');
|
||||
// \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
|
||||
std::string narrow_string("smile2");
|
||||
std::wstring wide_string(L"smile2\u263A");
|
||||
std::list< char > narrow_list;
|
||||
narrow_list.push_back('s');
|
||||
narrow_list.push_back('m');
|
||||
narrow_list.push_back('i');
|
||||
narrow_list.push_back('l');
|
||||
narrow_list.push_back('e');
|
||||
narrow_list.push_back('3');
|
||||
std::list< wchar_t > wide_list;
|
||||
wide_list.push_back(L's');
|
||||
wide_list.push_back(L'm');
|
||||
wide_list.push_back(L'i');
|
||||
wide_list.push_back(L'l');
|
||||
wide_list.push_back(L'e');
|
||||
wide_list.push_back(L'3');
|
||||
wide_list.push_back(L'\u263A');
|
||||
|
||||
{ fs::ofstream f("smile"); }
|
||||
{ fs::ofstream f(L"smile\u263A"); }
|
||||
{ fs::ofstream f(narrow_string); }
|
||||
{ fs::ofstream f(wide_string); }
|
||||
{ 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())); }
|
||||
{
|
||||
fs::ofstream f("smile");
|
||||
}
|
||||
{
|
||||
fs::ofstream f(L"smile\u263A");
|
||||
}
|
||||
{
|
||||
fs::ofstream f(narrow_string);
|
||||
}
|
||||
{
|
||||
fs::ofstream f(wide_string);
|
||||
}
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -10,39 +10,39 @@
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
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 (argc < 2)
|
||||
{
|
||||
if (it.level() > 1)
|
||||
it.pop();
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << it->path() << '\n';
|
||||
}
|
||||
std::cout << "Usage: tut6a path\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
std::cout << "************* exception *****************\n";
|
||||
std::cout << ex.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
for (recursive_directory_iterator it(argv[1]);
|
||||
it != recursive_directory_iterator();
|
||||
++it)
|
||||
{
|
||||
if (it.level() > 1)
|
||||
it.pop();
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << it->path() << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "************* exception *****************\n";
|
||||
std::cout << ex.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,41 +10,43 @@
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut6b path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (recursive_directory_iterator it (argv[1]);
|
||||
it != recursive_directory_iterator();
|
||||
)
|
||||
if (argc < 2)
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << it->path() << '\n';
|
||||
|
||||
try { ++it; }
|
||||
catch (const filesystem_error& ex)
|
||||
{
|
||||
std::cout << "************* filesystem_error *****************\n";
|
||||
std::cout << ex.what() << '\n';
|
||||
}
|
||||
std::cout << "Usage: tut6b path\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
std::cout << "************* exception *****************\n";
|
||||
std::cout << ex.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
for (recursive_directory_iterator it(argv[1]);
|
||||
it != recursive_directory_iterator();)
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -17,24 +17,23 @@ using namespace boost::system;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut6c path\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Usage: tut6c path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
error_code ec;
|
||||
for (recursive_directory_iterator it (argv[1], ec);
|
||||
it != recursive_directory_iterator();
|
||||
)
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
error_code ec;
|
||||
for (recursive_directory_iterator it(argv[1], ec);
|
||||
it != recursive_directory_iterator();)
|
||||
{
|
||||
for (int i = 0; i <= it.level(); ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << it->path() << '\n';
|
||||
std::cout << it->path() << '\n';
|
||||
|
||||
it.increment(ec);
|
||||
}
|
||||
it.increment(ec);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -12,13 +12,13 @@
|
||||
#ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP
|
||||
#define BOOST_FILESYSTEM_FILESYSTEM_HPP
|
||||
|
||||
# include <boost/filesystem/config.hpp>
|
||||
# include <boost/filesystem/path.hpp>
|
||||
# include <boost/filesystem/exception.hpp>
|
||||
# include <boost/filesystem/directory.hpp>
|
||||
# include <boost/filesystem/operations.hpp>
|
||||
# include <boost/filesystem/file_status.hpp>
|
||||
# include <boost/filesystem/convenience.hpp>
|
||||
# include <boost/filesystem/string_file.hpp>
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
#include <boost/filesystem/directory.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/file_status.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#include <boost/filesystem/string_file.hpp>
|
||||
|
||||
#endif // BOOST_FILESYSTEM_FILESYSTEM_HPP
|
||||
#endif // BOOST_FILESYSTEM_FILESYSTEM_HPP
|
||||
|
@ -12,29 +12,29 @@
|
||||
#ifndef BOOST_FILESYSTEM3_CONFIG_HPP
|
||||
#define BOOST_FILESYSTEM3_CONFIG_HPP
|
||||
|
||||
# if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
|
||||
# error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
|
||||
# endif
|
||||
#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
|
||||
#error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
|
||||
#endif
|
||||
|
||||
# if !defined(BOOST_FILESYSTEM_VERSION)
|
||||
# define BOOST_FILESYSTEM_VERSION 3
|
||||
# endif
|
||||
#if !defined(BOOST_FILESYSTEM_VERSION)
|
||||
#define BOOST_FILESYSTEM_VERSION 3
|
||||
#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
|
||||
// http://www.boost.org/more/separate_compilation.html
|
||||
|
||||
#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>
|
||||
|
||||
// BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------//
|
||||
|
||||
# ifdef BOOST_FILESYSTEM_SOURCE
|
||||
# define BOOST_FILESYSTEM_DEPRECATED
|
||||
# undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined
|
||||
# endif
|
||||
#ifdef BOOST_FILESYSTEM_SOURCE
|
||||
#define BOOST_FILESYSTEM_DEPRECATED
|
||||
#undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined
|
||||
#endif
|
||||
|
||||
// throw an exception ----------------------------------------------------------------//
|
||||
//
|
||||
@ -46,50 +46,48 @@
|
||||
|
||||
#define BOOST_FILESYSTEM_THROW(EX) throw EX
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
// This header implements separate compilation features as described in
|
||||
// http://www.boost.org/more/separate_compilation.html
|
||||
|
||||
// normalize macros ------------------------------------------------------------------//
|
||||
|
||||
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) \
|
||||
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
|
||||
# define 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)
|
||||
#define BOOST_FILESYSTEM_STATIC_LINK
|
||||
#endif
|
||||
|
||||
#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)
|
||||
# define BOOST_FILESYSTEM_STATIC_LINK
|
||||
#define BOOST_FILESYSTEM_STATIC_LINK
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#if defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
|
||||
# define BOOST_FILESYSTEM_NO_LIB
|
||||
#define BOOST_FILESYSTEM_NO_LIB
|
||||
#endif
|
||||
|
||||
// enable dynamic linking ------------------------------------------------------------//
|
||||
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
|
||||
# if defined(BOOST_FILESYSTEM_SOURCE)
|
||||
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
|
||||
# else
|
||||
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
|
||||
# endif
|
||||
#if defined(BOOST_FILESYSTEM_SOURCE)
|
||||
#define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
# define BOOST_FILESYSTEM_DECL
|
||||
#define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define BOOST_FILESYSTEM_DECL
|
||||
#endif
|
||||
|
||||
// enable automatic library variant selection ----------------------------------------//
|
||||
|
||||
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) \
|
||||
&& !defined(BOOST_FILESYSTEM_NO_LIB)
|
||||
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
|
||||
//
|
||||
// Set the name of our library, this will get undef'ed by auto_link.hpp
|
||||
// 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 defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
|
||||
# define BOOST_DYN_LINK
|
||||
#define BOOST_DYN_LINK
|
||||
#endif
|
||||
//
|
||||
// And include the header that does the work:
|
||||
//
|
||||
#include <boost/config/auto_link.hpp>
|
||||
#endif // auto-linking disabled
|
||||
#endif // auto-linking disabled
|
||||
|
||||
#endif // BOOST_FILESYSTEM3_CONFIG_HPP
|
||||
|
@ -15,44 +15,42 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#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)
|
||||
{
|
||||
return p.extension().string();
|
||||
}
|
||||
inline path change_extension(const path& p, const path& new_extension)
|
||||
{
|
||||
path new_p(p);
|
||||
new_p.replace_extension(new_extension);
|
||||
return new_p;
|
||||
}
|
||||
|
||||
inline std::string basename(const path & p)
|
||||
{
|
||||
return p.stem().string();
|
||||
}
|
||||
#endif
|
||||
|
||||
inline path change_extension( const path & p, const path & new_extension )
|
||||
{
|
||||
path new_p( p );
|
||||
new_p.replace_extension( new_extension );
|
||||
return new_p;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
|
||||
#endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP
|
||||
|
@ -20,25 +20,23 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace boost
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
|
||||
inline const char* macro_value(const char* name, const char* value)
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
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]";
|
||||
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(value, "value 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");
|
||||
|
||||
return strcmp(name, value + 1)
|
||||
? ((*value && *(value+1)) ? (value+1) : no_value)
|
||||
: not_defined; // name == value+1 so the macro is not defined
|
||||
}
|
||||
} // detail
|
||||
} // boost
|
||||
return strcmp(name, value + 1) ? ((*value && *(value + 1)) ? (value + 1) : no_value) : not_defined; // name == value+1 so the macro is not defined
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#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
|
||||
|
@ -10,9 +10,14 @@
|
||||
#include <boost/filesystem/config.hpp>
|
||||
|
||||
#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
|
||||
|
||||
#include <boost/detail/utf8_codecvt_facet.hpp>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -13,9 +13,9 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
@ -31,9 +31,9 @@
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(push)
|
||||
// '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'
|
||||
#pragma warning(disable: 4275)
|
||||
#pragma warning(disable : 4275)
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
@ -46,47 +46,53 @@ namespace filesystem {
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
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:
|
||||
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, const path& path2_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, const path& path2_arg, system::error_code ec);
|
||||
|
||||
BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that);
|
||||
BOOST_FILESYSTEM_DECL filesystem_error& operator= (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() BOOST_NOEXCEPT_OR_NOTHROW;
|
||||
BOOST_FILESYSTEM_DECL ~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW;
|
||||
|
||||
const path& path1() const BOOST_NOEXCEPT
|
||||
{
|
||||
return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path();
|
||||
}
|
||||
const path& path2() const BOOST_NOEXCEPT
|
||||
{
|
||||
return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path();
|
||||
}
|
||||
const path& path1() const BOOST_NOEXCEPT
|
||||
{
|
||||
return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path();
|
||||
}
|
||||
const path& path2() const BOOST_NOEXCEPT
|
||||
{
|
||||
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:
|
||||
BOOST_FILESYSTEM_DECL static const path& get_empty_path() BOOST_NOEXCEPT;
|
||||
BOOST_FILESYSTEM_DECL static const path& get_empty_path() BOOST_NOEXCEPT;
|
||||
|
||||
private:
|
||||
struct impl :
|
||||
public boost::intrusive_ref_counter< impl >
|
||||
{
|
||||
path m_path1; // may be empty()
|
||||
path m_path2; // may be empty()
|
||||
std::string m_what; // not built until needed
|
||||
struct impl :
|
||||
public boost::intrusive_ref_counter< impl >
|
||||
{
|
||||
path m_path1; // may be empty()
|
||||
path m_path2; // may be empty()
|
||||
std::string m_what; // not built until needed
|
||||
|
||||
BOOST_DEFAULTED_FUNCTION(impl(), {})
|
||||
explicit impl(path const& path1) : m_path1(path1) {}
|
||||
impl(path const& path1, path const& path2) : m_path1(path1), m_path2(path2) {}
|
||||
};
|
||||
boost::intrusive_ptr< impl > m_imp_ptr;
|
||||
BOOST_DEFAULTED_FUNCTION(impl(), {})
|
||||
explicit impl(path const& path1) :
|
||||
m_path1(path1)
|
||||
{
|
||||
}
|
||||
impl(path const& path1, path const& path2) :
|
||||
m_path1(path1), m_path2(path2)
|
||||
{
|
||||
}
|
||||
};
|
||||
boost::intrusive_ptr< impl > m_imp_ptr;
|
||||
};
|
||||
|
||||
} // namespace filesystem
|
||||
@ -97,4 +103,5 @@ private:
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
|
||||
#endif // BOOST_FILESYSTEM3_EXCEPTION_HPP
|
||||
|
@ -18,12 +18,11 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
|
||||
#include <boost/detail/bitmask.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp> // must be the last #include
|
||||
@ -39,24 +38,24 @@ namespace filesystem {
|
||||
|
||||
enum file_type
|
||||
{
|
||||
status_error,
|
||||
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
status_unknown = status_error,
|
||||
# endif
|
||||
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
|
||||
status_error,
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
status_unknown = status_error,
|
||||
#endif
|
||||
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
|
||||
_detail_directory_symlink // internal use only; never exposed to users
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
@ -65,58 +64,58 @@ enum file_type
|
||||
|
||||
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.
|
||||
// Values are from POSIX and are given in octal per the POSIX standard.
|
||||
// POSIX equivalent macros given in comments.
|
||||
// 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_write = 0200, // S_IWUSR, Write permission, owner
|
||||
owner_exe = 0100, // S_IXUSR, Execute/search permission, owner
|
||||
owner_all = 0700, // S_IRWXU, Read, write, execute/search by owner
|
||||
owner_read = 0400, // S_IRUSR, Read permission, owner
|
||||
owner_write = 0200, // S_IWUSR, Write permission, owner
|
||||
owner_exe = 0100, // S_IXUSR, Execute/search permission, owner
|
||||
owner_all = 0700, // S_IRWXU, Read, write, execute/search by owner
|
||||
|
||||
group_read = 040, // S_IRGRP, Read permission, group
|
||||
group_write = 020, // S_IWGRP, Write permission, group
|
||||
group_exe = 010, // S_IXGRP, Execute/search permission, group
|
||||
group_all = 070, // S_IRWXG, Read, write, execute/search by group
|
||||
group_read = 040, // S_IRGRP, Read permission, group
|
||||
group_write = 020, // S_IWGRP, Write permission, group
|
||||
group_exe = 010, // S_IXGRP, Execute/search permission, group
|
||||
group_all = 070, // S_IRWXG, Read, write, execute/search by group
|
||||
|
||||
others_read = 04, // S_IROTH, Read permission, others
|
||||
others_write = 02, // S_IWOTH, Write permission, others
|
||||
others_exe = 01, // S_IXOTH, Execute/search permission, others
|
||||
others_all = 07, // S_IRWXO, Read, write, execute/search by others
|
||||
others_read = 04, // S_IROTH, Read permission, others
|
||||
others_write = 02, // S_IWOTH, Write permission, others
|
||||
others_exe = 01, // S_IXOTH, Execute/search permission, 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_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
|
||||
sticky_bit = 01000, // S_ISVTX,
|
||||
// (POSIX XSI) On directories, restricted deletion flag
|
||||
// (V7) 'sticky bit': save swapped text even after use
|
||||
// (SunOS) On non-directories: don't cache this file
|
||||
// (SVID-v4.2) On directories: restricted deletion flag
|
||||
// Also see http://en.wikipedia.org/wiki/Sticky_bit
|
||||
set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
|
||||
set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
|
||||
sticky_bit = 01000, // S_ISVTX,
|
||||
// (POSIX XSI) On directories, restricted deletion flag
|
||||
// (V7) 'sticky bit': save swapped text even after use
|
||||
// (SunOS) On non-directories: don't cache this file
|
||||
// (SVID-v4.2) On directories: restricted deletion flag
|
||||
// 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
|
||||
remove_perms = 0x2000, // removes the given permission bits from the current bits;
|
||||
// choose add_perms or remove_perms, not both; if neither add_perms
|
||||
// nor remove_perms is given, replace the current bits with
|
||||
// the given 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;
|
||||
// choose add_perms or remove_perms, not both; if neither add_perms
|
||||
// nor remove_perms is given, replace the current bits with
|
||||
// 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
|
||||
_detail_extend_perms_32_1 = 0x7fffffff,
|
||||
_detail_extend_perms_32_2 = -0x7fffffff-1
|
||||
// BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values
|
||||
_detail_extend_perms_32_1 = 0x7fffffff,
|
||||
_detail_extend_perms_32_2 = -0x7fffffff - 1
|
||||
};
|
||||
|
||||
BOOST_BITMASK(perms)
|
||||
@ -128,110 +127,125 @@ BOOST_BITMASK(perms)
|
||||
class file_status
|
||||
{
|
||||
public:
|
||||
BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
|
||||
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)
|
||||
{
|
||||
}
|
||||
BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT :
|
||||
m_value(v), m_perms(prms)
|
||||
{
|
||||
}
|
||||
BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
|
||||
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)
|
||||
{
|
||||
}
|
||||
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
|
||||
// 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.
|
||||
// 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
|
||||
// functions. GCC is not even consistent for the same release on different platforms.
|
||||
|
||||
BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT :
|
||||
m_value(rhs.m_value), m_perms(rhs.m_perms)
|
||||
{
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
m_value = rhs.m_value;
|
||||
m_perms = rhs.m_perms;
|
||||
return *this;
|
||||
}
|
||||
BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT :
|
||||
m_value(rhs.m_value),
|
||||
m_perms(rhs.m_perms)
|
||||
{
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
m_value = rhs.m_value;
|
||||
m_perms = rhs.m_perms;
|
||||
return *this;
|
||||
}
|
||||
|
||||
# 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
|
||||
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))
|
||||
{
|
||||
}
|
||||
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);
|
||||
return *this;
|
||||
}
|
||||
# endif
|
||||
#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
|
||||
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))
|
||||
{
|
||||
}
|
||||
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);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
// observers
|
||||
BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; }
|
||||
BOOST_CONSTEXPR perms permissions() const BOOST_NOEXCEPT { return m_perms; }
|
||||
// observers
|
||||
BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; }
|
||||
BOOST_CONSTEXPR perms permissions() const BOOST_NOEXCEPT { return m_perms; }
|
||||
|
||||
// modifiers
|
||||
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; }
|
||||
// modifiers
|
||||
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_CONSTEXPR bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
|
||||
{
|
||||
return type() == rhs.type() && permissions() == rhs.permissions();
|
||||
}
|
||||
BOOST_CONSTEXPR bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
BOOST_CONSTEXPR bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
|
||||
{
|
||||
return type() == rhs.type() && permissions() == rhs.permissions();
|
||||
}
|
||||
BOOST_CONSTEXPR bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
file_type m_value;
|
||||
enum perms m_perms;
|
||||
file_type m_value;
|
||||
enum perms m_perms;
|
||||
};
|
||||
|
||||
inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT
|
||||
{
|
||||
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);
|
||||
return f.type() != status_error;
|
||||
}
|
||||
|
||||
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
inline bool is_regular(file_status f) BOOST_NOEXCEPT { return filesystem::is_regular_file(f); }
|
||||
# endif
|
||||
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 bool is_regular(file_status f) BOOST_NOEXCEPT
|
||||
{
|
||||
return filesystem::is_regular_file(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
|
||||
#endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP
|
||||
|
@ -14,9 +14,9 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <iosfwd>
|
||||
@ -26,160 +26,160 @@
|
||||
|
||||
// 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()
|
||||
#if defined(BOOST_WINDOWS_API) \
|
||||
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
|
||||
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
|
||||
# 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
|
||||
# define BOOST_FILESYSTEM_C_STR c_str()
|
||||
#if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
|
||||
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
|
||||
#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
|
||||
#define BOOST_FILESYSTEM_C_STR c_str()
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(push)
|
||||
// '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
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// basic_filebuf //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
template < class charT, class traits = std::char_traits<charT> >
|
||||
class basic_filebuf : public std::basic_filebuf<charT,traits>
|
||||
{
|
||||
private: // disallow copying
|
||||
basic_filebuf(const basic_filebuf&);
|
||||
const basic_filebuf& operator=(const basic_filebuf&);
|
||||
template< class charT, class traits = std::char_traits< charT > >
|
||||
class basic_filebuf :
|
||||
public std::basic_filebuf< charT, traits >
|
||||
{
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(basic_filebuf(), {})
|
||||
BOOST_DELETED_FUNCTION(basic_filebuf(const basic_filebuf&))
|
||||
BOOST_DELETED_FUNCTION(const basic_filebuf& operator=(const basic_filebuf&))
|
||||
|
||||
public:
|
||||
basic_filebuf() {}
|
||||
virtual ~basic_filebuf() {}
|
||||
|
||||
basic_filebuf<charT,traits>*
|
||||
open(const path& p, std::ios_base::openmode mode)
|
||||
public:
|
||||
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)
|
||||
? this : 0;
|
||||
return std::basic_filebuf< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode) ? this : 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// basic_ifstream //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
template < class charT, class traits = std::char_traits<charT> >
|
||||
class basic_ifstream : public std::basic_ifstream<charT,traits>
|
||||
{
|
||||
private: // disallow copying
|
||||
basic_ifstream(const basic_ifstream&);
|
||||
const basic_ifstream& operator=(const basic_ifstream&);
|
||||
|
||||
public:
|
||||
basic_ifstream() {}
|
||||
template< class charT, class traits = std::char_traits< charT > >
|
||||
class basic_ifstream :
|
||||
public std::basic_ifstream< charT, traits >
|
||||
{
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(basic_ifstream(), {})
|
||||
|
||||
// use two signatures, rather than one signature with default second
|
||||
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
|
||||
|
||||
explicit basic_ifstream(const path& p)
|
||||
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
|
||||
explicit basic_ifstream(const path& p) :
|
||||
std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
|
||||
|
||||
basic_ifstream(const path& p, std::ios_base::openmode mode)
|
||||
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
|
||||
basic_ifstream(const path& p, std::ios_base::openmode 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)
|
||||
{ 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)
|
||||
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
|
||||
|
||||
virtual ~basic_ifstream() {}
|
||||
};
|
||||
{
|
||||
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// basic_ofstream //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
template < class charT, class traits = std::char_traits<charT> >
|
||||
class basic_ofstream : public std::basic_ofstream<charT,traits>
|
||||
{
|
||||
private: // disallow copying
|
||||
basic_ofstream(const basic_ofstream&);
|
||||
const basic_ofstream& operator=(const basic_ofstream&);
|
||||
|
||||
public:
|
||||
basic_ofstream() {}
|
||||
template< class charT, class traits = std::char_traits< charT > >
|
||||
class basic_ofstream :
|
||||
public std::basic_ofstream< charT, traits >
|
||||
{
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(basic_ofstream(), {})
|
||||
|
||||
// use two signatures, rather than one signature with default second
|
||||
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
|
||||
|
||||
explicit basic_ofstream(const path& p)
|
||||
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
|
||||
explicit basic_ofstream(const path& p) :
|
||||
std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
|
||||
|
||||
basic_ofstream(const path& p, std::ios_base::openmode mode)
|
||||
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
|
||||
basic_ofstream(const path& p, std::ios_base::openmode 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)
|
||||
{ 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)
|
||||
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
|
||||
|
||||
virtual ~basic_ofstream() {}
|
||||
};
|
||||
{
|
||||
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// basic_fstream //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
template < class charT, class traits = std::char_traits<charT> >
|
||||
class basic_fstream : public std::basic_fstream<charT,traits>
|
||||
{
|
||||
private: // disallow copying
|
||||
basic_fstream(const basic_fstream&);
|
||||
const basic_fstream & operator=(const basic_fstream&);
|
||||
|
||||
public:
|
||||
basic_fstream() {}
|
||||
template< class charT, class traits = std::char_traits< charT > >
|
||||
class basic_fstream :
|
||||
public std::basic_fstream< charT, traits >
|
||||
{
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(basic_fstream(), {})
|
||||
|
||||
// use two signatures, rather than one signature with default second
|
||||
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
|
||||
|
||||
explicit basic_fstream(const path& p)
|
||||
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR,
|
||||
std::ios_base::in | std::ios_base::out) {}
|
||||
explicit basic_fstream(const path& p) :
|
||||
std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out) {}
|
||||
|
||||
basic_fstream(const path& p, std::ios_base::openmode mode)
|
||||
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
|
||||
basic_fstream(const path& p, std::ios_base::openmode 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)
|
||||
{ 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)
|
||||
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
|
||||
|
||||
virtual ~basic_fstream() {}
|
||||
|
||||
};
|
||||
{
|
||||
std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// typedefs //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
typedef basic_filebuf<char> filebuf;
|
||||
typedef basic_ifstream<char> ifstream;
|
||||
typedef basic_ofstream<char> ofstream;
|
||||
typedef basic_fstream<char> fstream;
|
||||
typedef basic_filebuf< char > filebuf;
|
||||
typedef basic_ifstream< char > ifstream;
|
||||
typedef basic_ofstream< char > ofstream;
|
||||
typedef basic_fstream< char > fstream;
|
||||
|
||||
typedef basic_filebuf<wchar_t> wfilebuf;
|
||||
typedef basic_ifstream<wchar_t> wifstream;
|
||||
typedef basic_ofstream<wchar_t> wofstream;
|
||||
typedef basic_fstream<wchar_t> wfstream;
|
||||
typedef basic_filebuf< wchar_t > wfilebuf;
|
||||
typedef basic_ifstream< wchar_t > wifstream;
|
||||
typedef basic_ofstream< wchar_t > wofstream;
|
||||
typedef basic_fstream< wchar_t > wfstream;
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
@ -189,4 +189,5 @@ namespace filesystem
|
||||
#endif
|
||||
|
||||
#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
@ -12,16 +12,17 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/type_traits/is_array.hpp>
|
||||
#include <boost/type_traits/decay.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <cwchar> // for mbstate_t
|
||||
#include <cstddef>
|
||||
#include <cwchar> // for mbstate_t
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
@ -32,321 +33,359 @@
|
||||
|
||||
#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();
|
||||
// uses std::codecvt_base::result used for error codes:
|
||||
//
|
||||
// ok: Conversion successful.
|
||||
// partial: Not all source characters converted; one or more additional source
|
||||
// characters are needed to produce the final target character, or the
|
||||
// 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.
|
||||
// noconv: The source and target characters have the same type and encoding, so no
|
||||
// conversion was necessary.
|
||||
BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
|
||||
// uses std::codecvt_base::result used for error codes:
|
||||
//
|
||||
// ok: Conversion successful.
|
||||
// partial: Not all source characters converted; one or more additional source
|
||||
// characters are needed to produce the final target character, or the
|
||||
// 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.
|
||||
// noconv: The source and target characters have the same type and encoding, so no
|
||||
// conversion was necessary.
|
||||
|
||||
class directory_entry;
|
||||
class directory_entry;
|
||||
|
||||
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>
|
||||
struct is_pathable { static const bool value = false; };
|
||||
template< class T >
|
||||
struct is_pathable
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template<> struct is_pathable<char*> { static const bool value = true; };
|
||||
template<> struct is_pathable<const char*> { static const bool value = true; };
|
||||
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; };
|
||||
template<>
|
||||
struct is_pathable< char* >
|
||||
{
|
||||
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
|
||||
// conforming compilers. Replace by plain "bool" at some future date (2012?)
|
||||
typename boost::disable_if<boost::is_array<Container>, bool>::type
|
||||
empty(const Container & c)
|
||||
{ return c.begin() == c.end(); }
|
||||
typename boost::disable_if< boost::is_array< Container >, bool >::type
|
||||
empty(Container const& c)
|
||||
{
|
||||
return c.begin() == c.end();
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
bool empty(T * const & c_str)
|
||||
{
|
||||
template< class T >
|
||||
inline bool empty(T* const& c_str)
|
||||
{
|
||||
BOOST_ASSERT(c_str);
|
||||
return !*c_str;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, size_t N> inline
|
||||
bool empty(T (&x)[N])
|
||||
{ return !x[0]; }
|
||||
template< typename T, std::size_t N >
|
||||
inline bool empty(T (&x)[N])
|
||||
{
|
||||
return !x[0];
|
||||
}
|
||||
|
||||
// value types differ ---------------------------------------------------------------//
|
||||
//
|
||||
// A from_end argument of 0 is less efficient than a known end, so use only if needed
|
||||
// value types differ ---------------------------------------------------------------//
|
||||
//
|
||||
// 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
|
||||
void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring & to,
|
||||
const codecvt_type& cvt);
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring& to, codecvt_type const& cvt);
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string & to,
|
||||
const codecvt_type& cvt);
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string& to, codecvt_type const& cvt);
|
||||
|
||||
inline
|
||||
void convert(const char* from,
|
||||
std::wstring & to,
|
||||
const codecvt_type& cvt)
|
||||
{
|
||||
inline void convert(const char* from, std::wstring& to, codecvt_type const& cvt)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
convert(from, 0, to, cvt);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from,
|
||||
std::string & to,
|
||||
const codecvt_type& cvt)
|
||||
{
|
||||
inline void convert(const wchar_t* from, std::string& to, codecvt_type const& cvt)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
convert(from, 0, to, cvt);
|
||||
}
|
||||
}
|
||||
|
||||
// without codecvt
|
||||
// without codecvt
|
||||
|
||||
inline
|
||||
void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring & to);
|
||||
inline void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring& to);
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string & to);
|
||||
inline void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string& to);
|
||||
|
||||
inline
|
||||
void convert(const char* from,
|
||||
std::wstring & to);
|
||||
inline void convert(const char* from, std::wstring& to);
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from,
|
||||
std::string & to);
|
||||
inline void convert(const wchar_t* from, std::string& to);
|
||||
|
||||
// value types same -----------------------------------------------------------------//
|
||||
// value types same -----------------------------------------------------------------//
|
||||
|
||||
// char with codecvt
|
||||
// char with codecvt
|
||||
|
||||
inline
|
||||
void convert(const char* from, const char* from_end, std::string & to,
|
||||
const codecvt_type&)
|
||||
{
|
||||
inline void convert(const char* from, const char* from_end, std::string& to, codecvt_type const&)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
BOOST_ASSERT(from_end);
|
||||
to.append(from, from_end);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void convert(const char* from,
|
||||
std::string & to,
|
||||
const codecvt_type&)
|
||||
{
|
||||
inline void convert(const char* from, std::string& to, codecvt_type const&)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
to += from;
|
||||
}
|
||||
}
|
||||
|
||||
// wchar_t with codecvt
|
||||
// wchar_t with codecvt
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to,
|
||||
const codecvt_type&)
|
||||
{
|
||||
inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to, codecvt_type const&)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
BOOST_ASSERT(from_end);
|
||||
to.append(from, from_end);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from,
|
||||
std::wstring & to,
|
||||
const codecvt_type&)
|
||||
{
|
||||
inline void convert(const wchar_t* from, std::wstring& to, codecvt_type const&)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
to += from;
|
||||
}
|
||||
}
|
||||
|
||||
// char without codecvt
|
||||
// char without codecvt
|
||||
|
||||
inline
|
||||
void convert(const char* from, const char* from_end, std::string & to)
|
||||
{
|
||||
inline void convert(const char* from, const char* from_end, std::string& to)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
BOOST_ASSERT(from_end);
|
||||
to.append(from, from_end);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void convert(const char* from, std::string & to)
|
||||
{
|
||||
inline void convert(const char* from, std::string& to)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
to += from;
|
||||
}
|
||||
}
|
||||
|
||||
// wchar_t without codecvt
|
||||
// wchar_t without codecvt
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to)
|
||||
{
|
||||
inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
BOOST_ASSERT(from_end);
|
||||
to.append(from, from_end);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void convert(const wchar_t* from, std::wstring & to)
|
||||
{
|
||||
inline void convert(const wchar_t* from, std::wstring& to)
|
||||
{
|
||||
BOOST_ASSERT(from);
|
||||
to += from;
|
||||
}
|
||||
}
|
||||
|
||||
// Source dispatch -----------------------------------------------------------------//
|
||||
// Source dispatch -----------------------------------------------------------------//
|
||||
|
||||
// contiguous containers with codecvt
|
||||
template <class U> inline
|
||||
void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
// contiguous containers with codecvt
|
||||
template< class U >
|
||||
inline void dispatch(std::string const& c, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::wstring const& c, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::vector< char > const& c, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::vector< wchar_t > const& c, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
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
|
||||
template <class U> inline
|
||||
void dispatch(const std::string& c, U& to)
|
||||
{
|
||||
// contiguous containers without codecvt
|
||||
template< class U >
|
||||
inline void dispatch(std::string const& c, U& to)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::wstring& c, U& to)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::wstring const& c, U& to)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::vector<char>& c, U& to)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::vector< char > const& c, U& to)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template <class U> inline
|
||||
void dispatch(const std::vector<wchar_t>& c, U& to)
|
||||
{
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
template< class U >
|
||||
inline void dispatch(std::vector< wchar_t > const& c, U& to)
|
||||
{
|
||||
if (!c.empty())
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
convert(&*c.begin(), &*c.begin() + c.size(), to);
|
||||
}
|
||||
|
||||
// non-contiguous containers with codecvt
|
||||
template <class Container, class U> inline
|
||||
// non-contiguous containers with codecvt
|
||||
template< class Container, class U >
|
||||
inline
|
||||
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
|
||||
// conforming compilers. Replace by plain "void" at some future date (2012?)
|
||||
typename boost::disable_if<boost::is_array<Container>, void>::type
|
||||
dispatch(const Container & c, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
typename boost::disable_if< boost::is_array< Container >, void >::type
|
||||
dispatch(Container const& c, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
if (!c.empty())
|
||||
{
|
||||
std::basic_string<typename Container::value_type> s(c.begin(), c.end());
|
||||
convert(s.c_str(), s.c_str()+s.size(), to, cvt);
|
||||
std::basic_string< typename Container::value_type > s(c.begin(), c.end());
|
||||
convert(s.c_str(), s.c_str() + s.size(), to, cvt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// c_str
|
||||
template <class T, class U> inline
|
||||
void dispatch(T * const & c_str, U& to, const codecvt_type& cvt)
|
||||
{
|
||||
// c_str
|
||||
template< class T, class U >
|
||||
inline void dispatch(T* const& c_str, U& to, codecvt_type const& cvt)
|
||||
{
|
||||
// std::cout << "dispatch() const T *\n";
|
||||
BOOST_ASSERT(c_str);
|
||||
convert(c_str, to, cvt);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: there is no dispatch on C-style arrays because the array may
|
||||
// contain a string smaller than the array size.
|
||||
// Note: there is no dispatch on C-style arrays because the array may
|
||||
// contain a string smaller than the array size.
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void dispatch(const directory_entry & de,
|
||||
# ifdef BOOST_WINDOWS_API
|
||||
std::wstring & to,
|
||||
# else
|
||||
std::string & to,
|
||||
# endif
|
||||
const codecvt_type&);
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void dispatch(directory_entry const& de,
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
std::wstring& to,
|
||||
#else
|
||||
std::string& to,
|
||||
#endif
|
||||
codecvt_type const&);
|
||||
|
||||
// non-contiguous containers without codecvt
|
||||
template <class Container, class U> inline
|
||||
// non-contiguous containers without codecvt
|
||||
template< class Container, class U >
|
||||
inline
|
||||
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
|
||||
// conforming compilers. Replace by plain "void" at some future date (2012?)
|
||||
typename boost::disable_if<boost::is_array<Container>, void>::type
|
||||
dispatch(const Container & c, U& to)
|
||||
{
|
||||
typename boost::disable_if< boost::is_array< Container >, void >::type
|
||||
dispatch(Container const& c, U& to)
|
||||
{
|
||||
if (!c.empty())
|
||||
{
|
||||
std::basic_string<typename Container::value_type> seq(c.begin(), c.end());
|
||||
convert(seq.c_str(), seq.c_str()+seq.size(), to);
|
||||
std::basic_string< typename Container::value_type > seq(c.begin(), c.end());
|
||||
convert(seq.c_str(), seq.c_str() + seq.size(), to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// c_str
|
||||
template <class T, class U> inline
|
||||
void dispatch(T * const & c_str, U& to)
|
||||
{
|
||||
// c_str
|
||||
template< class T, class U >
|
||||
inline void dispatch(T* const& c_str, U& to)
|
||||
{
|
||||
// std::cout << "dispatch() const T *\n";
|
||||
BOOST_ASSERT(c_str);
|
||||
convert(c_str, to);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: there is no dispatch on C-style arrays because the array may
|
||||
// contain a string smaller than the array size.
|
||||
// Note: there is no dispatch on C-style arrays because the array may
|
||||
// contain a string smaller than the array size.
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void dispatch(const directory_entry & de,
|
||||
# ifdef BOOST_WINDOWS_API
|
||||
std::wstring & to
|
||||
# else
|
||||
std::string & to
|
||||
# endif
|
||||
);
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void dispatch(directory_entry const& de,
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
std::wstring& to
|
||||
#else
|
||||
std::string& to
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
}}} // namespace boost::filesystem::path_traits
|
||||
} // namespace path_traits
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
|
||||
#endif // BOOST_FILESYSTEM_PATH_TRAITS_HPP
|
||||
#endif // BOOST_FILESYSTEM_PATH_TRAITS_HPP
|
||||
|
@ -10,34 +10,35 @@
|
||||
#ifndef BOOST_FILESYSTEM_STRING_FILE_HPP
|
||||
#define BOOST_FILESYSTEM_STRING_FILE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/fstream.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
|
||||
{
|
||||
inline
|
||||
void save_string_file(const path& p, const std::string& str)
|
||||
{
|
||||
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());
|
||||
filesystem::ofstream file;
|
||||
file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||
file.open(p, std::ios_base::binary);
|
||||
file.write(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
inline
|
||||
void load_string_file(const path& p, std::string& str)
|
||||
inline void load_string_file(path const& p, std::string& str)
|
||||
{
|
||||
filesystem::ifstream file;
|
||||
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
file.open(p, std::ios_base::binary);
|
||||
std::size_t sz = static_cast<std::size_t>(filesystem::file_size(p));
|
||||
str.resize(sz, '\0');
|
||||
file.read(&str[0], sz);
|
||||
filesystem::ifstream file;
|
||||
file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||
file.open(p, std::ios_base::binary);
|
||||
std::size_t sz = static_cast< std::size_t >(filesystem::file_size(p));
|
||||
str.resize(sz, '\0');
|
||||
file.read(&str[0], sz);
|
||||
}
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_FILESYSTEM_STRING_FILE_HPP
|
||||
|
@ -13,65 +13,67 @@
|
||||
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/path_traits.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#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:
|
||||
codecvt_error_cat(){}
|
||||
const char* name() const BOOST_SYSTEM_NOEXCEPT BOOST_OVERRIDE;
|
||||
std::string message(int ev) const BOOST_OVERRIDE;
|
||||
};
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(codecvt_error_cat(), {})
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
std::string codecvt_error_cat::message(int ev) const
|
||||
{
|
||||
std::string codecvt_error_cat::message(int ev) const
|
||||
{
|
||||
std::string str;
|
||||
switch (ev)
|
||||
{
|
||||
case std::codecvt_base::ok:
|
||||
str = "ok";
|
||||
break;
|
||||
str = "ok";
|
||||
break;
|
||||
case std::codecvt_base::partial:
|
||||
str = "partial";
|
||||
break;
|
||||
str = "partial";
|
||||
break;
|
||||
case std::codecvt_base::error:
|
||||
str = "error";
|
||||
break;
|
||||
str = "error";
|
||||
break;
|
||||
case std::codecvt_base::noconv:
|
||||
str = "noconv";
|
||||
break;
|
||||
str = "noconv";
|
||||
break;
|
||||
default:
|
||||
str = "unknown error";
|
||||
str = "unknown error";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
} // 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()
|
||||
{
|
||||
static const codecvt_error_cat codecvt_error_cat_const;
|
||||
return codecvt_error_cat_const;
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
} // namespace filesystem
|
||||
} // namespace boost
|
||||
|
1110
src/directory.cpp
1110
src/directory.cpp
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,7 @@ namespace filesystem {
|
||||
typedef int err_t;
|
||||
|
||||
// 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_ALREADY_EXISTS EEXIST
|
||||
@ -43,7 +43,7 @@ typedef int err_t;
|
||||
typedef boost::winapi::DWORD_ err_t;
|
||||
|
||||
// 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_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
|
||||
@ -55,52 +55,52 @@ typedef boost::winapi::DWORD_ err_t;
|
||||
|
||||
// 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, const path& 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& p, 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)
|
||||
{
|
||||
if (BOOST_LIKELY(!error_num))
|
||||
{
|
||||
if (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, ec, message);
|
||||
return true;
|
||||
}
|
||||
if (BOOST_LIKELY(!error_num))
|
||||
{
|
||||
if (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, ec, message);
|
||||
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 (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, p, ec, message);
|
||||
return true;
|
||||
}
|
||||
if (BOOST_LIKELY(!error_num))
|
||||
{
|
||||
if (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, p, ec, message);
|
||||
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 (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, p1, p2, ec, message);
|
||||
return true;
|
||||
}
|
||||
if (BOOST_LIKELY(!error_num))
|
||||
{
|
||||
if (ec)
|
||||
ec->clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // error
|
||||
filesystem::emit_error(error_num, p1, p2, ec, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
@ -23,55 +23,55 @@ namespace boost {
|
||||
namespace filesystem {
|
||||
|
||||
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
|
||||
{
|
||||
m_imp_ptr.reset(new impl());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr.reset();
|
||||
}
|
||||
try
|
||||
{
|
||||
m_imp_ptr.reset(new impl());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr.reset();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) :
|
||||
system::system_error(ec, what_arg)
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_imp_ptr.reset(new impl(path1_arg));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr.reset();
|
||||
}
|
||||
try
|
||||
{
|
||||
m_imp_ptr.reset(new impl(path1_arg));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
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) :
|
||||
system::system_error(ec, what_arg)
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_imp_ptr.reset(new impl(path1_arg, path2_arg));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr.reset();
|
||||
}
|
||||
try
|
||||
{
|
||||
m_imp_ptr.reset(new impl(path1_arg, path2_arg));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr.reset();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) :
|
||||
system::system_error(static_cast< system::system_error const& >(that)),
|
||||
m_imp_ptr(that.m_imp_ptr)
|
||||
system::system_error(static_cast< system::system_error const& >(that)),
|
||||
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);
|
||||
m_imp_ptr = that.m_imp_ptr;
|
||||
return *this;
|
||||
static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
|
||||
m_imp_ptr = that.m_imp_ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if (m_imp_ptr.get()) try
|
||||
{
|
||||
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 += ": \"";
|
||||
m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
|
||||
m_imp_ptr->m_what += "\"";
|
||||
}
|
||||
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 += "\"";
|
||||
}
|
||||
}
|
||||
if (m_imp_ptr.get())
|
||||
try
|
||||
{
|
||||
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 += ": \"";
|
||||
m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
|
||||
m_imp_ptr->m_what += "\"";
|
||||
}
|
||||
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 += "\"";
|
||||
}
|
||||
}
|
||||
|
||||
return m_imp_ptr->m_what.c_str();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_imp_ptr->m_what.clear();
|
||||
}
|
||||
return m_imp_ptr->m_what.c_str();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
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;
|
||||
return empty_path;
|
||||
static const path empty_path;
|
||||
return empty_path;
|
||||
}
|
||||
|
||||
// error handling helpers declared in error_handling.hpp -----------------------------------------------------//
|
||||
|
||||
void emit_error(err_t error_num, system::error_code* ec, const char* message)
|
||||
{
|
||||
if (!ec)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
ec->assign(error_num, system::system_category());
|
||||
if (!ec)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
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)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
ec->assign(error_num, system::system_category());
|
||||
if (!ec)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
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)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
ec->assign(error_num, system::system_category());
|
||||
if (ec == 0)
|
||||
BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
|
||||
else
|
||||
ec->assign(error_num, system::system_category());
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
4237
src/operations.cpp
4237
src/operations.cpp
File diff suppressed because it is too large
Load Diff
1108
src/path.cpp
1108
src/path.cpp
File diff suppressed because it is too large
Load Diff
@ -11,12 +11,16 @@
|
||||
|
||||
#include "platform_config.hpp"
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/path_traits.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <locale> // for codecvt_base::result
|
||||
#include <cstring> // for strlen
|
||||
#include <cwchar> // for wcslen
|
||||
#include <boost/smart_ptr/scoped_array.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#include <locale> // for codecvt_base::result
|
||||
#include <cstring> // for strlen
|
||||
#include <cwchar> // for wcslen
|
||||
#include <cstddef>
|
||||
|
||||
namespace pt = boost::filesystem::path_traits;
|
||||
namespace fs = boost::filesystem;
|
||||
@ -27,13 +31,12 @@ namespace bs = boost::system;
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
|
||||
# define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
|
||||
#define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
|
||||
#endif
|
||||
|
||||
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 //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
void convert_aux(
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
wchar_t* to, wchar_t* to_end,
|
||||
std::wstring & target,
|
||||
const pt::codecvt_type & cvt)
|
||||
{
|
||||
void convert_aux(
|
||||
const char* from,
|
||||
const char* from_end,
|
||||
wchar_t* to, wchar_t* to_end,
|
||||
std::wstring& target,
|
||||
pt::codecvt_type const& cvt)
|
||||
{
|
||||
//std::cout << std::hex
|
||||
// << " from=" << std::size_t(from)
|
||||
// << " from_end=" << std::size_t(from_end)
|
||||
@ -60,33 +63,31 @@ namespace {
|
||||
// << " to_end=" << std::size_t(to_end)
|
||||
// << 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;
|
||||
wchar_t* to_next;
|
||||
|
||||
std::codecvt_base::result res;
|
||||
|
||||
if ((res=cvt.in(state, from, from_end, from_next,
|
||||
to, to_end, to_next)) != std::codecvt_base::ok)
|
||||
if ((res = cvt.in(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
|
||||
{
|
||||
//std::cout << " result is " << static_cast<int>(res) << std::endl;
|
||||
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
|
||||
"boost::filesystem::path codecvt to wstring"));
|
||||
//std::cout << " result is " << static_cast<int>(res) << std::endl;
|
||||
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to wstring"));
|
||||
}
|
||||
target.append(to, to_next);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// convert_aux const wchar_t* to string //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
void convert_aux(
|
||||
const wchar_t* from,
|
||||
const wchar_t* from_end,
|
||||
char* to, char* to_end,
|
||||
std::string & target,
|
||||
const pt::codecvt_type & cvt)
|
||||
{
|
||||
void convert_aux(
|
||||
const wchar_t* from,
|
||||
const wchar_t* from_end,
|
||||
char* to, char* to_end,
|
||||
std::string& target,
|
||||
pt::codecvt_type const& cvt)
|
||||
{
|
||||
//std::cout << std::hex
|
||||
// << " from=" << std::size_t(from)
|
||||
// << " from_end=" << std::size_t(from_end)
|
||||
@ -94,100 +95,103 @@ namespace {
|
||||
// << " to_end=" << std::size_t(to_end)
|
||||
// << 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;
|
||||
char* to_next;
|
||||
|
||||
std::codecvt_base::result res;
|
||||
|
||||
if ((res=cvt.out(state, from, from_end, from_next,
|
||||
to, to_end, to_next)) != std::codecvt_base::ok)
|
||||
if ((res = cvt.out(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
|
||||
{
|
||||
//std::cout << " result is " << static_cast<int>(res) << std::endl;
|
||||
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
|
||||
"boost::filesystem::path codecvt to string"));
|
||||
//std::cout << " result is " << static_cast<int>(res) << std::endl;
|
||||
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to string"));
|
||||
}
|
||||
target.append(to, to_next);
|
||||
}
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
} // unnamed namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// path_traits //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
namespace boost { namespace filesystem { namespace path_traits {
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
namespace path_traits {
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// convert const char* to wstring //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring & to,
|
||||
const codecvt_type & cvt)
|
||||
{
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const char* from,
|
||||
const char* from_end, // 0 for null terminated MBCS
|
||||
std::wstring& to, codecvt_type const& cvt)
|
||||
{
|
||||
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
|
||||
if (buf_size > default_codecvt_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);
|
||||
boost::scoped_array< wchar_t > buf(new wchar_t[buf_size]);
|
||||
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buf[default_codecvt_buf_size];
|
||||
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
|
||||
wchar_t buf[default_codecvt_buf_size];
|
||||
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// convert const wchar_t* to string //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string & to,
|
||||
const codecvt_type & cvt)
|
||||
{
|
||||
BOOST_FILESYSTEM_DECL
|
||||
void convert(const wchar_t* from,
|
||||
const wchar_t* from_end, // 0 for null terminated MBCS
|
||||
std::string& to, codecvt_type const& cvt)
|
||||
{
|
||||
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
|
||||
// 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
|
||||
// will have to be fixed.
|
||||
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
|
||||
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
|
||||
|
||||
// dynamically allocate a buffer only if source is unusually large
|
||||
if (buf_size > default_codecvt_buf_size)
|
||||
{
|
||||
boost::scoped_array< char > buf(new char [buf_size]);
|
||||
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt);
|
||||
boost::scoped_array< char > buf(new char[buf_size]);
|
||||
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[default_codecvt_buf_size];
|
||||
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
|
||||
char buf[default_codecvt_buf_size];
|
||||
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
|
||||
|
@ -59,7 +59,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
#define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this
|
||||
#define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this
|
||||
#endif
|
||||
|
||||
#if !defined(_INCLUDE_STDCSOURCE_199901) && (defined(hpux) || defined(_hpux) || defined(__hpux))
|
||||
@ -68,7 +68,7 @@
|
||||
#define _INCLUDE_STDCSOURCE_199901
|
||||
#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__)
|
||||
// Define target Windows version macros before including any other headers
|
||||
#include <boost/winapi/config.hpp>
|
||||
|
@ -11,100 +11,79 @@
|
||||
|
||||
#include "platform_config.hpp"
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
#include <cstring> // SGI MIPSpro compilers need this
|
||||
#include <string>
|
||||
|
||||
# ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std { using ::strerror; }
|
||||
# endif
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std {
|
||||
using ::strerror;
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
namespace
|
||||
{
|
||||
const char invalid_chars[] =
|
||||
namespace {
|
||||
|
||||
BOOST_CONSTEXPR_OR_CONST char invalid_chars[] =
|
||||
"\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"
|
||||
"<>:\"/\\|";
|
||||
// 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
|
||||
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
|
||||
// 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
|
||||
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
|
||||
|
||||
const std::string valid_posix(
|
||||
const std::string valid_posix(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
|
||||
} // 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 native(const std::string & 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 windows_name(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 == "..");
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name)
|
||||
{
|
||||
return !name.empty()
|
||||
&& name.find_first_not_of(valid_posix) == std::string::npos;
|
||||
}
|
||||
BOOST_FILESYSTEM_DECL bool portable_name(const std::string& name)
|
||||
{
|
||||
return !name.empty() && (name == "." || name == ".." || (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-'));
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL bool windows_name(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 == "..");
|
||||
}
|
||||
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string& name)
|
||||
{
|
||||
return name == "." || name == ".." || (portable_name(name) && name.find('.') == std::string::npos);
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name)
|
||||
{
|
||||
return !name.empty()
|
||||
&& (name == "."
|
||||
|| name == ".."
|
||||
|| (windows_name(name)
|
||||
&& portable_posix_name(name)
|
||||
&& name[0] != '.' && name[0] != '-'));
|
||||
}
|
||||
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()));
|
||||
}
|
||||
|
||||
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name)
|
||||
{
|
||||
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 filesystem
|
||||
} // namespace boost
|
||||
|
@ -17,62 +17,73 @@
|
||||
#include <boost/predef/os/bsd/free.h>
|
||||
|
||||
#ifdef BOOST_POSIX_API
|
||||
# include <cerrno>
|
||||
# include <stddef.h>
|
||||
# include <fcntl.h>
|
||||
# ifdef BOOST_HAS_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# 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
|
||||
# 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)
|
||||
|
||||
#include <cerrno>
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef BOOST_HAS_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#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 <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include "error_handling.hpp"
|
||||
|
||||
@ -83,7 +94,9 @@
|
||||
#endif
|
||||
#endif // defined(BOOST_POSIX_API)
|
||||
|
||||
namespace boost { namespace filesystem { namespace detail {
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
namespace detail {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -91,20 +104,20 @@ namespace {
|
||||
//! Converts NTSTATUS error codes to Win32 error codes for reporting
|
||||
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.
|
||||
// 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.
|
||||
switch (static_cast< boost::winapi::ULONG_ >(status))
|
||||
{
|
||||
case 0xC0000017ul: // STATUS_NO_MEMORY
|
||||
return boost::winapi::ERROR_OUTOFMEMORY_;
|
||||
case 0xC0000008ul: // STATUS_INVALID_HANDLE
|
||||
return boost::winapi::ERROR_INVALID_HANDLE_;
|
||||
case 0xC000000Dul: // STATUS_INVALID_PARAMETER
|
||||
return boost::winapi::ERROR_INVALID_PARAMETER_;
|
||||
default:
|
||||
return boost::winapi::ERROR_NOT_SUPPORTED_;
|
||||
}
|
||||
// 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
|
||||
// integral type to avoid signed overflow and narrowing conversion in the constants.
|
||||
switch (static_cast< boost::winapi::ULONG_ >(status))
|
||||
{
|
||||
case 0xC0000017ul: // STATUS_NO_MEMORY
|
||||
return boost::winapi::ERROR_OUTOFMEMORY_;
|
||||
case 0xC0000008ul: // STATUS_INVALID_HANDLE
|
||||
return boost::winapi::ERROR_INVALID_HANDLE_;
|
||||
case 0xC000000Dul: // STATUS_INVALID_PARAMETER
|
||||
return boost::winapi::ERROR_INVALID_PARAMETER_;
|
||||
default:
|
||||
return boost::winapi::ERROR_NOT_SUPPORTED_;
|
||||
}
|
||||
}
|
||||
#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)
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
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))
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < len)
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EINTR)
|
||||
continue;
|
||||
emit_error(err, ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
}
|
||||
#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 (err == EINTR)
|
||||
continue;
|
||||
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;
|
||||
}
|
||||
|
||||
#elif defined(BOOST_FILESYSTEM_HAS_ARC4RANDOM)
|
||||
|
||||
arc4random_buf(buf, len);
|
||||
arc4random_buf(buf, len);
|
||||
|
||||
#else
|
||||
|
||||
int file = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if (file == -1)
|
||||
{
|
||||
file = open("/dev/random", O_RDONLY | O_CLOEXEC);
|
||||
int file = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if (file == -1)
|
||||
{
|
||||
emit_error(errno, ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
file = open("/dev/random", O_RDONLY | O_CLOEXEC);
|
||||
if (file == -1)
|
||||
{
|
||||
emit_error(errno, ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < len)
|
||||
{
|
||||
ssize_t n = read(file, buf, len - bytes_read);
|
||||
if (BOOST_UNLIKELY(n == -1))
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < len)
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EINTR)
|
||||
continue;
|
||||
close(file);
|
||||
emit_error(err, ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
ssize_t n = read(file, buf, len - bytes_read);
|
||||
if (BOOST_UNLIKELY(n == -1))
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EINTR)
|
||||
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
|
||||
|
||||
@ -177,44 +190,44 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
|
||||
|
||||
#if defined(BOOST_FILESYSTEM_HAS_BCRYPT)
|
||||
|
||||
boost::winapi::BCRYPT_ALG_HANDLE_ handle;
|
||||
boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
|
||||
if (BOOST_UNLIKELY(status != 0))
|
||||
{
|
||||
fail:
|
||||
emit_error(translate_ntstatus(status), ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
}
|
||||
boost::winapi::BCRYPT_ALG_HANDLE_ handle;
|
||||
boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
|
||||
if (BOOST_UNLIKELY(status != 0))
|
||||
{
|
||||
fail:
|
||||
emit_error(translate_ntstatus(status), ec, "boost::filesystem::unique_path");
|
||||
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))
|
||||
goto fail;
|
||||
if (BOOST_UNLIKELY(status != 0))
|
||||
goto fail;
|
||||
|
||||
#else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
|
||||
|
||||
boost::winapi::HCRYPTPROV_ handle;
|
||||
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_)))
|
||||
{
|
||||
err = boost::winapi::GetLastError();
|
||||
boost::winapi::HCRYPTPROV_ handle;
|
||||
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_)))
|
||||
{
|
||||
err = boost::winapi::GetLastError();
|
||||
|
||||
fail:
|
||||
emit_error(err, ec, "boost::filesystem::unique_path");
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
emit_error(err, ec, "boost::filesystem::unique_path");
|
||||
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))
|
||||
err = boost::winapi::GetLastError();
|
||||
if (BOOST_UNLIKELY(!gen_ok))
|
||||
err = boost::winapi::GetLastError();
|
||||
|
||||
boost::winapi::CryptReleaseContext(handle, 0);
|
||||
boost::winapi::CryptReleaseContext(handle, 0);
|
||||
|
||||
if (BOOST_UNLIKELY(!gen_ok))
|
||||
goto fail;
|
||||
if (BOOST_UNLIKELY(!gen_ok))
|
||||
goto fail;
|
||||
|
||||
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
|
||||
|
||||
@ -229,44 +242,47 @@ BOOST_CONSTEXPR_OR_CONST char hex[] = "0123456789abcdef";
|
||||
BOOST_CONSTEXPR_OR_CONST char percent = '%';
|
||||
#endif
|
||||
|
||||
} // unnamed namespace
|
||||
} // unnamed namespace
|
||||
|
||||
BOOST_FILESYSTEM_DECL
|
||||
path unique_path(const path& model, system::error_code* ec)
|
||||
{
|
||||
// This function used wstring for fear of misidentifying
|
||||
// a part of a multibyte character as a percent sign.
|
||||
// However, double byte encodings only have 80-FF as lead
|
||||
// bytes and 40-7F as trailing bytes, whereas % is 25.
|
||||
// So, use string on POSIX and avoid conversions.
|
||||
// This function used wstring for fear of misidentifying
|
||||
// a part of a multibyte character as a percent sign.
|
||||
// However, double byte encodings only have 80-FF as lead
|
||||
// bytes and 40-7F as trailing bytes, whereas % is 25.
|
||||
// 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
|
||||
// see ticket #8954
|
||||
BOOST_CONSTEXPR_OR_CONST unsigned int max_nibbles = 2u * sizeof(ran); // 4-bits per nibble
|
||||
char ran[16] = {}; // init to avoid clang static analyzer message
|
||||
// see ticket #8954
|
||||
BOOST_CONSTEXPR_OR_CONST unsigned int max_nibbles = 2u * sizeof(ran); // 4-bits per nibble
|
||||
|
||||
unsigned int nibbles_used = max_nibbles;
|
||||
for (path::string_type::size_type i = 0, n = s.size(); i < n; ++i)
|
||||
{
|
||||
if (s[i] == percent) // digit request
|
||||
unsigned int nibbles_used = max_nibbles;
|
||||
for (path::string_type::size_type i = 0, n = s.size(); i < n; ++i)
|
||||
{
|
||||
if (nibbles_used == max_nibbles)
|
||||
{
|
||||
system_crypt_random(ran, sizeof(ran), ec);
|
||||
if (ec != 0 && *ec)
|
||||
return path();
|
||||
nibbles_used = 0;
|
||||
}
|
||||
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 (s[i] == percent) // digit request
|
||||
{
|
||||
if (nibbles_used == max_nibbles)
|
||||
{
|
||||
system_crypt_random(ran, sizeof(ran), ec);
|
||||
if (ec != 0 && *ec)
|
||||
return path();
|
||||
nibbles_used = 0;
|
||||
}
|
||||
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
|
||||
|
@ -5,10 +5,17 @@
|
||||
|
||||
#include "platform_config.hpp"
|
||||
|
||||
#define BOOST_UTF8_BEGIN_NAMESPACE \
|
||||
namespace boost { namespace filesystem { namespace detail {
|
||||
#include <boost/filesystem/config.hpp>
|
||||
|
||||
#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
|
||||
|
||||
#include <boost/detail/utf8_codecvt_facet.ipp>
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "platform_config.hpp"
|
||||
|
||||
#include <cwchar> // for mbstate_t
|
||||
#include <cwchar> // for mbstate_t
|
||||
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
|
||||
@ -20,43 +20,41 @@
|
||||
#include <windows.h>
|
||||
|
||||
std::codecvt_base::result windows_file_codecvt::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
|
||||
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
|
||||
{
|
||||
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
|
||||
int count;
|
||||
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from,
|
||||
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
|
||||
{
|
||||
return error; // conversion failed
|
||||
}
|
||||
int count;
|
||||
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0)
|
||||
{
|
||||
return error; // conversion failed
|
||||
}
|
||||
|
||||
from_next = from_end;
|
||||
to_next = to + count;
|
||||
*to_next = L'\0';
|
||||
return ok;
|
||||
from_next = from_end;
|
||||
to_next = to + count;
|
||||
*to_next = L'\0';
|
||||
return ok;
|
||||
}
|
||||
|
||||
std::codecvt_base::result windows_file_codecvt::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
|
||||
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
|
||||
{
|
||||
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
|
||||
int count;
|
||||
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)
|
||||
{
|
||||
return error; // conversion failed
|
||||
}
|
||||
int count;
|
||||
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)
|
||||
{
|
||||
return error; // conversion failed
|
||||
}
|
||||
|
||||
from_next = from_end;
|
||||
to_next = to + count;
|
||||
*to_next = '\0';
|
||||
return ok;
|
||||
from_next = from_end;
|
||||
to_next = to + count;
|
||||
*to_next = '\0';
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif // BOOST_WINDOWS_API
|
||||
#endif // BOOST_WINDOWS_API
|
||||
|
@ -23,35 +23,26 @@
|
||||
// //
|
||||
//------------------------------------------------------------------------------------//
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE windows_file_codecvt
|
||||
: public std::codecvt< wchar_t, char, std::mbstate_t >
|
||||
class BOOST_SYMBOL_VISIBLE windows_file_codecvt :
|
||||
public std::codecvt< wchar_t, char, std::mbstate_t >
|
||||
{
|
||||
public:
|
||||
explicit windows_file_codecvt(std::size_t refs = 0)
|
||||
: std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}
|
||||
explicit windows_file_codecvt(std::size_t refs = 0) :
|
||||
std::codecvt< wchar_t, char, std::mbstate_t >(refs)
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
virtual int do_encoding() const throw() { return 0; }
|
||||
|
||||
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 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; }
|
||||
// seems safest to assume variable number of characters since we don't
|
||||
// actually know what codepage is active
|
||||
virtual int do_encoding() const throw() { return 0; }
|
||||
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 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
|
||||
|
@ -24,27 +24,23 @@ namespace detail {
|
||||
|
||||
inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5])
|
||||
{
|
||||
return
|
||||
(p[0] == x1[0] || p[0] == x2[0]) &&
|
||||
(p[1] == x1[1] || p[1] == x2[1]) &&
|
||||
(p[2] == x1[2] || p[2] == x2[2]) &&
|
||||
(p[3] == x1[3] || p[3] == x2[3]) &&
|
||||
p[4] == 0;
|
||||
return (p[0] == x1[0] || p[0] == x2[0]) &&
|
||||
(p[1] == x1[1] || p[1] == x2[1]) &&
|
||||
(p[2] == x1[2] || p[2] == x2[2]) &&
|
||||
(p[3] == x1[3] || p[3] == x2[3]) &&
|
||||
p[4] == 0;
|
||||
}
|
||||
|
||||
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;
|
||||
if ((attr & FILE_ATTRIBUTE_READONLY) == 0u)
|
||||
prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
|
||||
boost::filesystem::path ext = p.extension();
|
||||
wchar_t const* q = ext.c_str();
|
||||
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"))
|
||||
prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
|
||||
return prms;
|
||||
boost::filesystem::perms prms = boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read;
|
||||
if ((attr & FILE_ATTRIBUTE_READONLY) == 0u)
|
||||
prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
|
||||
boost::filesystem::path ext = p.extension();
|
||||
wchar_t const* q = ext.c_str();
|
||||
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"))
|
||||
prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
|
||||
return prms;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
@ -16,37 +16,35 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Verify macro reporting works correctly\n";
|
||||
cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl;
|
||||
# define SUCHAMACRO
|
||||
cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl;
|
||||
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
|
||||
cout << "Verify macro reporting works correctly\n";
|
||||
cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl;
|
||||
#define SUCHAMACRO
|
||||
cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << 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 << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_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_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << 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_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_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl;
|
||||
cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl;
|
||||
cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl;
|
||||
cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << 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 << "Report macro values that may be useful in debugging various test programs\n";
|
||||
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_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_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << 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_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_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl;
|
||||
cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl;
|
||||
cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl;
|
||||
cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << 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;
|
||||
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
// See deprecated_test for tests of deprecated features
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
@ -23,9 +23,9 @@
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
@ -37,143 +37,146 @@ namespace fs = boost::filesystem;
|
||||
using fs::path;
|
||||
namespace sys = boost::system;
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
template< typename F >
|
||||
bool throws_fs_error(F func)
|
||||
{
|
||||
template< typename F >
|
||||
bool throws_fs_error(F func)
|
||||
{
|
||||
try { func(); }
|
||||
|
||||
catch (const fs::filesystem_error &)
|
||||
try
|
||||
{
|
||||
return true;
|
||||
func();
|
||||
}
|
||||
|
||||
catch (const fs::filesystem_error&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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*[])
|
||||
{
|
||||
|
||||
// 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_yy = unique_dir / "yy";
|
||||
path unique_yya = unique_dir / "yya";
|
||||
path unique_yy_zz = unique_dir / "yy" / "zz";
|
||||
path unique_dir = fs::unique_path(); // unique name in case tests running in parallel
|
||||
path unique_yy = unique_dir / "yy";
|
||||
path unique_yya = unique_dir / "yya";
|
||||
path unique_yy_zz = unique_dir / "yy" / "zz";
|
||||
|
||||
fs::remove_all(unique_dir); // make sure slate is blank
|
||||
BOOST_TEST(!fs::exists(unique_dir)); // reality check
|
||||
fs::remove_all(unique_dir); // make sure slate is blank
|
||||
BOOST_TEST(!fs::exists(unique_dir)); // reality check
|
||||
|
||||
BOOST_TEST(fs::create_directories(unique_dir));
|
||||
BOOST_TEST(fs::exists(unique_dir));
|
||||
BOOST_TEST(fs::is_directory(unique_dir));
|
||||
BOOST_TEST(fs::create_directories(unique_dir));
|
||||
BOOST_TEST(fs::exists(unique_dir));
|
||||
BOOST_TEST(fs::is_directory(unique_dir));
|
||||
|
||||
BOOST_TEST(fs::create_directories(unique_yy_zz));
|
||||
BOOST_TEST(fs::exists(unique_dir));
|
||||
BOOST_TEST(fs::exists(unique_yy));
|
||||
BOOST_TEST(fs::exists(unique_yy_zz));
|
||||
BOOST_TEST(fs::is_directory(unique_dir));
|
||||
BOOST_TEST(fs::is_directory(unique_yy));
|
||||
BOOST_TEST(fs::is_directory(unique_yy_zz));
|
||||
BOOST_TEST(fs::create_directories(unique_yy_zz));
|
||||
BOOST_TEST(fs::exists(unique_dir));
|
||||
BOOST_TEST(fs::exists(unique_yy));
|
||||
BOOST_TEST(fs::exists(unique_yy_zz));
|
||||
BOOST_TEST(fs::is_directory(unique_dir));
|
||||
BOOST_TEST(fs::is_directory(unique_yy));
|
||||
BOOST_TEST(fs::is_directory(unique_yy_zz));
|
||||
|
||||
path is_a_file(unique_dir / "uu");
|
||||
{
|
||||
std::ofstream f(is_a_file.string().c_str());
|
||||
BOOST_TEST(!!f);
|
||||
}
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(fs::create_directories, is_a_file)));
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(fs::create_directories, is_a_file / "aa")));
|
||||
path is_a_file(unique_dir / "uu");
|
||||
{
|
||||
std::ofstream f(is_a_file.string().c_str());
|
||||
BOOST_TEST(!!f);
|
||||
}
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(fs::create_directories, is_a_file)));
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(fs::create_directories, is_a_file / "aa")));
|
||||
|
||||
// recursive_directory_iterator tests ----------------------------------------//
|
||||
// recursive_directory_iterator tests ----------------------------------------//
|
||||
|
||||
sys::error_code ec;
|
||||
fs::recursive_directory_iterator it("/no-such-path", ec);
|
||||
BOOST_TEST(ec);
|
||||
sys::error_code ec;
|
||||
fs::recursive_directory_iterator it("/no-such-path", ec);
|
||||
BOOST_TEST(ec);
|
||||
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(create_recursive_iterator, "/no-such-path")));
|
||||
BOOST_TEST(throws_fs_error(
|
||||
boost::bind(create_recursive_iterator, "/no-such-path")));
|
||||
|
||||
fs::remove(unique_dir / "uu");
|
||||
fs::remove(unique_dir / "uu");
|
||||
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
// These tests depends on ordering of directory entries, and that's guaranteed
|
||||
// on Windows but not necessarily on other operating systems
|
||||
{
|
||||
std::ofstream f(unique_yya.string().c_str());
|
||||
BOOST_TEST(!!f);
|
||||
}
|
||||
// These tests depends on ordering of directory entries, and that's guaranteed
|
||||
// on Windows but not necessarily on other operating systems
|
||||
{
|
||||
std::ofstream f(unique_yya.string().c_str());
|
||||
BOOST_TEST(!!f);
|
||||
}
|
||||
|
||||
for (it = fs::recursive_directory_iterator(unique_dir);
|
||||
it != fs::recursive_directory_iterator(); ++it)
|
||||
{ std::cout << it->path() << '\n'; }
|
||||
for (it = fs::recursive_directory_iterator(unique_dir);
|
||||
it != fs::recursive_directory_iterator(); ++it)
|
||||
{
|
||||
std::cout << it->path() << '\n';
|
||||
}
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yy_zz);
|
||||
BOOST_TEST(it.depth() == 1);
|
||||
it.pop();
|
||||
BOOST_TEST(it->path() == unique_yya);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
it++;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yy_zz);
|
||||
BOOST_TEST(it.depth() == 1);
|
||||
it.pop();
|
||||
BOOST_TEST(it->path() == unique_yya);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
it++;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
it.disable_recursion_pending();
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yya);
|
||||
++it;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
it.disable_recursion_pending();
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yya);
|
||||
++it;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
fs::remove(unique_yya);
|
||||
fs::remove(unique_yya);
|
||||
#endif
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_yy_zz);
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_yy_zz);
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yy_zz);
|
||||
BOOST_TEST(it.depth() == 1);
|
||||
it++;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
BOOST_TEST(it.depth() == 0);
|
||||
++it;
|
||||
BOOST_TEST(it->path() == unique_yy_zz);
|
||||
BOOST_TEST(it.depth() == 1);
|
||||
it++;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
it.disable_recursion_pending();
|
||||
++it;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
it.disable_recursion_pending();
|
||||
++it;
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
++it;
|
||||
it.pop();
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
it = fs::recursive_directory_iterator(unique_dir);
|
||||
BOOST_TEST(it->path() == unique_yy);
|
||||
++it;
|
||||
it.pop();
|
||||
BOOST_TEST(it == fs::recursive_directory_iterator());
|
||||
|
||||
ec.clear();
|
||||
BOOST_TEST(!ec);
|
||||
// check that two argument failed constructor creates the end iterator
|
||||
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec)
|
||||
== fs::recursive_directory_iterator());
|
||||
BOOST_TEST(ec);
|
||||
ec.clear();
|
||||
BOOST_TEST(!ec);
|
||||
// check that two argument failed constructor creates the end iterator
|
||||
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator());
|
||||
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();
|
||||
}
|
||||
|
@ -25,11 +25,10 @@
|
||||
|
||||
// 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()
|
||||
#if defined(BOOST_WINDOWS_API) \
|
||||
&& (!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
|
||||
#else // use the native c_str, which will be narrow on POSIX, wide on Windows
|
||||
# define BOOST_FILESYSTEM_C_STR c_str()
|
||||
#if defined(BOOST_WINDOWS_API) && (!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
|
||||
#else // use the native c_str, which will be narrow on POSIX, wide on Windows
|
||||
#define BOOST_FILESYSTEM_C_STR c_str()
|
||||
#endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
@ -55,7 +54,7 @@ void verify_file(fs::path const& ph, std::string const& expected)
|
||||
BOOST_TEST_EQ(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';
|
||||
|
||||
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)
|
||||
{
|
||||
fs::path p = fs::relative(it->path(), root_dir);
|
||||
@ -312,17 +313,18 @@ int main()
|
||||
{
|
||||
fs::create_symlink("f1", root_dir / "s1");
|
||||
symlinks_supported = true;
|
||||
std::cout <<
|
||||
" *** For information only ***\n"
|
||||
" create_symlink() attempt succeeded" << std::endl;
|
||||
std::cout << " *** For information only ***\n"
|
||||
" create_symlink() attempt succeeded"
|
||||
<< std::endl;
|
||||
}
|
||||
catch (fs::filesystem_error& e)
|
||||
{
|
||||
std::cout <<
|
||||
" *** For information only ***\n"
|
||||
" create_symlink() attempt failed\n"
|
||||
" filesystem_error.what() reports: " << e.what() << "\n"
|
||||
" create_symlink() may not be supported on this operating system or file system" << std::endl;
|
||||
std::cout << " *** For information only ***\n"
|
||||
" create_symlink() attempt failed\n"
|
||||
" filesystem_error.what() reports: "
|
||||
<< e.what() << "\n"
|
||||
" create_symlink() may not be supported on this operating system or file system"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if (symlinks_supported)
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
@ -28,24 +28,23 @@ using boost::filesystem::path;
|
||||
|
||||
#define PATH_CHECK(a, b) check(a, b, __LINE__)
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string platform(BOOST_PLATFORM);
|
||||
namespace {
|
||||
std::string platform(BOOST_PLATFORM);
|
||||
|
||||
void check(const fs::path & source,
|
||||
const std::string & expected, int line)
|
||||
{
|
||||
if (source.generic_string()== expected) return;
|
||||
void check(const fs::path& source, const std::string& expected, int line)
|
||||
{
|
||||
if (source.generic_string() == expected)
|
||||
return;
|
||||
|
||||
++::boost::detail::test_errors();
|
||||
|
||||
std::cout << '(' << line << ") source.string(): \"" << source.string()
|
||||
<< "\" != expected: \"" << expected
|
||||
<< "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void normalize_test()
|
||||
{
|
||||
void normalize_test()
|
||||
{
|
||||
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(), ".");
|
||||
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/..bar").normalize(), "foo/..bar");
|
||||
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("foo/../..").normalize(), "..");
|
||||
PATH_CHECK(path("foo/../../").normalize(), "../.");
|
||||
PATH_CHECK(path("foo/../../..").normalize(), "../..");
|
||||
@ -114,59 +113,59 @@ namespace
|
||||
|
||||
if (platform == "Windows")
|
||||
{
|
||||
PATH_CHECK(path("c:..").normalize(), "c:..");
|
||||
PATH_CHECK(path("c:foo/..").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:/..").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:/");
|
||||
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:/../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
|
||||
{
|
||||
PATH_CHECK(path("c:..").normalize(), "c:..");
|
||||
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:/..").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(), "c:/..foo");
|
||||
PATH_CHECK(path("c:..").normalize(), "c:..");
|
||||
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:/..").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(), "c:/..foo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// misc_test ------------------------------------------------------------------------//
|
||||
// misc_test ------------------------------------------------------------------------//
|
||||
|
||||
void misc_test()
|
||||
{
|
||||
void misc_test()
|
||||
{
|
||||
fs::path p;
|
||||
|
||||
fs::initial_path<fs::path>();
|
||||
fs::initial_path<fs::wpath>();
|
||||
fs::initial_path< fs::path >();
|
||||
fs::initial_path< fs::wpath >();
|
||||
|
||||
p.file_string();
|
||||
p.directory_string();
|
||||
}
|
||||
}
|
||||
|
||||
// path_rename_test -----------------------------------------------------------------//
|
||||
// path_rename_test -----------------------------------------------------------------//
|
||||
|
||||
void path_rename_test()
|
||||
{
|
||||
void path_rename_test()
|
||||
{
|
||||
fs::path p("foo/bar/blah");
|
||||
|
||||
BOOST_TEST_EQ(path("foo/bar/blah").remove_leaf(), "foo/bar");
|
||||
@ -178,74 +177,71 @@ namespace
|
||||
|
||||
if (platform == "Windows")
|
||||
{
|
||||
BOOST_TEST_EQ(path("foo\\bar\\blah").remove_leaf(), "foo\\bar");
|
||||
p = "foo\\bar\\blah";
|
||||
BOOST_TEST_EQ(p.branch_path(), "foo\\bar");
|
||||
BOOST_TEST_EQ(path("foo\\bar\\blah").remove_leaf(), "foo\\bar");
|
||||
p = "foo\\bar\\blah";
|
||||
BOOST_TEST_EQ(p.branch_path(), "foo\\bar");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int /*argc*/, char* /*argv*/[])
|
||||
{
|
||||
// The choice of platform is make 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.
|
||||
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin")
|
||||
? "Windows"
|
||||
: "POSIX";
|
||||
std::cout << "Platform is " << platform << '\n';
|
||||
// The choice of platform is make 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.
|
||||
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "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.string();
|
||||
//de.leaf();
|
||||
//de.string();
|
||||
|
||||
fs::path ng(" no-way, Jose");
|
||||
BOOST_TEST(!fs::is_regular(ng)); // verify deprecated name still works
|
||||
BOOST_TEST(!fs::symbolic_link_exists("nosuchfileordirectory"));
|
||||
fs::path ng(" no-way, Jose");
|
||||
BOOST_TEST(!fs::is_regular(ng)); // verify deprecated name still works
|
||||
BOOST_TEST(!fs::symbolic_link_exists("nosuchfileordirectory"));
|
||||
|
||||
misc_test();
|
||||
path_rename_test();
|
||||
normalize_test();
|
||||
BOOST_TEST(fs::path("foo/bar").generic() == fs::path("foo/bar"));
|
||||
misc_test();
|
||||
path_rename_test();
|
||||
normalize_test();
|
||||
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.txt") == ".txt");
|
||||
BOOST_TEST(fs::extension("a/b.") == ".");
|
||||
BOOST_TEST(fs::extension("a.b.c") == ".c");
|
||||
BOOST_TEST(fs::extension("a.b.c.") == ".");
|
||||
BOOST_TEST(fs::extension("") == "");
|
||||
BOOST_TEST(fs::extension("a/") == "");
|
||||
BOOST_TEST(fs::extension("a/b") == "");
|
||||
BOOST_TEST(fs::extension("a/b.txt") == ".txt");
|
||||
BOOST_TEST(fs::extension("a/b.") == ".");
|
||||
BOOST_TEST(fs::extension("a.b.c") == ".c");
|
||||
BOOST_TEST(fs::extension("a.b.c.") == ".");
|
||||
BOOST_TEST(fs::extension("") == "");
|
||||
BOOST_TEST(fs::extension("a/") == "");
|
||||
|
||||
// basename() tests ----------------------------------------------------------//
|
||||
// basename() tests ----------------------------------------------------------//
|
||||
|
||||
BOOST_TEST(fs::basename("b") == "b");
|
||||
BOOST_TEST(fs::basename("a/b.txt") == "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.c");
|
||||
BOOST_TEST(fs::basename("") == "");
|
||||
BOOST_TEST(fs::basename("b") == "b");
|
||||
BOOST_TEST(fs::basename("a/b.txt") == "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.c");
|
||||
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.", ".tex").string() == "a.tex");
|
||||
BOOST_TEST(fs::change_extension("a", ".txt").string() == "a.txt");
|
||||
BOOST_TEST(fs::change_extension("a.b.txt", ".tex").string() == "a.b.tex");
|
||||
// see the rationale in html docs for explanation why this works
|
||||
BOOST_TEST(fs::change_extension("", ".png").string() == ".png");
|
||||
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", ".txt").string() == "a.txt");
|
||||
BOOST_TEST(fs::change_extension("a.b.txt", ".tex").string() == "a.b.tex");
|
||||
// see the rationale in html docs for explanation why this works
|
||||
BOOST_TEST(fs::change_extension("", ".png").string() == ".png");
|
||||
|
||||
return ::boost::report_errors();
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@ -6,76 +6,76 @@
|
||||
class path
|
||||
{
|
||||
public:
|
||||
path( const char * )
|
||||
{
|
||||
std::cout << "path( const char * )\n";
|
||||
}
|
||||
path( const std::string & )
|
||||
{
|
||||
std::cout << "path( std::string & )\n";
|
||||
}
|
||||
path(const char*)
|
||||
{
|
||||
std::cout << "path( const char * )\n";
|
||||
}
|
||||
path(const std::string&)
|
||||
{
|
||||
std::cout << "path( std::string & )\n";
|
||||
}
|
||||
|
||||
// for maximum efficiency, either signature must work
|
||||
# ifdef BY_VALUE
|
||||
operator const std::string() const
|
||||
# else
|
||||
operator const std::string&() const
|
||||
# endif
|
||||
{
|
||||
std::cout << "operator string\n";
|
||||
return m_path;
|
||||
}
|
||||
#ifdef BY_VALUE
|
||||
operator const std::string() const
|
||||
#else
|
||||
operator const std::string&() const
|
||||
#endif
|
||||
{
|
||||
std::cout << "operator string\n";
|
||||
return m_path;
|
||||
}
|
||||
|
||||
#ifdef NAMED_CONVERSION
|
||||
std::string string() const
|
||||
{
|
||||
std::cout << "std::string string() const\n";
|
||||
return m_path;
|
||||
}
|
||||
std::string string() const
|
||||
{
|
||||
std::cout << "std::string string() const\n";
|
||||
return m_path;
|
||||
}
|
||||
#endif
|
||||
|
||||
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";
|
||||
return true;
|
||||
std::cout << "operator==( const path &, const path & )\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
// These are the critical use cases. If any of these don't compile, usability
|
||||
// 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()
|
||||
{
|
||||
f( "foo" );
|
||||
f( std::string( "foo" ) );
|
||||
f( path( "foo" ) );
|
||||
f("foo");
|
||||
f(std::string("foo"));
|
||||
f(path("foo"));
|
||||
|
||||
std::cout << '\n';
|
||||
std::cout << '\n';
|
||||
|
||||
std::string s1( path( "foo" ) );
|
||||
std::string s2 = path( "foo" );
|
||||
s2 = path( "foo" );
|
||||
std::string s1(path("foo"));
|
||||
std::string s2 = path("foo");
|
||||
s2 = path("foo");
|
||||
|
||||
#ifdef NAMED_CONVERSION
|
||||
s2 = path( "foo" ).string();
|
||||
s2 = path("foo").string();
|
||||
#endif
|
||||
|
||||
std::cout << '\n';
|
||||
std::cout << '\n';
|
||||
|
||||
// these must call bool path( const path &, const path & );
|
||||
path( "foo" ) == path( "foo" );
|
||||
path( "foo" ) == "foo";
|
||||
path( "foo" ) == std::string( "foo" );
|
||||
"foo" == path( "foo" );
|
||||
std::string( "foo" ) == path( "foo" );
|
||||
// these must call bool path( const path &, const path & );
|
||||
path("foo") == path("foo");
|
||||
path("foo") == "foo";
|
||||
path("foo") == std::string("foo");
|
||||
"foo" == path("foo");
|
||||
std::string("foo") == path("foo");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -14,26 +14,26 @@
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
boost::filesystem::path::default_name_check( boost::filesystem::native );
|
||||
if ( argc != 3 )
|
||||
{
|
||||
std::cout << "Usage: equivalent path1 path2\n";
|
||||
return 2;
|
||||
}
|
||||
boost::filesystem::path::default_name_check(boost::filesystem::native);
|
||||
if (argc != 3)
|
||||
{
|
||||
std::cout << "Usage: equivalent path1 path2\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool eq;
|
||||
try
|
||||
{
|
||||
eq = boost::filesystem::equivalent( argv[1], argv[2] );
|
||||
}
|
||||
catch ( const std::exception & ex )
|
||||
{
|
||||
std::cout << ex.what() << "\n";
|
||||
return 3;
|
||||
}
|
||||
bool eq;
|
||||
try
|
||||
{
|
||||
eq = boost::filesystem::equivalent(argv[1], argv[2]);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
std::cout << ex.what() << "\n";
|
||||
return 3;
|
||||
}
|
||||
|
||||
std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n");
|
||||
return !eq;
|
||||
std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n");
|
||||
return !eq;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ int main()
|
||||
{
|
||||
fs::directory_iterator const it;
|
||||
|
||||
BOOST_FOREACH( fs::path const& p, it )
|
||||
BOOST_FOREACH(fs::path const& p, it)
|
||||
{
|
||||
p.string();
|
||||
}
|
||||
@ -30,7 +30,7 @@ int main()
|
||||
{
|
||||
fs::directory_iterator const it;
|
||||
|
||||
for( fs::path const& p: it )
|
||||
for (fs::path const& p : it)
|
||||
{
|
||||
p.string();
|
||||
}
|
||||
@ -41,7 +41,7 @@ int main()
|
||||
{
|
||||
fs::recursive_directory_iterator it;
|
||||
|
||||
BOOST_FOREACH( fs::path const& p, it )
|
||||
BOOST_FOREACH(fs::path const& p, it)
|
||||
{
|
||||
p.string();
|
||||
}
|
||||
@ -52,7 +52,7 @@ int main()
|
||||
{
|
||||
fs::recursive_directory_iterator const it;
|
||||
|
||||
for( fs::path const& p: it )
|
||||
for (fs::path const& p : it)
|
||||
{
|
||||
p.string();
|
||||
}
|
||||
|
@ -11,18 +11,18 @@
|
||||
|
||||
// See deprecated_test for tests of deprecated features
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <string>
|
||||
@ -35,135 +35,136 @@ namespace fs = boost::filesystem;
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std { using ::remove; }
|
||||
namespace std {
|
||||
using ::remove;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool cleanup = true;
|
||||
namespace {
|
||||
bool cleanup = true;
|
||||
|
||||
void test(const fs::path & p)
|
||||
{
|
||||
void test(const fs::path& p)
|
||||
{
|
||||
fs::remove(p);
|
||||
{
|
||||
std::cout << " in test 1\n";
|
||||
fs::filebuf fb1;
|
||||
fb1.open(p, std::ios_base::out);
|
||||
BOOST_TEST(fb1.is_open());
|
||||
std::cout << " in test 1\n";
|
||||
fs::filebuf fb1;
|
||||
fb1.open(p, std::ios_base::out);
|
||||
BOOST_TEST(fb1.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 2\n";
|
||||
fs::filebuf fb2;
|
||||
fb2.open(p, std::ios_base::in);
|
||||
BOOST_TEST(fb2.is_open());
|
||||
std::cout << " in test 2\n";
|
||||
fs::filebuf fb2;
|
||||
fb2.open(p, std::ios_base::in);
|
||||
BOOST_TEST(fb2.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 3\n";
|
||||
fs::ifstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 3\n";
|
||||
fs::ifstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 4\n";
|
||||
fs::ifstream tfs(p / p.filename()); // should fail
|
||||
BOOST_TEST(!tfs.is_open());
|
||||
std::cout << " in test 4\n";
|
||||
fs::ifstream tfs(p / p.filename()); // should fail
|
||||
BOOST_TEST(!tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 5\n";
|
||||
fs::ifstream tfs(p, std::ios_base::in);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 5\n";
|
||||
fs::ifstream tfs(p, std::ios_base::in);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 6\n";
|
||||
fs::ifstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 6\n";
|
||||
fs::ifstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 7\n";
|
||||
fs::ifstream tfs;
|
||||
tfs.open(p, std::ios_base::in);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 7\n";
|
||||
fs::ifstream tfs;
|
||||
tfs.open(p, std::ios_base::in);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 8\n";
|
||||
fs::ofstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 8\n";
|
||||
fs::ofstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 9\n";
|
||||
fs::ofstream tfs(p, std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 9\n";
|
||||
fs::ofstream tfs(p, std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 10\n";
|
||||
fs::ofstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 10\n";
|
||||
fs::ofstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 11\n";
|
||||
fs::ofstream tfs;
|
||||
tfs.open(p, std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 11\n";
|
||||
fs::ofstream tfs;
|
||||
tfs.open(p, std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 12\n";
|
||||
fs::fstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 12\n";
|
||||
fs::fstream tfs(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 13\n";
|
||||
fs::fstream tfs(p, std::ios_base::in|std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 13\n";
|
||||
fs::fstream tfs(p, std::ios_base::in | std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 14\n";
|
||||
fs::fstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 14\n";
|
||||
fs::fstream tfs;
|
||||
tfs.open(p);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
{
|
||||
std::cout << " in test 15\n";
|
||||
fs::fstream tfs;
|
||||
tfs.open(p, std::ios_base::in|std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
std::cout << " in test 15\n";
|
||||
fs::fstream tfs;
|
||||
tfs.open(p, std::ios_base::in | std::ios_base::out);
|
||||
BOOST_TEST(tfs.is_open());
|
||||
}
|
||||
|
||||
if (cleanup)
|
||||
fs::remove(p);
|
||||
fs::remove(p);
|
||||
|
||||
} // test
|
||||
} // test
|
||||
} // unnamed namespace
|
||||
|
||||
int cpp_main(int argc, char*[])
|
||||
{
|
||||
if (argc > 1) cleanup = false;
|
||||
if (argc > 1)
|
||||
cleanup = false;
|
||||
|
||||
std::cout << "BOOST_FILESYSTEM_C_STR defined as \""
|
||||
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n";
|
||||
std::cout << "BOOST_FILESYSTEM_C_STR defined as \""
|
||||
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n";
|
||||
|
||||
// test narrow characters
|
||||
std::cout << "narrow character tests:\n";
|
||||
test("narrow_fstream_test");
|
||||
// test narrow characters
|
||||
std::cout << "narrow character tests:\n";
|
||||
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
|
||||
std::locale global_loc = std::locale();
|
||||
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);
|
||||
fs::path::imbue(loc);
|
||||
// test with some wide characters
|
||||
// \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);
|
||||
|
||||
// test with some wide characters
|
||||
// \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();
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@ -5,4 +5,3 @@ int main(void)
|
||||
boost::filesystem::copy_file("a", "b");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::filesystem::path dir("/");
|
||||
for (char c : dir.filename().string())
|
||||
printf("%c\n", c);
|
||||
boost::filesystem::path dir("/");
|
||||
for (char c : dir.filename().string())
|
||||
printf("%c\n", c);
|
||||
}
|
||||
|
@ -5,16 +5,18 @@ namespace fs = boost::filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
fs::path my_path("test/test.txt");
|
||||
cout << "current path is " << my_path << endl;
|
||||
cout << "parent path is " << my_path.parent_path() << endl;
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
cerr << endl << "Error during execution: " << e.what() << endl << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
try
|
||||
{
|
||||
fs::path my_path("test/test.txt");
|
||||
cout << "current path is " << my_path << endl;
|
||||
cout << "parent path is " << my_path.parent_path() << endl;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
cerr << endl
|
||||
<< "Error during execution: " << e.what() << endl
|
||||
<< endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ boost::mutex mut;
|
||||
#define FNAME ("remove-test")
|
||||
void remover()
|
||||
{
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
boost::filesystem::remove(FNAME);
|
||||
}
|
||||
@ -16,7 +16,8 @@ void remover()
|
||||
|
||||
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()
|
||||
@ -24,15 +25,16 @@ int main()
|
||||
boost::filesystem::remove(FNAME);
|
||||
boost::filesystem::remove(FNAME);
|
||||
|
||||
std::cout <<
|
||||
"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"
|
||||
"This is likely to crash after just a few seconds at most." <<
|
||||
std::endl;
|
||||
std::cout << "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"
|
||||
"This is likely to crash after just a few seconds at most."
|
||||
<< std::endl;
|
||||
|
||||
boost::thread c(creater), r1(remover), r2(remover);
|
||||
|
||||
c.join();
|
||||
r1.interrupt(); r1.join();
|
||||
r2.interrupt(); r2.join();
|
||||
r1.interrupt();
|
||||
r1.join();
|
||||
r2.interrupt();
|
||||
r2.join();
|
||||
}
|
||||
|
@ -8,18 +8,17 @@
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
fs::recursive_directory_iterator beg("."), end;
|
||||
|
||||
auto fileFilter = [](fs::path const & path)
|
||||
{
|
||||
return is_regular_file(path);
|
||||
auto fileFilter = [](fs::path const& path) {
|
||||
return is_regular_file(path);
|
||||
};
|
||||
|
||||
std::vector<fs::path> paths;
|
||||
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter),
|
||||
std::back_inserter(paths));
|
||||
std::vector< fs::path > paths;
|
||||
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), std::back_inserter(paths));
|
||||
|
||||
for(auto& p : paths)
|
||||
for (auto& p : paths)
|
||||
std::cout << p << "\n";
|
||||
}
|
@ -6,32 +6,32 @@
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
|
||||
std::locale global_loc = std::locale();
|
||||
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950<wchar_t>);
|
||||
fs::path::imbue(loc);
|
||||
std::locale global_loc = std::locale();
|
||||
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950< wchar_t >);
|
||||
fs::path::imbue(loc);
|
||||
|
||||
std::cout <<
|
||||
"HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
|
||||
"WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n"
|
||||
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW." << std::endl;
|
||||
std::cout << "HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
|
||||
"WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n"
|
||||
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW."
|
||||
<< std::endl;
|
||||
|
||||
fs::recursive_directory_iterator end;
|
||||
fs::recursive_directory_iterator iter
|
||||
("C:/boost/test-files/utf-8");
|
||||
fs::recursive_directory_iterator end;
|
||||
fs::recursive_directory_iterator iter("C:/boost/test-files/utf-8");
|
||||
|
||||
while (iter != end)
|
||||
{
|
||||
if (fs::is_directory(*iter))
|
||||
while (iter != end)
|
||||
{
|
||||
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))
|
||||
{
|
||||
std::cout << " [file] " << iter->path().generic_string() << std::endl;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,17 +4,15 @@ using boost::filesystem::path;
|
||||
|
||||
int main()
|
||||
{
|
||||
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/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/e").stem() << std::endl;
|
||||
std::cout << path("a/b/c/d/e/").stem() << std::endl;
|
||||
return 0;
|
||||
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/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/e").stem() << std::endl;
|
||||
std::cout << path("a/b/c/d/e/").stem() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,11 +14,11 @@ using namespace boost::filesystem;
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
~Test()
|
||||
{
|
||||
path p(L"C:\\TEMP\\");
|
||||
path r(p / "narrow");
|
||||
}
|
||||
~Test()
|
||||
{
|
||||
path p(L"C:\\TEMP\\");
|
||||
path r(p / "narrow");
|
||||
}
|
||||
};
|
||||
|
||||
// path p("narrow");
|
||||
@ -30,7 +30,7 @@ public:
|
||||
Test test1;
|
||||
Test test2;
|
||||
|
||||
int cpp_main(int, char* [])
|
||||
int cpp_main(int, char*[])
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ namespace fs = boost::filesystem;
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Before running this test: export LANG=foo
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
int main() {
|
||||
boost::filesystem::path("/abc").root_directory();
|
||||
int main()
|
||||
{
|
||||
boost::filesystem::path("/abc").root_directory();
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
static const boost::filesystem::path::codecvt_type &dummy =
|
||||
boost::filesystem::path::codecvt();
|
||||
static const boost::filesystem::path::codecvt_type& dummy =
|
||||
boost::filesystem::path::codecvt();
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,10 @@ namespace fs = boost::filesystem;
|
||||
|
||||
int cpp_main(int argc, char* argv[])
|
||||
{
|
||||
cout << "Hello, 9219" << endl;
|
||||
cout << "This is a test for non-Windows systems" << endl;
|
||||
cout << "Hello, 9219" << 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
|
||||
|
@ -21,16 +21,17 @@ namespace fs = boost::filesystem;
|
||||
|
||||
struct TmpDir
|
||||
{
|
||||
fs::path path;
|
||||
TmpDir(const fs::path& base): path(fs::absolute(base) / fs::unique_path())
|
||||
{
|
||||
fs::create_directories(path);
|
||||
}
|
||||
~TmpDir()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
fs::remove_all(path, ec);
|
||||
}
|
||||
fs::path path;
|
||||
TmpDir(const fs::path& base) :
|
||||
path(fs::absolute(base) / fs::unique_path())
|
||||
{
|
||||
fs::create_directories(path);
|
||||
}
|
||||
~TmpDir()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
fs::remove_all(path, ec);
|
||||
}
|
||||
};
|
||||
|
||||
// Test fs::canonical for various path in a Windows directory junction point
|
||||
@ -38,48 +39,47 @@ struct TmpDir
|
||||
int main()
|
||||
{
|
||||
|
||||
const fs::path cwd = fs::current_path();
|
||||
const TmpDir tmp(cwd);
|
||||
const fs::path junction = tmp.path / "junction";
|
||||
const fs::path real = tmp.path / "real";
|
||||
const fs::path subDir = "sub";
|
||||
fs::create_directories(real / subDir);
|
||||
fs::current_path(tmp.path);
|
||||
BOOST_TEST(std::system("mklink /j junction real") == 0);
|
||||
BOOST_TEST(fs::exists(junction));
|
||||
const fs::path cwd = fs::current_path();
|
||||
const TmpDir tmp(cwd);
|
||||
const fs::path junction = tmp.path / "junction";
|
||||
const fs::path real = tmp.path / "real";
|
||||
const fs::path subDir = "sub";
|
||||
fs::create_directories(real / subDir);
|
||||
fs::current_path(tmp.path);
|
||||
BOOST_TEST(std::system("mklink /j junction real") == 0);
|
||||
BOOST_TEST(fs::exists(junction));
|
||||
|
||||
// Due to a bug there was a dependency on the current path so try the below for all:
|
||||
std::vector<fs::path> paths;
|
||||
paths.push_back(cwd);
|
||||
paths.push_back(junction);
|
||||
paths.push_back(real);
|
||||
paths.push_back(junction / subDir);
|
||||
paths.push_back(real / subDir);
|
||||
for (std::vector<fs::path>::iterator it = paths.begin(); it != paths.end(); ++it)
|
||||
{
|
||||
std::cout << "Testing in " << *it << std::endl;
|
||||
fs::current_path(*it);
|
||||
// Due to a bug there was a dependency on the current path so try the below for all:
|
||||
std::vector< fs::path > paths;
|
||||
paths.push_back(cwd);
|
||||
paths.push_back(junction);
|
||||
paths.push_back(real);
|
||||
paths.push_back(junction / subDir);
|
||||
paths.push_back(real / subDir);
|
||||
for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it)
|
||||
{
|
||||
std::cout << "Testing in " << *it << std::endl;
|
||||
fs::current_path(*it);
|
||||
|
||||
// Used by canonical, must work too
|
||||
BOOST_TEST(fs::read_symlink(junction) == real);
|
||||
// Used by canonical, must work too
|
||||
BOOST_TEST(fs::read_symlink(junction) == real);
|
||||
|
||||
BOOST_TEST(fs::canonical(junction) == real);
|
||||
BOOST_TEST(fs::canonical(junction / subDir) == real / subDir);
|
||||
}
|
||||
BOOST_TEST(fs::canonical(junction) == real);
|
||||
BOOST_TEST(fs::canonical(junction / subDir) == real / subDir);
|
||||
}
|
||||
|
||||
// Restore the original current directory so that temp directory can be removed
|
||||
fs::current_path(cwd);
|
||||
// Restore the original current directory so that temp directory can be removed
|
||||
fs::current_path(cwd);
|
||||
|
||||
return boost::report_errors();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
|
||||
return 0;
|
||||
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)
|
||||
|
||||
|
@ -5,10 +5,10 @@
|
||||
|
||||
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"),opt);
|
||||
copy_file(path("p1"), path("p2"), copy_options::overwrite_existing);
|
||||
// copy_file(path("p1"),path("p2"),opt);
|
||||
}
|
@ -19,12 +19,15 @@
|
||||
#include <cerrno>
|
||||
|
||||
#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
|
||||
|
||||
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"));
|
||||
|
||||
|
@ -31,9 +31,9 @@ namespace fs = boost::filesystem;
|
||||
|
||||
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
|
||||
|
@ -11,18 +11,18 @@
|
||||
|
||||
// See deprecated_test for tests of deprecated features
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/cerrno.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
@ -39,16 +39,15 @@ using std::cout;
|
||||
using std::endl;
|
||||
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
# include <windows.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
namespace
|
||||
{
|
||||
typedef int errno_t;
|
||||
std::string platform(BOOST_PLATFORM);
|
||||
bool report_throws = false;
|
||||
bool cleanup = true;
|
||||
bool skip_long_windows_tests = false;
|
||||
unsigned short language_id; // 0 except for Windows
|
||||
namespace {
|
||||
typedef int errno_t;
|
||||
std::string platform(BOOST_PLATFORM);
|
||||
bool report_throws = false;
|
||||
bool cleanup = true;
|
||||
bool skip_long_windows_tests = false;
|
||||
unsigned short language_id; // 0 except for Windows
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
@ -60,73 +59,73 @@ namespace
|
||||
|
||||
int cpp_main(int argc, char* argv[])
|
||||
{
|
||||
// document state of critical macros
|
||||
// document state of critical macros
|
||||
#ifdef BOOST_POSIX_API
|
||||
cout << "BOOST_POSIX_API is defined\n";
|
||||
cout << "BOOST_POSIX_API is defined\n";
|
||||
#endif
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
cout << "BOOST_WINDOWS_API is defined\n";
|
||||
cout << "BOOST_WINDOWS_API is defined\n";
|
||||
#endif
|
||||
|
||||
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)
|
||||
for (; argc > 1; --argc, ++argv)
|
||||
{
|
||||
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;
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "returning from main()" << endl;
|
||||
return ::boost::report_errors();
|
||||
// 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;
|
||||
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
|
||||
|
@ -16,140 +16,141 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
# include <windows.h>
|
||||
# include <winnt.h>
|
||||
#include <windows.h>
|
||||
#include <winnt.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma comment(lib, "Advapi32.lib")
|
||||
#pragma comment(lib, "Advapi32.lib")
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
#if !defined(__MINGW32__) || defined(__MINGW64__)
|
||||
typedef struct _REPARSE_DATA_BUFFER {
|
||||
ULONG ReparseTag;
|
||||
USHORT ReparseDataLength;
|
||||
USHORT Reserved;
|
||||
union {
|
||||
struct {
|
||||
USHORT SubstituteNameOffset;
|
||||
USHORT SubstituteNameLength;
|
||||
USHORT PrintNameOffset;
|
||||
USHORT PrintNameLength;
|
||||
ULONG Flags;
|
||||
WCHAR PathBuffer[1];
|
||||
} SymbolicLinkReparseBuffer;
|
||||
struct {
|
||||
USHORT SubstituteNameOffset;
|
||||
USHORT SubstituteNameLength;
|
||||
USHORT PrintNameOffset;
|
||||
USHORT PrintNameLength;
|
||||
WCHAR PathBuffer[1];
|
||||
} MountPointReparseBuffer;
|
||||
struct {
|
||||
UCHAR DataBuffer[1];
|
||||
} GenericReparseBuffer;
|
||||
};
|
||||
typedef struct _REPARSE_DATA_BUFFER
|
||||
{
|
||||
ULONG ReparseTag;
|
||||
USHORT ReparseDataLength;
|
||||
USHORT Reserved;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
USHORT SubstituteNameOffset;
|
||||
USHORT SubstituteNameLength;
|
||||
USHORT PrintNameOffset;
|
||||
USHORT PrintNameLength;
|
||||
ULONG Flags;
|
||||
WCHAR PathBuffer[1];
|
||||
} SymbolicLinkReparseBuffer;
|
||||
struct
|
||||
{
|
||||
USHORT SubstituteNameOffset;
|
||||
USHORT SubstituteNameLength;
|
||||
USHORT PrintNameOffset;
|
||||
USHORT PrintNameLength;
|
||||
WCHAR PathBuffer[1];
|
||||
} MountPointReparseBuffer;
|
||||
struct
|
||||
{
|
||||
UCHAR DataBuffer[1];
|
||||
} GenericReparseBuffer;
|
||||
};
|
||||
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
|
||||
#endif
|
||||
|
||||
#ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER
|
||||
# define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
|
||||
#define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
|
||||
#endif
|
||||
|
||||
#ifndef FSCTL_SET_REPARSE_POINT
|
||||
# define FSCTL_SET_REPARSE_POINT (0x000900a4)
|
||||
#define FSCTL_SET_REPARSE_POINT (0x000900a4)
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
bool obtain_restore_privilege()
|
||||
{
|
||||
HANDLE hToken;
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
||||
{
|
||||
std::cout << "OpenProcessToken() failed with: " << GetLastError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
HANDLE hToken;
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
||||
{
|
||||
std::cout << "OpenProcessToken() failed with: " << GetLastError() << std::endl;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
CloseHandle(hToken);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool create_io_reparse_file_placeholder(const wchar_t* name)
|
||||
{
|
||||
if (!obtain_restore_privilege())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!obtain_restore_privilege())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
|
||||
FILE_FLAG_OPEN_REPARSE_POINT, 0);
|
||||
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0);
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
std::cout << "CreateFile() failed with: " << GetLastError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
std::cout << "CreateFile() failed with: " << GetLastError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
|
||||
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
|
||||
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
|
||||
|
||||
DWORD dwLen;
|
||||
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse,
|
||||
pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE,
|
||||
NULL, 0, &dwLen, NULL) != 0;
|
||||
DWORD dwLen;
|
||||
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, NULL, 0, &dwLen, NULL) != 0;
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
std::cout << "DeviceIoControl() failed with: " << GetLastError() << std::endl;
|
||||
}
|
||||
if (!ret)
|
||||
{
|
||||
std::cout << "DeviceIoControl() failed with: " << GetLastError() << std::endl;
|
||||
}
|
||||
|
||||
CloseHandle(hHandle);
|
||||
GlobalFree(pReparse);
|
||||
return ret;
|
||||
CloseHandle(hHandle);
|
||||
GlobalFree(pReparse);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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(boost::filesystem::status(rpt).type() == boost::filesystem::reparse_file);
|
||||
BOOST_TEST(boost::filesystem::remove(rpt));
|
||||
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::remove(rpt));
|
||||
|
||||
return boost::report_errors();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
|
||||
return 0;
|
||||
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
@ -24,19 +24,19 @@ namespace fs = boost::filesystem;
|
||||
|
||||
int main()
|
||||
{
|
||||
if ( fs::detail::possible_large_file_size_support() )
|
||||
{
|
||||
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"
|
||||
"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";
|
||||
return 0;
|
||||
}
|
||||
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"
|
||||
"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"
|
||||
"support large files, please report the problem to the Boost developers\n"
|
||||
"mailing list.\n";
|
||||
return 1;
|
||||
if (fs::detail::possible_large_file_size_support())
|
||||
{
|
||||
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"
|
||||
"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";
|
||||
return 0;
|
||||
}
|
||||
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"
|
||||
"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"
|
||||
"support large files, please report the problem to the Boost developers\n"
|
||||
"mailing list.\n";
|
||||
return 1;
|
||||
}
|
||||
|
@ -12,77 +12,74 @@
|
||||
using namespace std;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996) // ... Function call with parameters that may be unsafe
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe
|
||||
#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> >("
|
||||
<< msg << ") is "
|
||||
<< (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)
|
||||
? "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;
|
||||
}
|
||||
}
|
||||
<< msg << ") is "
|
||||
<< (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "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;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
const char* lang = getenv("LANG");
|
||||
cout << "\nLANG environmental variable is "
|
||||
<< (lang ? lang : "not present") << endl;
|
||||
const char* lang = getenv("LANG");
|
||||
cout << "\nLANG environmental variable is "
|
||||
<< (lang ? lang : "not present") << endl;
|
||||
|
||||
default_info();
|
||||
null_string_info();
|
||||
classic_info();
|
||||
default_info();
|
||||
null_string_info();
|
||||
classic_info();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
@ -20,40 +20,38 @@ using namespace boost::filesystem;
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
} // unnamed namespace
|
||||
namespace {
|
||||
} // unnamed namespace
|
||||
|
||||
int cpp_main(int, char*[])
|
||||
{
|
||||
|
||||
std::string prefix("d:\\temp\\");
|
||||
std::cout << "prefix is " << prefix << '\n';
|
||||
std::string prefix("d:\\temp\\");
|
||||
std::cout << "prefix is " << prefix << '\n';
|
||||
|
||||
const std::size_t safe_size
|
||||
= 260 - prefix.size() - 100; // Windows MAX_PATH is 260
|
||||
const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260
|
||||
|
||||
std::string safe_x_string(safe_size, 'x');
|
||||
std::string safe_y_string(safe_size, 'y');
|
||||
std::string path_escape("\\\\?\\");
|
||||
std::string safe_x_string(safe_size, 'x');
|
||||
std::string safe_y_string(safe_size, 'y');
|
||||
std::string path_escape("\\\\?\\");
|
||||
|
||||
path x_p(prefix + safe_x_string);
|
||||
path y_p(path_escape + prefix + safe_x_string + "\\" + safe_y_string);
|
||||
path x_p(prefix + safe_x_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 << "y_p.native().size() is " << y_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';
|
||||
|
||||
create_directory(x_p);
|
||||
BOOST_TEST(exists(x_p));
|
||||
create_directory(y_p);
|
||||
BOOST_TEST(exists(y_p));
|
||||
create_directory(x_p);
|
||||
BOOST_TEST(exists(x_p));
|
||||
create_directory(y_p);
|
||||
BOOST_TEST(exists(y_p));
|
||||
|
||||
//std::cout << "directory x.../y... ready for testing, where ... is " << safe_size
|
||||
// << " repeats of x and y, respectively\n";
|
||||
//std::cout << "directory x.../y... ready for testing, where ... is " << safe_size
|
||||
// << " 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();
|
||||
}
|
||||
|
@ -15,22 +15,21 @@
|
||||
#undef BOOST_SYSTEM_STATIC_LINK
|
||||
|
||||
#ifndef BOOST_ALL_NO_LIB
|
||||
# define BOOST_ALL_NO_LIB
|
||||
#define BOOST_ALL_NO_LIB
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/system/config.hpp>
|
||||
|
||||
#ifndef BOOST_FILESYSTEM_STATIC_LINK
|
||||
# error BOOST_FILESYSTEM_STATIC_LINK not set by default
|
||||
#error BOOST_FILESYSTEM_STATIC_LINK not set by default
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_SYSTEM_STATIC_LINK
|
||||
# error BOOST_SYSTEM_STATIC_LINK not set by default
|
||||
#error BOOST_SYSTEM_STATIC_LINK not set by default
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,16 +9,14 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
void tu2();
|
||||
}
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
void tu2();
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::filesystem::tu2();
|
||||
return 0;
|
||||
boost::filesystem::tu2();
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,10 +9,12 @@
|
||||
|
||||
#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
@ -13,23 +13,22 @@
|
||||
|
||||
// ------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
|
||||
// See deprecated_test for tests of deprecated features
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem.hpp> // make sure filesystem.hpp works
|
||||
#include <boost/filesystem.hpp> // make sure filesystem.hpp works
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
@ -44,47 +43,47 @@ using std::string;
|
||||
|
||||
#define CHECK(x) check(x, __FILE__, __LINE__)
|
||||
|
||||
namespace
|
||||
{
|
||||
bool cleanup = true;
|
||||
namespace {
|
||||
bool cleanup = true;
|
||||
|
||||
void check(bool ok, const char* file, int line)
|
||||
{
|
||||
if (ok) return;
|
||||
void check(bool ok, const char* file, int line)
|
||||
{
|
||||
if (ok)
|
||||
return;
|
||||
|
||||
++::boost::detail::test_errors();
|
||||
|
||||
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;
|
||||
|
||||
file_status s = status(".");
|
||||
int v = s.permissions();
|
||||
cout << " status(\".\") permissions are "
|
||||
<< std::oct << (v & 0777) << std::dec << endl;
|
||||
<< std::oct << (v & 0777) << std::dec << endl;
|
||||
CHECK((v & 0400) == 0400);
|
||||
|
||||
s = symlink_status(".");
|
||||
v = s.permissions();
|
||||
cout << " symlink_status(\".\") permissions are "
|
||||
<< std::oct << (v & 0777) << std::dec << endl;
|
||||
<< std::oct << (v & 0777) << std::dec << endl;
|
||||
CHECK((v & 0400) == 0400);
|
||||
}
|
||||
}
|
||||
|
||||
// query_test ----------------------------------------------------------------------//
|
||||
// query_test ----------------------------------------------------------------------//
|
||||
|
||||
void query_test()
|
||||
{
|
||||
void query_test()
|
||||
{
|
||||
cout << "query test..." << endl;
|
||||
|
||||
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(status("no-such-file") == file_status(file_not_found, no_perms));
|
||||
@ -96,8 +95,8 @@ namespace
|
||||
exists("/", ec);
|
||||
if (ec)
|
||||
{
|
||||
cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl;
|
||||
cout << "ec value: " << ec.value() << ", message: "<< ec.message() << endl;
|
||||
cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl;
|
||||
cout << "ec value: " << ec.value() << ", message: " << ec.message() << endl;
|
||||
}
|
||||
CHECK(!ec);
|
||||
|
||||
@ -106,12 +105,12 @@ namespace
|
||||
CHECK(!is_regular_file("/"));
|
||||
CHECK(!boost::filesystem::is_empty("/"));
|
||||
CHECK(!is_other("/"));
|
||||
}
|
||||
}
|
||||
|
||||
// directory_iterator_test -----------------------------------------------//
|
||||
// directory_iterator_test -----------------------------------------------//
|
||||
|
||||
void directory_iterator_test()
|
||||
{
|
||||
void directory_iterator_test()
|
||||
{
|
||||
cout << "directory_iterator_test..." << endl;
|
||||
|
||||
directory_iterator end;
|
||||
@ -122,25 +121,25 @@ namespace
|
||||
|
||||
if (is_regular_file(it->status()))
|
||||
{
|
||||
CHECK(is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_directory(it->status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_directory(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
CHECK(is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_directory(it->status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_directory(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK(is_directory(it->status()));
|
||||
CHECK(is_directory(it->symlink_status()));
|
||||
CHECK(!is_regular_file(it->status()));
|
||||
CHECK(!is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
CHECK(is_directory(it->status()));
|
||||
CHECK(is_directory(it->symlink_status()));
|
||||
CHECK(!is_regular_file(it->status()));
|
||||
CHECK(!is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
}
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
//cout << " " << it->path() << "\n";
|
||||
//cout << " " << it->path() << "\n";
|
||||
}
|
||||
|
||||
CHECK(directory_iterator(".") != directory_iterator());
|
||||
@ -149,30 +148,30 @@ namespace
|
||||
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
|
||||
for (directory_entry& x : directory_iterator("."))
|
||||
{
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
}
|
||||
const directory_iterator dir_itr(".");
|
||||
for (directory_entry& x : dir_itr)
|
||||
{
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
for (directory_iterator itr("."); itr != directory_iterator(); ++itr)
|
||||
{
|
||||
CHECK(!itr->path().empty());
|
||||
//cout << " " << itr->path() << "\n";
|
||||
CHECK(!itr->path().empty());
|
||||
//cout << " " << itr->path() << "\n";
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
recursive_directory_iterator end;
|
||||
@ -183,25 +182,25 @@ namespace
|
||||
|
||||
if (is_regular_file(it->status()))
|
||||
{
|
||||
CHECK(is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_directory(it->status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_directory(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
CHECK(is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_directory(it->status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_directory(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK(is_directory(it->status()));
|
||||
CHECK(is_directory(it->symlink_status()));
|
||||
CHECK(!is_regular_file(it->status()));
|
||||
CHECK(!is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
CHECK(is_directory(it->status()));
|
||||
CHECK(is_directory(it->symlink_status()));
|
||||
CHECK(!is_regular_file(it->status()));
|
||||
CHECK(!is_regular_file(it->symlink_status()));
|
||||
CHECK(!is_symlink(it->status()));
|
||||
CHECK(!is_symlink(it->symlink_status()));
|
||||
}
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
//cout << " " << it->path() << "\n";
|
||||
//cout << " " << it->path() << "\n";
|
||||
}
|
||||
|
||||
CHECK(recursive_directory_iterator(".") != recursive_directory_iterator());
|
||||
@ -210,31 +209,31 @@ namespace
|
||||
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
|
||||
for (directory_entry& x : recursive_directory_iterator("."))
|
||||
{
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
}
|
||||
const recursive_directory_iterator dir_itr(".");
|
||||
for (directory_entry& x : dir_itr)
|
||||
{
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
CHECK(!x.path().empty());
|
||||
//cout << " " << x.path() << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
for (recursive_directory_iterator itr(".");
|
||||
itr != recursive_directory_iterator(); ++itr)
|
||||
itr != recursive_directory_iterator(); ++itr)
|
||||
{
|
||||
CHECK(!itr->path().empty());
|
||||
//cout << " " << itr->path() << "\n";
|
||||
CHECK(!itr->path().empty());
|
||||
//cout << " " << itr->path() << "\n";
|
||||
}
|
||||
|
||||
cout << "recursive_directory_iterator_test complete" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// operations_test -------------------------------------------------------//
|
||||
// operations_test -------------------------------------------------------//
|
||||
|
||||
void operations_test()
|
||||
{
|
||||
void operations_test()
|
||||
{
|
||||
cout << "operations test..." << endl;
|
||||
|
||||
error_code ec;
|
||||
@ -254,16 +253,15 @@ namespace
|
||||
std::time_t ft = last_write_time(".");
|
||||
ft = -1;
|
||||
last_write_time(".", ft, ec);
|
||||
}
|
||||
}
|
||||
|
||||
// directory_entry_test ------------------------------------------------------------//
|
||||
// directory_entry_test ------------------------------------------------------------//
|
||||
|
||||
void directory_entry_test()
|
||||
{
|
||||
void directory_entry_test()
|
||||
{
|
||||
cout << "directory_entry test..." << endl;
|
||||
|
||||
directory_entry de("foo.bar",
|
||||
file_status(regular_file, owner_all), file_status(directory_file, group_all));
|
||||
directory_entry de("foo.bar", file_status(regular_file, owner_all), file_status(directory_file, group_all));
|
||||
|
||||
CHECK(de.path() == "foo.bar");
|
||||
CHECK(de.status() == file_status(regular_file, owner_all));
|
||||
@ -273,50 +271,51 @@ namespace
|
||||
CHECK(de != directory_entry("goo.bar"));
|
||||
de.replace_filename("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;
|
||||
|
||||
directory_iterator it(".");
|
||||
path p(*it);
|
||||
}
|
||||
}
|
||||
|
||||
// error_handling_test -------------------------------------------------------------//
|
||||
// error_handling_test -------------------------------------------------------------//
|
||||
|
||||
void error_handling_test()
|
||||
{
|
||||
void error_handling_test()
|
||||
{
|
||||
cout << "error handling test..." << endl;
|
||||
|
||||
bool threw(false);
|
||||
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;
|
||||
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
|
||||
"what() returns " << ex.what() << "\n";
|
||||
threw = true;
|
||||
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
|
||||
"what() returns "
|
||||
<< ex.what() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cout << "\nunexpected exception type caught" << endl;
|
||||
cout << "\nunexpected exception type caught" << endl;
|
||||
}
|
||||
|
||||
CHECK(threw);
|
||||
|
||||
error_code 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;
|
||||
std::string contents("0123456789");
|
||||
path p(temp_dir / "string_file");
|
||||
@ -326,9 +325,9 @@ namespace
|
||||
std::string round_trip;
|
||||
load_string_file(p, 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
|
||||
#ifdef BOOST_POSIX_API
|
||||
cout << "BOOST_POSIX_API is defined\n";
|
||||
cout << "BOOST_POSIX_API is defined\n";
|
||||
#endif
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
cout << "BOOST_WINDOWS_API is defined\n";
|
||||
cout << "BOOST_WINDOWS_API is defined\n";
|
||||
#endif
|
||||
cout << "BOOST_FILESYSTEM_DECL" << BOOST_STRINGIZE(=BOOST_FILESYSTEM_DECL) << "\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 << "BOOST_FILESYSTEM_DECL" << BOOST_STRINGIZE(=BOOST_FILESYSTEM_DECL) << "\n";
|
||||
cout << "BOOST_SYMBOL_VISIBLE" << BOOST_STRINGIZE(=BOOST_SYMBOL_VISIBLE) << "\n";
|
||||
|
||||
cout << "current_path() is " << current_path().string() << endl;
|
||||
}
|
||||
|
||||
const path temp_dir(current_path() / ".." / unique_path("op-unit_test-%%%%-%%%%-%%%%"));
|
||||
cout << "temp_dir is " << temp_dir.string() << endl;
|
||||
if (argc >= 2)
|
||||
{
|
||||
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();
|
||||
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);
|
||||
if (ec)
|
||||
{
|
||||
cout << "current_path('" << argv[1] << "') failed: " << ec << ": " << ec.message() << endl;
|
||||
}
|
||||
|
||||
cout << unique_path() << endl;
|
||||
cout << unique_path("foo-%%%%%-%%%%%-bar") << endl;
|
||||
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%-bar") << endl;
|
||||
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-bar") << endl;
|
||||
cout << "current_path() is " << current_path().string() << 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
|
||||
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
|
||||
}
|
||||
create_directory(temp_dir);
|
||||
|
||||
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();
|
||||
}
|
||||
|
1478
test/path_test.cpp
1478
test/path_test.cpp
File diff suppressed because it is too large
Load Diff
@ -10,10 +10,10 @@
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
|
||||
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
# define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
#ifndef BOOST_SYSTEM_NO_DEPRECATED
|
||||
# define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include <boost/timer/timer.hpp>
|
||||
@ -21,9 +21,9 @@
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
# if defined( BOOST_NO_STD_WSTRING )
|
||||
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
# endif
|
||||
#if defined(BOOST_NO_STD_WSTRING)
|
||||
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
|
||||
#endif
|
||||
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
|
||||
@ -36,38 +36,37 @@ using namespace boost::timer;
|
||||
using std::cout;
|
||||
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::int64_t count = 0;
|
||||
do
|
||||
{
|
||||
fs::path p(s);
|
||||
++count;
|
||||
fs::path p(s);
|
||||
++count;
|
||||
} while (count < max_cycles);
|
||||
|
||||
boost::timer::cpu_times elapsed = tmr.elapsed();
|
||||
return elapsed.user + elapsed.system;
|
||||
}
|
||||
}
|
||||
|
||||
nanosecond_type time_loop()
|
||||
{
|
||||
nanosecond_type time_loop()
|
||||
{
|
||||
boost::timer::auto_cpu_timer tmr;
|
||||
boost::int64_t count = 0;
|
||||
do
|
||||
{
|
||||
++count;
|
||||
++count;
|
||||
} while (count < max_cycles);
|
||||
|
||||
boost::timer::cpu_times elapsed = tmr.elapsed();
|
||||
return elapsed.user + elapsed.system;
|
||||
}
|
||||
} // unnamed namespace
|
||||
}
|
||||
} // unnamed namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// main //
|
||||
@ -75,29 +74,29 @@ namespace
|
||||
|
||||
int cpp_main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
cout << "Usage: path_times <cycles-in-millions>\n";
|
||||
return 1;
|
||||
}
|
||||
if (argc != 2)
|
||||
{
|
||||
cout << "Usage: path_times <cycles-in-millions>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
max_cycles = std::atoi(argv[1]) * 1000000LL;
|
||||
cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
|
||||
max_cycles = std::atoi(argv[1]) * 1000000LL;
|
||||
cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
|
||||
|
||||
cout << "time_loop" << endl;
|
||||
nanosecond_type x = time_loop();
|
||||
cout << "time_loop" << endl;
|
||||
nanosecond_type x = time_loop();
|
||||
|
||||
cout << "time_ctor with string" << endl;
|
||||
nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
|
||||
cout << "time_ctor with string" << endl;
|
||||
nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
|
||||
|
||||
cout << "time_ctor with wstring" << endl;
|
||||
nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
|
||||
cout << "time_ctor with wstring" << endl;
|
||||
nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
|
||||
|
||||
if (s > w)
|
||||
cout << "narrow/wide CPU-time ratio = " << long double(s)/w << endl;
|
||||
else
|
||||
cout << "wide/narrow CPU-time ratio = " << long double(w)/s << endl;
|
||||
if (s > w)
|
||||
cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
|
||||
else
|
||||
cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;
|
||||
|
||||
cout << "returning from main()" << endl;
|
||||
return 0;
|
||||
cout << "returning from main()" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,10 +15,10 @@ namespace fs = boost::filesystem;
|
||||
|
||||
int main()
|
||||
{
|
||||
fs::path p1( "a" );
|
||||
fs::path p1("a");
|
||||
fs::path p2 = p1 / "b";
|
||||
|
||||
BOOST_TEST_EQ( p2, "a/b" );
|
||||
BOOST_TEST_EQ(p2, "a/b");
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ using boost::filesystem::path;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
|
||||
void lexically_relative_test()
|
||||
{
|
||||
void lexically_relative_test()
|
||||
{
|
||||
cout << "lexically_relative_test..." << endl;
|
||||
|
||||
BOOST_TEST(path("").lexically_relative("") == "");
|
||||
@ -76,24 +76,25 @@ namespace
|
||||
// Some tests from Jamie Allsop's paper
|
||||
BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d");
|
||||
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");
|
||||
#else
|
||||
#else
|
||||
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "");
|
||||
#endif
|
||||
#endif
|
||||
BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == "");
|
||||
|
||||
// From issue #1976
|
||||
BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new");
|
||||
}
|
||||
}
|
||||
|
||||
void lexically_proximate_test()
|
||||
{
|
||||
void lexically_proximate_test()
|
||||
{
|
||||
cout << "lexically_proximate_test..." << endl;
|
||||
// paths unrelated
|
||||
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
|
||||
#ifdef BOOST_POSIX_API
|
||||
cout << "BOOST_POSIX_API" << endl;
|
||||
cout << "BOOST_POSIX_API" << endl;
|
||||
#endif
|
||||
#ifdef BOOST_WINDOWS_API
|
||||
cout << "BOOST_WINDOWS_API" << endl;
|
||||
cout << "BOOST_WINDOWS_API" << endl;
|
||||
#endif
|
||||
|
||||
lexically_relative_test();
|
||||
lexically_proximate_test();
|
||||
lexically_relative_test();
|
||||
lexically_proximate_test();
|
||||
|
||||
return ::boost::report_errors();
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#ifndef BOOST_LIGHTWEIGHT_MAIN
|
||||
# include <boost/test/prg_exec_monitor.hpp>
|
||||
#include <boost/test/prg_exec_monitor.hpp>
|
||||
#else
|
||||
# include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
@ -30,34 +30,33 @@ using std::endl;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
namespace
|
||||
{
|
||||
bool cleanup = true;
|
||||
namespace {
|
||||
bool cleanup = true;
|
||||
}
|
||||
|
||||
// cpp_main ----------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0)
|
||||
cleanup = false;
|
||||
if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0)
|
||||
cleanup = false;
|
||||
|
||||
// Test cases go after this block of comments
|
||||
// Use test case macros from boost/core/lightweight_test.hpp:
|
||||
//
|
||||
// BOOST_TEST(predicate); // test passes if predicate evaluates to true
|
||||
// BOOST_TEST_EQ(x, y); // test passes if x == y
|
||||
// BOOST_TEST_NE(x, y); // test passes if x != y
|
||||
// BOOST_ERROR(msg); // test fails, outputs msg
|
||||
// Examples:
|
||||
// BOOST_TEST(path("f00").size() == 3); // test passes
|
||||
// BOOST_TEST_EQ(path("f00").size(), 3); // test passes
|
||||
// BOOST_MSG("Oops!"); // test fails, outputs "Oops!"
|
||||
// Test cases go after this block of comments
|
||||
// Use test case macros from boost/core/lightweight_test.hpp:
|
||||
//
|
||||
// BOOST_TEST(predicate); // test passes if predicate evaluates to true
|
||||
// BOOST_TEST_EQ(x, y); // test passes if x == y
|
||||
// BOOST_TEST_NE(x, y); // test passes if x != y
|
||||
// BOOST_ERROR(msg); // test fails, outputs msg
|
||||
// Examples:
|
||||
// BOOST_TEST(path("f00").size() == 3); // test passes
|
||||
// BOOST_TEST_EQ(path("f00").size(), 3); // test passes
|
||||
// BOOST_MSG("Oops!"); // test fails, outputs "Oops!"
|
||||
|
||||
if (cleanup)
|
||||
{
|
||||
// Remove any test files or directories here
|
||||
}
|
||||
if (cleanup)
|
||||
{
|
||||
// Remove any test files or directories here
|
||||
}
|
||||
|
||||
return ::boost::report_errors();
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@ -12,68 +12,61 @@
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <locale>
|
||||
#include <cwchar> // for mbstate_t
|
||||
#include <cwchar> // for mbstate_t
|
||||
|
||||
//------------------------------------------------------------------------------------//
|
||||
// //
|
||||
// class test_codecvt //
|
||||
// //
|
||||
// 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. //
|
||||
// //
|
||||
// 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 //
|
||||
// code conversion did not occur as expected. //
|
||||
// //
|
||||
//------------------------------------------------------------------------------------//
|
||||
//------------------------------------------------------------------------------------//
|
||||
// //
|
||||
// class test_codecvt //
|
||||
// //
|
||||
// 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. //
|
||||
// //
|
||||
// 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 //
|
||||
// code conversion did not occur as expected. //
|
||||
// //
|
||||
//------------------------------------------------------------------------------------//
|
||||
|
||||
class test_codecvt
|
||||
: public std::codecvt< wchar_t, char, std::mbstate_t >
|
||||
{
|
||||
public:
|
||||
explicit test_codecvt()
|
||||
: 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
|
||||
class test_codecvt :
|
||||
public std::codecvt< wchar_t, char, std::mbstate_t >
|
||||
{
|
||||
public:
|
||||
explicit test_codecvt() :
|
||||
std::codecvt< wchar_t, char, std::mbstate_t >()
|
||||
{
|
||||
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&,
|
||||
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; }
|
||||
protected:
|
||||
virtual bool do_always_noconv() const throw() { return false; }
|
||||
virtual int do_encoding() const throw() { return 0; }
|
||||
|
||||
virtual int do_length(std::mbstate_t&,
|
||||
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { 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 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
|
||||
|
@ -24,85 +24,85 @@
|
||||
using std::make_pair;
|
||||
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;
|
||||
decode_type table;
|
||||
typedef std::map< DWORD, std::string > decode_type;
|
||||
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_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_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_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_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_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_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_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
|
||||
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_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_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_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_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_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_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
|
||||
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
|
||||
|
||||
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[] =
|
||||
if (argc < 2)
|
||||
{
|
||||
"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
|
||||
std::cout << "Usage: windows_attributes path\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
"_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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user