Reformatted code for more consistent look and better readability.

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

View File

@ -17,8 +17,7 @@ using boost::filesystem::path;
using std::string; using std::string;
using std::cout; using std::cout;
namespace namespace {
{
std::ifstream infile; std::ifstream infile;
std::ofstream posix_outfile; std::ofstream posix_outfile;
std::ifstream posix_infile; std::ifstream posix_infile;
@ -54,7 +53,8 @@ namespace
string s; string s;
for (path::iterator i(p.begin()); i != p.end(); ++i) for (path::iterator i(p.begin()); i != p.end(); ++i)
{ {
if ( i != p.begin() ) s += ','; if (i != p.begin())
s += ',';
s += (*i).string(); s += (*i).string();
} }
return s; return s;
@ -151,14 +151,12 @@ namespace
void do_table() void do_table()
{ {
outfile << outfile << "<h1>Path Decomposition Table</h1>\n"
"<h1>Path Decomposition Table</h1>\n"
"<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n" "<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n"
"implementations yield different results. The top value is the\n" "implementations yield different results. The top value is the\n"
"<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n" "<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n"
"<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n" "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
"<p>\n" "<p>\n";
;
// generate the column headings // generate the column headings
@ -196,15 +194,13 @@ int cpp_main( int argc, char * argv[] ) // note name!
{ {
if (argc != 5) if (argc != 5)
{ {
std::cerr << std::cerr << "Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
"Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
"Run on POSIX first, then on Windows\n" "Run on POSIX first, then on Windows\n"
" \"POSIX\" causes POSIX results to be saved in posix-file;\n" " \"POSIX\" causes POSIX results to be saved in posix-file;\n"
" \"Windows\" causes POSIX results read from posix-file\n" " \"Windows\" causes POSIX results read from posix-file\n"
" input-file contains the paths to appear in the table.\n" " input-file contains the paths to appear in the table.\n"
" posix-file will be used for POSIX results\n" " posix-file will be used for POSIX results\n"
" output-file will contain the generated HTML.\n" " output-file will contain the generated HTML.\n";
;
return 1; return 1;
} }
@ -247,14 +243,12 @@ int cpp_main( int argc, char * argv[] ) // note name!
"<head>\n" "<head>\n"
"<title>Path Decomposition Table</title>\n" "<title>Path Decomposition Table</title>\n"
"</head>\n" "</head>\n"
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n" "<body bgcolor=\"#ffffff\" text=\"#000000\">\n";
;
do_table(); do_table();
outfile << "</body>\n" outfile << "</body>\n"
"</html>\n" "</html>\n";
;
return 0; return 0;
} }

View File

@ -12,6 +12,7 @@
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
using std::cout; using std::cout;
using std::endl; using std::endl;
using namespace boost::filesystem; using namespace boost::filesystem;

View File

@ -24,15 +24,13 @@ using boost::system::error_code;
using boost::system::system_error; using boost::system::system_error;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
{
void report_system_error(const system_error& ex) void report_system_error(const system_error& ex)
{ {
cout << " threw system_error:\n" cout << " threw system_error:\n"
<< " ex.code().value() is " << ex.code().value() << '\n' << " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n' << " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n' << " ex.what() is " << ex.what() << '\n';
;
} }
void report_filesystem_error(const system_error& ex) void report_filesystem_error(const system_error& ex)
@ -40,8 +38,7 @@ namespace
cout << " threw filesystem_error exception:\n" cout << " threw filesystem_error exception:\n"
<< " ex.code().value() is " << ex.code().value() << '\n' << " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n' << " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n' << " ex.what() is " << ex.what() << '\n';
;
} }
void report_status(fs::file_status s) void report_status(fs::file_status s)
@ -50,25 +47,35 @@ namespace
switch (s.type()) switch (s.type())
{ {
case fs::status_error: case fs::status_error:
cout << "status_error\n"; break; cout << "status_error\n";
break;
case fs::file_not_found: case fs::file_not_found:
cout << "file_not_found\n"; break; cout << "file_not_found\n";
break;
case fs::regular_file: case fs::regular_file:
cout << "regular_file\n"; break; cout << "regular_file\n";
break;
case fs::directory_file: case fs::directory_file:
cout << "directory_file\n"; break; cout << "directory_file\n";
break;
case fs::symlink_file: case fs::symlink_file:
cout << "symlink_file\n"; break; cout << "symlink_file\n";
break;
case fs::block_file: case fs::block_file:
cout << "block_file\n"; break; cout << "block_file\n";
break;
case fs::character_file: case fs::character_file:
cout << "character_file\n"; break; cout << "character_file\n";
break;
case fs::fifo_file: case fs::fifo_file:
cout << "fifo_file\n"; break; cout << "fifo_file\n";
break;
case fs::socket_file: case fs::socket_file:
cout << "socket_file\n"; break; cout << "socket_file\n";
break;
case fs::type_unknown: case fs::type_unknown:
cout << "type_unknown\n"; break; cout << "type_unknown\n";
break;
default: default:
cout << "not a valid enumeration constant\n"; cout << "not a valid enumeration constant\n";
} }
@ -79,13 +86,12 @@ namespace
cout << " ec:\n" cout << " ec:\n"
<< " value() is " << ec.value() << '\n' << " value() is " << ec.value() << '\n'
<< " category().name() is " << ec.category().name() << '\n' << " category().name() is " << ec.category().name() << '\n'
<< " message() is " << ec.message() << '\n' << " message() is " << ec.message() << '\n';
;
} }
bool threw_exception; bool threw_exception;
} } // namespace
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
@ -119,7 +125,10 @@ int main(int argc, char* argv[])
cout << "\nstatus(\"" << p.string() << "\");\n"; cout << "\nstatus(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { s = fs::status(p); } try
{
s = fs::status(p);
}
catch (const system_error& ex) catch (const system_error& ex)
{ {
report_filesystem_error(ex); report_filesystem_error(ex);
@ -141,7 +150,10 @@ int main(int argc, char* argv[])
cout << "\nexists(\"" << p.string() << "\");\n"; cout << "\nexists(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { b = fs::exists(p); } try
{
b = fs::exists(p);
}
catch (const system_error& ex) catch (const system_error& ex)
{ {
report_filesystem_error(ex); report_filesystem_error(ex);
@ -160,7 +172,10 @@ int main(int argc, char* argv[])
cout << "\ndirectory_iterator(\"" << p.string() << "\");\n"; cout << "\ndirectory_iterator(\"" << p.string() << "\");\n";
threw_exception = false; threw_exception = false;
try { di = fs::directory_iterator(p); } try
{
di = fs::directory_iterator(p);
}
catch (const system_error& ex) catch (const system_error& ex)
{ {
report_filesystem_error(ex); report_filesystem_error(ex);

View File

@ -13,11 +13,12 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
using std::cout; using std::endl; using std::cout;
using std::endl;
using namespace boost::filesystem; using namespace boost::filesystem;
namespace namespace {
{
path p; path p;
void print_boost_macros() void print_boost_macros()
@ -36,11 +37,9 @@ namespace
<< std::endl; << std::endl;
} }
const char* file_type_tab[] = const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file",
{ "status_error", "file_not_found", "regular_file", "directory_file",
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file", "symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
"type_unknown" "type_unknown" };
};
const char* file_type_c_str(enum file_type t) const char* file_type_c_str(enum file_type t)
{ {
@ -88,7 +87,7 @@ namespace
} }
} }
} } // namespace
int cpp_main(int argc, char* argv[]) int cpp_main(int argc, char* argv[])
{ {

View File

@ -25,30 +25,45 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
{
// we can't use boost::filesystem::copy_file() because the argument types // we can't use boost::filesystem::copy_file() because the argument types
// differ, so provide a not-very-smart replacement. // differ, so provide a not-very-smart replacement.
void copy_file(const fs::wpath& from, const user::mbpath& to) void copy_file(const fs::wpath& from, const user::mbpath& to)
{ {
fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary); fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary);
if ( !from_file ) { std::cout << "input open failed\n"; return; } if (!from_file)
{
std::cout << "input open failed\n";
return;
}
fs::ofstream to_file(to, std::ios_base::out | std::ios_base::binary); fs::ofstream to_file(to, std::ios_base::out | std::ios_base::binary);
if ( !to_file ) { std::cout << "output open failed\n"; return; } if (!to_file)
{
std::cout << "output open failed\n";
return;
}
char c; char c;
while (from_file.get(c)) while (from_file.get(c))
{ {
to_file.put(c); to_file.put(c);
if ( to_file.fail() ) { std::cout << "write error\n"; return; } if (to_file.fail())
{
std::cout << "write error\n";
return;
}
} }
if ( !from_file.eof() ) { std::cout << "read error\n"; } if (!from_file.eof())
{
std::cout << "read error\n";
} }
} }
} // namespace
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc != 2) if (argc != 2)
@ -83,8 +98,3 @@ int main( int argc, char * argv[] )
return 0; return 0;
} }

View File

@ -19,21 +19,20 @@
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace namespace {
{
// ISO C calls this "the locale-specific native environment": // ISO C calls this "the locale-specific native environment":
std::locale loc(""); std::locale loc("");
const std::codecvt< wchar_t, char, std::mbstate_t >* const std::codecvt< wchar_t, char, std::mbstate_t >*
cvt( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> > cvt(&std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc));
( loc ) );
} } // namespace
namespace user {
namespace user
{
mbpath_traits::external_string_type mbpath_traits::external_string_type
mbpath_traits::to_external( const mbpath & ph, mbpath_traits::to_external(const mbpath& ph, const internal_string_type& src)
const internal_string_type & src )
{ {
std::size_t work_size(cvt->max_length() * (src.size() + 1)); std::size_t work_size(cvt->max_length() * (src.size() + 1));
boost::scoped_array< char > work(new char[work_size]); boost::scoped_array< char > work(new char[work_size]);
@ -73,8 +72,7 @@ namespace user
void mbpath_traits::imbue(const std::locale& new_loc) void mbpath_traits::imbue(const std::locale& new_loc)
{ {
loc = new_loc; loc = new_loc;
cvt = &std::use_facet cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc);
<std::codecvt<wchar_t, char, std::mbstate_t> >( loc );
} }
} // namespace user } // namespace user

View File

@ -14,8 +14,8 @@
#include <string> #include <string>
#include <locale> #include <locale>
namespace user namespace user {
{
struct mbpath_traits; struct mbpath_traits;
typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath; typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath;
@ -25,20 +25,23 @@ namespace user
typedef std::wstring internal_string_type; typedef std::wstring internal_string_type;
typedef std::string external_string_type; typedef std::string external_string_type;
static external_string_type to_external( const mbpath & ph, static external_string_type to_external(const mbpath& ph, const internal_string_type& src);
const internal_string_type & src );
static internal_string_type to_internal(const external_string_type& src); static internal_string_type to_internal(const external_string_type& src);
static void imbue(const std::locale& loc); static void imbue(const std::locale& loc);
}; };
} // namespace user } // namespace user
namespace boost namespace boost {
namespace filesystem {
template<>
struct is_basic_path< user::mbpath >
{ {
namespace filesystem static const bool value = true;
{ };
template<> struct is_basic_path<user::mbpath>
{ static const bool value = true; }; } // namespace filesystem
} } // namespace boost
}

View File

@ -9,10 +9,14 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace std; using namespace std;
using namespace boost::filesystem; using namespace boost::filesystem;
const char * say_what(bool b) { return b ? "true" : "false"; } const char* say_what(bool b)
{
return b ? "true" : "false";
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {

View File

@ -70,7 +70,6 @@ int main(int argc, char* argv[])
++other_count; ++other_count;
std::cout << dir_itr->path().filename() << " [other]\n"; std::cout << dir_itr->path().filename() << " [other]\n";
} }
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
@ -78,7 +77,8 @@ int main(int argc, char* argv[])
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
} }
} }
std::cout << "\n" << file_count << " files\n" std::cout << "\n"
<< file_count << " files\n"
<< dir_count << " directories\n" << dir_count << " directories\n"
<< other_count << " others\n" << other_count << " others\n"
<< err_count << " errors\n"; << err_count << " errors\n";

View File

@ -16,7 +16,7 @@ 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));
} }

View File

@ -9,6 +9,7 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])

View File

@ -9,6 +9,7 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])

View File

@ -9,6 +9,7 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace std; using namespace std;
using namespace boost::filesystem; using namespace boost::filesystem;
@ -26,10 +27,8 @@ int main(int argc, char* argv[])
{ {
if (is_regular_file(p)) // is path p a regular file? if (is_regular_file(p)) // is path p a regular file?
cout << p << " size is " << file_size(p) << '\n'; cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p)) // is path p a directory? else if (is_directory(p)) // is path p a directory?
cout << p << " is a directory\n"; cout << p << " is a directory\n";
else else
cout << p << " exists, but is not a regular file or directory\n"; cout << p << " exists, but is not a regular file or directory\n";
} }

View File

@ -9,6 +9,7 @@
#include <iostream> #include <iostream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using std::cout; using std::cout;
using namespace boost::filesystem; using namespace boost::filesystem;
@ -27,13 +28,14 @@ int main(int argc, char* argv[])
if (exists(p)) if (exists(p))
{ {
if (is_regular_file(p)) if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n'; cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p)) else if (is_directory(p))
{ {
cout << p << " is a directory containing:\n"; cout << p << " is a directory containing:\n";
for (const directory_entry& x : directory_iterator(p)) for (directory_entry const& x : directory_iterator(p))
cout << " " << x.path() << '\n'; cout << " " << x.path() << '\n';
} }
else else
@ -42,8 +44,7 @@ int main(int argc, char* argv[])
else else
cout << p << " does not exist\n"; cout << p << " does not exist\n";
} }
catch (filesystem_error& ex)
catch (const filesystem_error& ex)
{ {
cout << ex.what() << '\n'; cout << ex.what() << '\n';
} }

View File

@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using std::cout; using std::cout;
using namespace boost::filesystem; using namespace boost::filesystem;
@ -29,8 +30,9 @@ int main(int argc, char* argv[])
if (exists(p)) if (exists(p))
{ {
if (is_regular_file(p)) if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n'; cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p)) else if (is_directory(p))
{ {
cout << p << " is a directory containing:\n"; cout << p << " is a directory containing:\n";
@ -51,8 +53,7 @@ int main(int argc, char* argv[])
else else
cout << p << " does not exist\n"; cout << p << " does not exist\n";
} }
catch (filesystem_error& ex)
catch (const filesystem_error& ex)
{ {
cout << ex.what() << '\n'; cout << ex.what() << '\n';
} }

View File

@ -10,6 +10,7 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <string> #include <string>
#include <list> #include <list>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
int main() int main()
@ -33,20 +34,36 @@ int main()
wide_list.push_back(L'3'); wide_list.push_back(L'3');
wide_list.push_back(L'\u263A'); wide_list.push_back(L'\u263A');
{ fs::ofstream f("smile"); } {
{ fs::ofstream f(L"smile\u263A"); } fs::ofstream f("smile");
{ fs::ofstream f(narrow_string); } }
{ fs::ofstream f(wide_string); } {
{ fs::ofstream f(narrow_list); } fs::ofstream f(L"smile\u263A");
{ fs::ofstream f(wide_list); } }
{
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.pop_back();
narrow_list.push_back('4'); narrow_list.push_back('4');
wide_list.pop_back(); wide_list.pop_back();
wide_list.pop_back(); wide_list.pop_back();
wide_list.push_back(L'4'); wide_list.push_back(L'4');
wide_list.push_back(L'\u263A'); 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(fs::path(narrow_list.begin(), narrow_list.end()));
}
{
fs::ofstream f(fs::path(wide_list.begin(), wide_list.end()));
}
return 0; return 0;
} }

View File

@ -10,6 +10,7 @@
#include <iostream> #include <iostream>
#include <exception> #include <exception>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
using namespace boost::filesystem; using namespace boost::filesystem;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@ -37,8 +38,7 @@ int main(int argc, char* argv[])
} }
} }
} }
catch (std::exception& ex)
catch (const std::exception& ex)
{ {
std::cout << "************* exception *****************\n"; std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n'; std::cout << ex.what() << '\n';

View File

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

View File

@ -25,8 +25,7 @@ int main(int argc, char* argv[])
error_code ec; error_code ec;
for (recursive_directory_iterator it(argv[1], ec); for (recursive_directory_iterator it(argv[1], ec);
it != recursive_directory_iterator(); it != recursive_directory_iterator();)
)
{ {
for (int i = 0; i <= it.level(); ++i) for (int i = 0; i <= it.level(); ++i)
std::cout << " "; std::cout << " ";

View File

@ -55,8 +55,7 @@
// normalize macros ------------------------------------------------------------------// // normalize macros ------------------------------------------------------------------//
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) \ #if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) && !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
#define BOOST_FILESYSTEM_STATIC_LINK #define BOOST_FILESYSTEM_STATIC_LINK
#endif #endif
@ -88,8 +87,7 @@
// enable automatic library variant selection ----------------------------------------// // enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) \ #if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
&& !defined(BOOST_FILESYSTEM_NO_LIB)
// //
// Set the name of our library, this will get undef'ed by auto_link.hpp // Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it: // once it's done with it:

View File

@ -24,10 +24,8 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
@ -50,9 +48,9 @@ namespace boost
#endif #endif
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP #endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP

View File

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

View File

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

View File

@ -62,22 +62,23 @@ public:
typedef boost::filesystem::path::value_type value_type; // enables class path ctor taking directory_entry typedef boost::filesystem::path::value_type value_type; // enables class path ctor taking directory_entry
directory_entry() BOOST_NOEXCEPT {} directory_entry() BOOST_NOEXCEPT {}
explicit directory_entry(const boost::filesystem::path& p) : explicit directory_entry(const boost::filesystem::path& p) :
m_path(p), m_status(file_status()), m_symlink_status(file_status()) m_path(p), m_status(file_status()), m_symlink_status(file_status())
{ {
} }
directory_entry(const boost::filesystem::path& p,
file_status st, file_status symlink_st = file_status()) : directory_entry(const boost::filesystem::path& p, file_status st, file_status symlink_st = file_status()) :
m_path(p), m_status(st), m_symlink_status(symlink_st) m_path(p), m_status(st), m_symlink_status(symlink_st)
{ {
} }
directory_entry(const directory_entry& rhs) : directory_entry(directory_entry const& rhs) :
m_path(rhs.m_path), m_status(rhs.m_status), m_symlink_status(rhs.m_symlink_status) m_path(rhs.m_path), m_status(rhs.m_status), m_symlink_status(rhs.m_symlink_status)
{ {
} }
directory_entry& operator=(const directory_entry& rhs) directory_entry& operator=(directory_entry const& rhs)
{ {
m_path = rhs.m_path; m_path = rhs.m_path;
m_status = rhs.m_status; m_status = rhs.m_status;
@ -91,9 +92,12 @@ public:
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
directory_entry(directory_entry&& rhs) BOOST_NOEXCEPT : directory_entry(directory_entry&& rhs) BOOST_NOEXCEPT :
m_path(std::move(rhs.m_path)), m_status(std::move(rhs.m_status)), m_symlink_status(std::move(rhs.m_symlink_status)) m_path(std::move(rhs.m_path)),
m_status(std::move(rhs.m_status)),
m_symlink_status(std::move(rhs.m_symlink_status))
{ {
} }
directory_entry& operator=(directory_entry&& rhs) BOOST_NOEXCEPT directory_entry& operator=(directory_entry&& rhs) BOOST_NOEXCEPT
{ {
m_path = std::move(rhs.m_path); m_path = std::move(rhs.m_path);
@ -103,16 +107,14 @@ public:
} }
#endif #endif
void assign(const boost::filesystem::path& p, void assign(const boost::filesystem::path& p, file_status st = file_status(), file_status symlink_st = file_status())
file_status st = file_status(), file_status symlink_st = file_status())
{ {
m_path = p; m_path = p;
m_status = st; m_status = st;
m_symlink_status = symlink_st; m_symlink_status = symlink_st;
} }
void replace_filename(const boost::filesystem::path& p, void replace_filename(const boost::filesystem::path& p, file_status st = file_status(), file_status symlink_st = file_status())
file_status st = file_status(), file_status symlink_st = file_status())
{ {
m_path.remove_filename(); m_path.remove_filename();
m_path /= p; m_path /= p;
@ -127,19 +129,22 @@ public:
} }
#endif #endif
const boost::filesystem::path& path() const BOOST_NOEXCEPT { return m_path; } const boost::filesystem::path& path() const BOOST_NOEXCEPT
operator const boost::filesystem::path&() const BOOST_NOEXCEPT { return m_path; } {
return m_path;
}
operator boost::filesystem::path const&() const BOOST_NOEXCEPT { return m_path; }
file_status status() const { return get_status(); } file_status status() const { return get_status(); }
file_status status(system::error_code& ec) const BOOST_NOEXCEPT { return get_status(&ec); } file_status status(system::error_code& ec) const BOOST_NOEXCEPT { return get_status(&ec); }
file_status symlink_status() const { return get_symlink_status(); } file_status symlink_status() const { return get_symlink_status(); }
file_status symlink_status(system::error_code& ec) const BOOST_NOEXCEPT { return get_symlink_status(&ec); } file_status symlink_status(system::error_code& ec) const BOOST_NOEXCEPT { return get_symlink_status(&ec); }
bool operator==(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path == rhs.m_path; } bool operator==(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path == rhs.m_path; }
bool operator!=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path != rhs.m_path; } bool operator!=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path != rhs.m_path; }
bool operator< (const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path < rhs.m_path; } bool operator<(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path < rhs.m_path; }
bool operator<=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path <= rhs.m_path; } bool operator<=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path <= rhs.m_path; }
bool operator> (const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path > rhs.m_path; } bool operator>(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path > rhs.m_path; }
bool operator>=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path >= rhs.m_path; } bool operator>=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path >= rhs.m_path; }
private: private:
BOOST_FILESYSTEM_DECL file_status get_status(system::error_code* ec = 0) const; BOOST_FILESYSTEM_DECL file_status get_status(system::error_code* ec = 0) const;
@ -151,7 +156,6 @@ private:
mutable file_status m_symlink_status; // lstat()-like mutable file_status m_symlink_status; // lstat()-like
}; // directory_entry }; // directory_entry
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
// directory_entry overloads // // directory_entry overloads //
@ -160,28 +164,79 @@ private:
// Without these functions, calling (for example) 'is_directory' with a 'directory_entry' results in: // Without these functions, calling (for example) 'is_directory' with a 'directory_entry' results in:
// - a conversion to 'path' using 'operator const boost::filesystem::path&()', // - a conversion to 'path' using 'operator const boost::filesystem::path&()',
// - then a call to 'is_directory(const path& p)' which recomputes the status with 'detail::status(p)'. // - then a call to 'is_directory(path const& p)' which recomputes the status with 'detail::status(p)'.
// //
// These functions avoid a costly recomputation of the status if one calls 'is_directory(e)' instead of 'is_directory(e.status())' // These functions avoid a costly recomputation of the status if one calls 'is_directory(e)' instead of 'is_directory(e.status())'
inline file_status status (const directory_entry& e) { return e.status(); } inline file_status status(directory_entry const& e)
inline file_status status (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return e.status(ec); } {
inline bool type_present (const directory_entry& e) { return filesystem::type_present(e.status()); } return e.status();
inline bool type_present (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::type_present(e.status(ec)); } }
inline bool status_known (const directory_entry& e) { return filesystem::status_known(e.status()); } inline file_status status(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
inline bool status_known (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::status_known(e.status(ec)); } {
inline bool exists (const directory_entry& e) { return filesystem::exists(e.status()); } return e.status(ec);
inline bool exists (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::exists(e.status(ec)); } }
inline bool is_regular_file(const directory_entry& e) { return filesystem::is_regular_file(e.status()); } inline bool type_present(directory_entry const& e)
inline bool is_regular_file(const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_regular_file(e.status(ec)); } {
inline bool is_directory (const directory_entry& e) { return filesystem::is_directory(e.status()); } return filesystem::type_present(e.status());
inline bool is_directory (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_directory(e.status(ec)); } }
inline bool is_symlink (const directory_entry& e) { return filesystem::is_symlink(e.symlink_status()); } inline bool type_present(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
inline bool is_symlink (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_symlink(e.symlink_status(ec)); } {
inline bool is_other (const directory_entry& e) { return filesystem::is_other(e.status()); } return filesystem::type_present(e.status(ec));
inline bool is_other (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_other(e.status(ec)); } }
inline bool status_known(directory_entry const& e)
{
return filesystem::status_known(e.status());
}
inline bool status_known(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::status_known(e.status(ec));
}
inline bool exists(directory_entry const& e)
{
return filesystem::exists(e.status());
}
inline bool exists(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::exists(e.status(ec));
}
inline bool is_regular_file(directory_entry const& e)
{
return filesystem::is_regular_file(e.status());
}
inline bool is_regular_file(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_regular_file(e.status(ec));
}
inline bool is_directory(directory_entry const& e)
{
return filesystem::is_directory(e.status());
}
inline bool is_directory(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_directory(e.status(ec));
}
inline bool is_symlink(directory_entry const& e)
{
return filesystem::is_symlink(e.symlink_status());
}
inline bool is_symlink(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_symlink(e.symlink_status(ec));
}
inline bool is_other(directory_entry const& e)
{
return filesystem::is_other(e.status());
}
inline bool is_other(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_other(e.status(ec));
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular (const directory_entry& e) { return filesystem::is_regular(e.status()); } inline bool is_regular(directory_entry const& e)
{
return filesystem::is_regular(e.status());
}
#endif #endif
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
@ -245,7 +300,7 @@ struct dir_itr_imp :
}; };
// see path::iterator: comment below // see path::iterator: comment below
BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec); BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it, system::error_code* ec); BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it, system::error_code* ec);
} // namespace detail } // namespace detail
@ -265,7 +320,7 @@ class directory_iterator :
{ {
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec); friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it, system::error_code* ec); friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it, system::error_code* ec);
public: public:
@ -273,17 +328,17 @@ public:
// iterator_facade derived classes don't seem to like implementations in // iterator_facade derived classes don't seem to like implementations in
// separate translation unit dll's, so forward to detail functions // separate translation unit dll's, so forward to detail functions
explicit directory_iterator(const path& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts = directory_options::none) explicit directory_iterator(path const& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts = directory_options::none)
{ {
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), 0); detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), 0);
} }
directory_iterator(const path& p, system::error_code& ec) BOOST_NOEXCEPT directory_iterator(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{ {
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(directory_options::none), &ec); detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(directory_options::none), &ec);
} }
directory_iterator(const path& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec) BOOST_NOEXCEPT directory_iterator(path const& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec) BOOST_NOEXCEPT
{ {
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), &ec); detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), &ec);
} }
@ -346,19 +401,48 @@ private:
// begin() and end() are only used by a range-based for statement in the context of // begin() and end() are only used by a range-based for statement in the context of
// auto - thus the top-level const is stripped - so returning const is harmless and // auto - thus the top-level const is stripped - so returning const is harmless and
// emphasizes begin() is just a pass through. // emphasizes begin() is just a pass through.
inline const directory_iterator& begin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline directory_iterator const& begin(directory_iterator const& iter) BOOST_NOEXCEPT
inline directory_iterator end(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); } {
return iter;
}
inline directory_iterator end(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
// enable C++14 generic accessors for range const iterators // enable C++14 generic accessors for range const iterators
inline const directory_iterator& cbegin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline directory_iterator const& cbegin(directory_iterator const& iter) BOOST_NOEXCEPT
inline directory_iterator cend(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); } {
return iter;
}
inline directory_iterator cend(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
// enable directory_iterator BOOST_FOREACH -----------------------------------------// // enable directory_iterator BOOST_FOREACH -----------------------------------------//
inline directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT
inline directory_iterator range_begin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; } {
inline directory_iterator range_end(directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); } return iter;
inline directory_iterator range_end(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); } }
inline directory_iterator range_begin(directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline directory_iterator range_end(directory_iterator&) BOOST_NOEXCEPT
{
return directory_iterator();
}
inline directory_iterator range_end(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
} // namespace filesystem } // namespace filesystem
@ -418,7 +502,7 @@ struct recur_dir_itr_imp :
explicit recur_dir_itr_imp(unsigned int opts) BOOST_NOEXCEPT : m_options(opts) {} explicit recur_dir_itr_imp(unsigned int opts) BOOST_NOEXCEPT : m_options(opts) {}
}; };
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec); BOOST_FILESYSTEM_DECL void recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec); BOOST_FILESYSTEM_DECL void recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec);
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec); BOOST_FILESYSTEM_DECL void recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec);
@ -439,41 +523,41 @@ class recursive_directory_iterator :
{ {
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec); friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec); friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec); friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec);
public: public:
recursive_directory_iterator() BOOST_NOEXCEPT {} // creates the "end" iterator recursive_directory_iterator() BOOST_NOEXCEPT {} // creates the "end" iterator
explicit recursive_directory_iterator(const path& dir_path) explicit recursive_directory_iterator(path const& dir_path)
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), 0); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), 0);
} }
recursive_directory_iterator(const path& dir_path, system::error_code& ec) recursive_directory_iterator(path const& dir_path, system::error_code& ec)
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), &ec); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), &ec);
} }
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts) recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts)
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0);
} }
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec) recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec)
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec);
} }
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
// Deprecated constructors // Deprecated constructors
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts) recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts)
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0);
} }
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts, system::error_code& ec) BOOST_NOEXCEPT recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts, system::error_code& ec) BOOST_NOEXCEPT
{ {
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec); detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec);
} }
@ -514,7 +598,10 @@ public:
} }
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
int level() const BOOST_NOEXCEPT { return depth(); } int level() const BOOST_NOEXCEPT
{
return depth();
}
bool no_push_pending() const BOOST_NOEXCEPT { return !recursion_pending(); } bool no_push_pending() const BOOST_NOEXCEPT { return !recursion_pending(); }
bool no_push_request() const BOOST_NOEXCEPT { return !recursion_pending(); } bool no_push_request() const BOOST_NOEXCEPT { return !recursion_pending(); }
#endif #endif
@ -539,7 +626,10 @@ public:
} }
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
void no_push(bool value = true) BOOST_NOEXCEPT { disable_recursion_pending(value); } void no_push(bool value = true) BOOST_NOEXCEPT
{
disable_recursion_pending(value);
}
#endif #endif
file_status status() const file_status status() const
@ -594,19 +684,48 @@ typedef recursive_directory_iterator wrecursive_directory_iterator;
// begin() and end() are only used by a range-based for statement in the context of // begin() and end() are only used by a range-based for statement in the context of
// auto - thus the top-level const is stripped - so returning const is harmless and // auto - thus the top-level const is stripped - so returning const is harmless and
// emphasizes begin() is just a pass through. // emphasizes begin() is just a pass through.
inline const recursive_directory_iterator& begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline recursive_directory_iterator const& begin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
inline recursive_directory_iterator end(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); } {
return iter;
}
inline recursive_directory_iterator end(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
// enable C++14 generic accessors for range const iterators // enable C++14 generic accessors for range const iterators
inline const recursive_directory_iterator& cbegin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline recursive_directory_iterator const& cbegin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
inline recursive_directory_iterator cend(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); } {
return iter;
}
inline recursive_directory_iterator cend(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
// enable recursive directory iterator BOOST_FOREACH -------------------------------// // enable recursive directory iterator BOOST_FOREACH -------------------------------//
inline recursive_directory_iterator& range_begin(recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; } inline recursive_directory_iterator& range_begin(recursive_directory_iterator& iter) BOOST_NOEXCEPT
inline recursive_directory_iterator range_begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; } {
inline recursive_directory_iterator range_end(recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); } return iter;
inline recursive_directory_iterator range_end(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); } }
inline recursive_directory_iterator range_begin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline recursive_directory_iterator range_end(recursive_directory_iterator&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
inline recursive_directory_iterator range_end(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
} // namespace filesystem } // namespace filesystem
@ -616,6 +735,7 @@ struct range_mutable_iterator<boost::filesystem::recursive_directory_iterator, v
{ {
typedef boost::filesystem::recursive_directory_iterator type; typedef boost::filesystem::recursive_directory_iterator type;
}; };
template<> template<>
struct range_const_iterator< boost::filesystem::recursive_directory_iterator, void > struct range_const_iterator< boost::filesystem::recursive_directory_iterator, void >
{ {
@ -625,4 +745,5 @@ struct range_const_iterator<boost::filesystem::recursive_directory_iterator, voi
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_DIRECTORY_HPP #endif // BOOST_FILESYSTEM3_DIRECTORY_HPP

View File

@ -83,8 +83,14 @@ private:
std::string m_what; // not built until needed std::string m_what; // not built until needed
BOOST_DEFAULTED_FUNCTION(impl(), {}) BOOST_DEFAULTED_FUNCTION(impl(), {})
explicit impl(path const& path1) : m_path1(path1) {} explicit impl(path const& path1) :
impl(path const& path1, path const& path2) : m_path1(path1), m_path2(path2) {} m_path1(path1)
{
}
impl(path const& path1, path const& path2) :
m_path1(path1), m_path2(path2)
{
}
}; };
boost::intrusive_ptr< impl > m_imp_ptr; boost::intrusive_ptr< impl > m_imp_ptr;
}; };
@ -97,4 +103,5 @@ private:
#endif #endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_EXCEPTION_HPP #endif // BOOST_FILESYSTEM3_EXCEPTION_HPP

View File

@ -23,7 +23,6 @@
#endif #endif
#include <boost/filesystem/config.hpp> #include <boost/filesystem/config.hpp>
#include <boost/detail/bitmask.hpp> #include <boost/detail/bitmask.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
@ -129,15 +128,18 @@ class file_status
{ {
public: public:
BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
m_value(status_error), m_perms(perms_not_known) m_value(status_error),
m_perms(perms_not_known)
{ {
} }
explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT : explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT :
m_value(v), m_perms(perms_not_known) m_value(v),
m_perms(perms_not_known)
{ {
} }
BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT :
m_value(v), m_perms(prms) m_value(v),
m_perms(prms)
{ {
} }
@ -146,7 +148,8 @@ public:
// functions. GCC is not even consistent for the same release on different platforms. // functions. GCC is not even consistent for the same release on different platforms.
BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT :
m_value(rhs.m_value), m_perms(rhs.m_perms) m_value(rhs.m_value),
m_perms(rhs.m_perms)
{ {
} }
BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
@ -159,7 +162,8 @@ public:
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
// Note: std::move is not constexpr in C++11, that's why we're not using it here // Note: std::move is not constexpr in C++11, that's why we're not using it here
BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT : BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT :
m_value(static_cast< file_type&& >(rhs.m_value)), m_perms(static_cast< enum perms&& >(rhs.m_perms)) m_value(static_cast< file_type&& >(rhs.m_value)),
m_perms(static_cast< enum perms&& >(rhs.m_perms))
{ {
} }
BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
@ -196,42 +200,52 @@ inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT
{ {
return f.type() != status_error; return f.type() != status_error;
} }
inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT
{ {
return f.permissions() != perms_not_known; return f.permissions() != perms_not_known;
} }
inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT
{ {
return filesystem::type_present(f) && filesystem::permissions_present(f); return filesystem::type_present(f) && filesystem::permissions_present(f);
} }
inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT
{ {
return f.type() != status_error && f.type() != file_not_found; return f.type() != status_error && f.type() != file_not_found;
} }
inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT
{ {
return f.type() == regular_file; return f.type() == regular_file;
} }
inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT
{ {
return f.type() == directory_file; return f.type() == directory_file;
} }
inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT
{ {
return f.type() == symlink_file; return f.type() == symlink_file;
} }
inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT
{ {
return filesystem::exists(f) && !filesystem::is_regular_file(f) return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
&& !filesystem::is_directory(f) && !filesystem::is_symlink(f);
} }
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular(file_status f) BOOST_NOEXCEPT { return filesystem::is_regular_file(f); } inline bool is_regular(file_status f) BOOST_NOEXCEPT
{
return filesystem::is_regular_file(f);
}
#endif #endif
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP #endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP

View File

@ -26,8 +26,7 @@
// on Windows, except for standard libaries known to have wchar_t overloads for // on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str() // file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \ #if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware // !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
#define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available #define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#else // use the native c_str, which will be narrow on POSIX, wide on Windows #else // use the native c_str, which will be narrow on POSIX, wide on Windows
@ -40,31 +39,26 @@
#pragma warning(disable : 4250) #pragma warning(disable : 4250)
#endif #endif
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// basic_filebuf // // basic_filebuf //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template< class charT, class traits = std::char_traits< charT > > template< class charT, class traits = std::char_traits< charT > >
class basic_filebuf : public std::basic_filebuf<charT,traits> class basic_filebuf :
public std::basic_filebuf< charT, traits >
{ {
private: // disallow copying public:
basic_filebuf(const basic_filebuf&); BOOST_DEFAULTED_FUNCTION(basic_filebuf(), {})
const basic_filebuf& operator=(const basic_filebuf&); BOOST_DELETED_FUNCTION(basic_filebuf(const basic_filebuf&))
BOOST_DELETED_FUNCTION(const basic_filebuf& operator=(const basic_filebuf&))
public: public:
basic_filebuf() {} basic_filebuf< charT, traits >* open(const path& p, std::ios_base::openmode mode)
virtual ~basic_filebuf() {}
basic_filebuf<charT,traits>*
open(const path& p, std::ios_base::openmode mode)
{ {
return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode) return std::basic_filebuf< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode) ? this : 0;
? this : 0;
} }
}; };
@ -73,31 +67,34 @@ namespace filesystem
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template< class charT, class traits = std::char_traits< charT > > template< class charT, class traits = std::char_traits< charT > >
class basic_ifstream : public std::basic_ifstream<charT,traits> class basic_ifstream :
public std::basic_ifstream< charT, traits >
{ {
private: // disallow copying
basic_ifstream(const basic_ifstream&);
const basic_ifstream& operator=(const basic_ifstream&);
public: public:
basic_ifstream() {} BOOST_DEFAULTED_FUNCTION(basic_ifstream(), {})
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ifstream(const path& p) explicit basic_ifstream(const path& p) :
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {} std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
basic_ifstream(const path& p, std::ios_base::openmode mode) basic_ifstream(const path& p, std::ios_base::openmode mode) :
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ifstream(const basic_ifstream&))
BOOST_DELETED_FUNCTION(const basic_ifstream& operator=(const basic_ifstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); } {
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_ifstream() {} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
@ -105,31 +102,34 @@ namespace filesystem
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template< class charT, class traits = std::char_traits< charT > > template< class charT, class traits = std::char_traits< charT > >
class basic_ofstream : public std::basic_ofstream<charT,traits> class basic_ofstream :
public std::basic_ofstream< charT, traits >
{ {
private: // disallow copying
basic_ofstream(const basic_ofstream&);
const basic_ofstream& operator=(const basic_ofstream&);
public: public:
basic_ofstream() {} BOOST_DEFAULTED_FUNCTION(basic_ofstream(), {})
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ofstream(const path& p) explicit basic_ofstream(const path& p) :
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {} std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
basic_ofstream(const path& p, std::ios_base::openmode mode) basic_ofstream(const path& p, std::ios_base::openmode mode) :
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ofstream(const basic_ofstream&))
BOOST_DELETED_FUNCTION(const basic_ofstream& operator=(const basic_ofstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); } {
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_ofstream() {} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
@ -137,34 +137,34 @@ namespace filesystem
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template< class charT, class traits = std::char_traits< charT > > template< class charT, class traits = std::char_traits< charT > >
class basic_fstream : public std::basic_fstream<charT,traits> class basic_fstream :
public std::basic_fstream< charT, traits >
{ {
private: // disallow copying
basic_fstream(const basic_fstream&);
const basic_fstream & operator=(const basic_fstream&);
public: public:
basic_fstream() {} BOOST_DEFAULTED_FUNCTION(basic_fstream(), {})
// use two signatures, rather than one signature with default second // use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416) // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_fstream(const path& p) explicit basic_fstream(const path& p) :
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out) {}
std::ios_base::in | std::ios_base::out) {}
basic_fstream(const path& p, std::ios_base::openmode mode) basic_fstream(const path& p, std::ios_base::openmode mode) :
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {} std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_fstream(const basic_fstream&))
BOOST_DELETED_FUNCTION(const basic_fstream& operator=(const basic_fstream&))
public:
void open(const path& p) void open(const path& p)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, {
std::ios_base::in | std::ios_base::out); } std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode) void open(const path& p, std::ios_base::openmode mode)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); } {
std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
virtual ~basic_fstream() {} }
}; };
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
@ -189,4 +189,5 @@ namespace filesystem
#endif #endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FSTREAM_HPP #endif // BOOST_FILESYSTEM3_FSTREAM_HPP

View File

@ -93,80 +93,78 @@ BOOST_SCOPED_ENUM_DECLARE_END(copy_option)
namespace detail { namespace detail {
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path absolute(const path& p, const path& base, system::error_code* ec=0); path absolute(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
file_status status(const path&p, system::error_code* ec=0); file_status status(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
file_status symlink_status(const path& p, system::error_code* ec=0); file_status symlink_status(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool is_empty(const path& p, system::error_code* ec=0); bool is_empty(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path initial_path(system::error_code* ec = 0); path initial_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path canonical(const path& p, const path& base, system::error_code* ec=0); path canonical(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void copy(const path& from, const path& to, unsigned int options, system::error_code* ec=0); void copy(path const& from, path const& to, unsigned int options, system::error_code* ec = 0);
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void copy_directory(const path& from, const path& to, system::error_code* ec=0); void copy_directory(path const& from, path const& to, system::error_code* ec = 0);
#endif #endif
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool copy_file(const path& from, const path& to, // See ticket #2925 bool copy_file(path const& from, path const& to, // See ticket #2925
unsigned int options, system::error_code* ec = 0); // see copy_options for options unsigned int options, system::error_code* ec = 0); // see copy_options for options
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0); void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec=0); bool create_directories(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool create_directory(const path& p, const path* existing, system::error_code* ec=0); bool create_directory(path const& p, const path* existing, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void create_directory_symlink(const path& to, const path& from, void create_directory_symlink(path const& to, path const& from, system::error_code* ec = 0);
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void create_hard_link(const path& to, const path& from, system::error_code* ec=0); void create_hard_link(path const& to, path const& from, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void create_symlink(const path& to, const path& from, system::error_code* ec=0); void create_symlink(path const& to, path const& from, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path current_path(system::error_code* ec = 0); path current_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void current_path(const path& p, system::error_code* ec=0); void current_path(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool equivalent(const path& p1, const path& p2, system::error_code* ec=0); bool equivalent(path const& p1, path const& p2, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
boost::uintmax_t file_size(const path& p, system::error_code* ec=0); boost::uintmax_t file_size(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0); boost::uintmax_t hard_link_count(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
std::time_t creation_time(const path& p, system::error_code* ec=0); std::time_t creation_time(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
std::time_t last_write_time(const path& p, system::error_code* ec=0); std::time_t last_write_time(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void last_write_time(const path& p, const std::time_t new_time, void last_write_time(path const& p, const std::time_t new_time, system::error_code* ec = 0);
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void permissions(const path& p, perms prms, system::error_code* ec=0); void permissions(path const& p, perms prms, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path read_symlink(const path& p, system::error_code* ec=0); path read_symlink(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path relative(const path& p, const path& base, system::error_code* ec = 0); path relative(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
bool remove(const path& p, system::error_code* ec=0); bool remove(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
boost::uintmax_t remove_all(const path& p, system::error_code* ec=0); boost::uintmax_t remove_all(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void rename(const path& old_p, const path& new_p, system::error_code* ec=0); void rename(path const& old_p, path const& new_p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void resize_file(const path& p, uintmax_t size, system::error_code* ec=0); void resize_file(path const& p, uintmax_t size, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
space_info space(const path& p, system::error_code* ec=0); space_info space(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path system_complete(const path& p, system::error_code* ec=0); path system_complete(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path temp_directory_path(system::error_code* ec = 0); path temp_directory_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path unique_path(const path& p, system::error_code* ec=0); path unique_path(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
path weakly_canonical(const path& p, system::error_code* ec = 0); path weakly_canonical(path const& p, system::error_code* ec = 0);
} // namespace detail } // namespace detail
@ -176,54 +174,97 @@ path weakly_canonical(const path& p, system::error_code* ec = 0);
// // // //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
inline inline file_status status(path const& p)
file_status status(const path& p) {return detail::status(p);} {
inline return detail::status(p);
file_status status(const path& p, system::error_code& ec) }
{return detail::status(p, &ec);}
inline inline file_status status(path const& p, system::error_code& ec)
file_status symlink_status(const path& p) {return detail::symlink_status(p);} {
inline return detail::status(p, &ec);
file_status symlink_status(const path& p, system::error_code& ec) }
{return detail::symlink_status(p, &ec);}
inline inline file_status symlink_status(path const& p)
bool exists(const path& p) {return exists(detail::status(p));} {
inline return detail::symlink_status(p);
bool exists(const path& p, system::error_code& ec) }
{return exists(detail::status(p, &ec));}
inline inline file_status symlink_status(path const& p, system::error_code& ec)
bool is_directory(const path& p) {return is_directory(detail::status(p));} {
inline return detail::symlink_status(p, &ec);
bool is_directory(const path& p, system::error_code& ec) }
{return is_directory(detail::status(p, &ec));}
inline inline bool exists(path const& p)
bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));} {
inline return exists(detail::status(p));
bool is_regular_file(const path& p, system::error_code& ec) }
{return is_regular_file(detail::status(p, &ec));}
inline inline bool exists(path const& p, system::error_code& ec)
bool is_other(const path& p) {return is_other(detail::status(p));} {
inline return exists(detail::status(p, &ec));
bool is_other(const path& p, system::error_code& ec) }
{return is_other(detail::status(p, &ec));}
inline inline bool is_directory(path const& p)
bool is_symlink(const path& p) {return is_symlink(detail::symlink_status(p));} {
inline return is_directory(detail::status(p));
bool is_symlink(const path& p, system::error_code& ec) }
{return is_symlink(detail::symlink_status(p, &ec));}
inline bool is_directory(path const& p, system::error_code& ec)
{
return is_directory(detail::status(p, &ec));
}
inline bool is_regular_file(path const& p)
{
return is_regular_file(detail::status(p));
}
inline bool is_regular_file(path const& p, system::error_code& ec)
{
return is_regular_file(detail::status(p, &ec));
}
inline bool is_other(path const& p)
{
return is_other(detail::status(p));
}
inline bool is_other(path const& p, system::error_code& ec)
{
return is_other(detail::status(p, &ec));
}
inline bool is_symlink(path const& p)
{
return is_symlink(detail::symlink_status(p));
}
inline bool is_symlink(path const& p, system::error_code& ec)
{
return is_symlink(detail::symlink_status(p, &ec));
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline inline bool is_regular(path const& p)
bool is_regular(const path& p) {return is_regular(detail::status(p));} {
inline return is_regular(detail::status(p));
bool is_regular(const path& p, system::error_code& ec) }
{return is_regular(detail::status(p, &ec));}
inline bool is_regular(path const& p, system::error_code& ec)
{
return is_regular(detail::status(p, &ec));
}
#endif #endif
inline inline bool is_empty(path const& p)
bool is_empty(const path& p) {return detail::is_empty(p);} {
inline return detail::is_empty(p);
bool is_empty(const path& p, system::error_code& ec) }
{return detail::is_empty(p, &ec);}
inline bool is_empty(path const& p, system::error_code& ec)
{
return detail::is_empty(p, &ec);
}
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -231,306 +272,428 @@ bool is_empty(const path& p, system::error_code& ec)
// // // //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
inline inline path initial_path()
path initial_path() {return detail::initial_path();} {
return detail::initial_path();
}
inline inline path initial_path(system::error_code& ec)
path initial_path(system::error_code& ec) {return detail::initial_path(&ec);} {
return detail::initial_path(&ec);
}
template< class Path > template< class Path >
path initial_path() {return initial_path();} path initial_path()
{
return initial_path();
}
template< class Path > template< class Path >
path initial_path(system::error_code& ec) {return detail::initial_path(&ec);} path initial_path(system::error_code& ec)
{
return detail::initial_path(&ec);
}
inline inline path current_path()
path current_path() {return detail::current_path();} {
return detail::current_path();
}
inline inline path current_path(system::error_code& ec)
path current_path(system::error_code& ec) {return detail::current_path(&ec);} {
return detail::current_path(&ec);
}
inline inline void current_path(path const& p)
void current_path(const path& p) {detail::current_path(p);} {
detail::current_path(p);
}
inline inline void current_path(path const& p, system::error_code& ec) BOOST_NOEXCEPT
void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);} {
detail::current_path(p, &ec);
}
inline inline path absolute(path const& p, path const& base = current_path())
path absolute(const path& p, const path& base=current_path()) {return detail::absolute(p, base);} {
inline return detail::absolute(p, base);
path absolute(const path& p, system::error_code& ec) }
inline path absolute(path const& p, system::error_code& ec)
{ {
path base = current_path(ec); path base = current_path(ec);
if (ec) if (ec)
return path(); return path();
return detail::absolute(p, base, &ec); return detail::absolute(p, base, &ec);
} }
inline
path absolute(const path& p, const path& base, system::error_code& ec) {return detail::absolute(p, base, &ec);}
inline inline path absolute(path const& p, path const& base, system::error_code& ec)
path canonical(const path& p, const path& base=current_path()) {
{return detail::canonical(p, base);} return detail::absolute(p, base, &ec);
inline }
path canonical(const path& p, system::error_code& ec)
inline path canonical(path const& p, path const& base = current_path())
{
return detail::canonical(p, base);
}
inline path canonical(path const& p, system::error_code& ec)
{ {
path base = current_path(ec); path base = current_path(ec);
if (ec) if (ec)
return path(); return path();
return detail::canonical(p, base, &ec); return detail::canonical(p, base, &ec);
} }
inline
path canonical(const path& p, const path& base, system::error_code& ec) inline path canonical(path const& p, path const& base, system::error_code& ec)
{return detail::canonical(p, base, &ec);} {
return detail::canonical(p, base, &ec);
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline inline path complete(path const& p)
path complete(const path& p)
{ {
return absolute(p, initial_path()); return absolute(p, initial_path());
} }
inline inline path complete(path const& p, path const& base)
path complete(const path& p, const path& base)
{ {
return absolute(p, base); return absolute(p, base);
} }
#endif #endif
inline inline void copy(path const& from, path const& to)
void copy(const path& from, const path& to)
{ {
detail::copy(from, to, static_cast< unsigned int >(copy_options::none)); detail::copy(from, to, static_cast< unsigned int >(copy_options::none));
} }
inline
void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT inline void copy(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{ {
detail::copy(from, to, static_cast< unsigned int >(copy_options::none), &ec); detail::copy(from, to, static_cast< unsigned int >(copy_options::none), &ec);
} }
inline
void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options) inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
{ {
detail::copy(from, to, static_cast< unsigned int >(options)); detail::copy(from, to, static_cast< unsigned int >(options));
} }
inline
void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{ {
detail::copy(from, to, static_cast< unsigned int >(options), &ec); detail::copy(from, to, static_cast< unsigned int >(options), &ec);
} }
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline inline void copy_directory(path const& from, path const& to)
void copy_directory(const path& from, const path& to) {
{detail::copy_directory(from, to);} detail::copy_directory(from, to);
inline }
void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{detail::copy_directory(from, to, &ec);} inline void copy_directory(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{
detail::copy_directory(from, to, &ec);
}
#endif #endif
inline
bool copy_file(const path& from, const path& to) inline bool copy_file(path const& from, path const& to)
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none)); return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none));
} }
inline
bool copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT inline bool copy_file(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none), &ec); return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none), &ec);
} }
inline
bool copy_file(const path& from, const path& to, // See ticket #2925 inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_options) options) BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(options)); return detail::copy_file(from, to, static_cast< unsigned int >(options));
} }
inline
bool copy_file(const path& from, const path& to, // See ticket #2925 inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec); return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
} }
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline inline bool copy_file(path const& from, path const& to, // See ticket #2925
bool copy_file(const path& from, const path& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_option) options) BOOST_SCOPED_ENUM_NATIVE(copy_option) options)
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(options)); return detail::copy_file(from, to, static_cast< unsigned int >(options));
} }
inline
bool copy_file(const path& from, const path& to, // See ticket #2925 inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_option) options, system::error_code& ec) BOOST_NOEXCEPT BOOST_SCOPED_ENUM_NATIVE(copy_option) options, system::error_code& ec) BOOST_NOEXCEPT
{ {
return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec); return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
} }
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
void copy_symlink(const path& existing_symlink,
const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);}
inline inline void copy_symlink(path const& existing_symlink, path const& new_symlink)
void copy_symlink(const path& existing_symlink, const path& new_symlink, {
system::error_code& ec) BOOST_NOEXCEPT detail::copy_symlink(existing_symlink, new_symlink);
{detail::copy_symlink(existing_symlink, new_symlink, &ec);} }
inline
bool create_directories(const path& p) {return detail::create_directories(p);}
inline inline void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::create_directories(p, &ec);} detail::copy_symlink(existing_symlink, new_symlink, &ec);
inline }
bool create_directory(const path& p) {return detail::create_directory(p, 0);}
inline inline bool create_directories(path const& p)
bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::create_directory(p, 0, &ec);} return detail::create_directories(p);
inline }
bool create_directory(const path& p, const path& existing)
{return detail::create_directory(p, &existing);}
inline
bool create_directory(const path& p, const path& existing, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directory(p, &existing, &ec);}
inline
void create_directory_symlink(const path& to, const path& from)
{detail::create_directory_symlink(to, from);}
inline
void create_directory_symlink(const path& to, const path& from, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_directory_symlink(to, from, &ec);}
inline
void create_hard_link(const path& to, const path& new_hard_link) {detail::create_hard_link(to, new_hard_link);}
inline inline bool create_directories(path const& p, system::error_code& ec) BOOST_NOEXCEPT
void create_hard_link(const path& to, const path& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT {
{detail::create_hard_link(to, new_hard_link, &ec);} return detail::create_directories(p, &ec);
inline }
void create_symlink(const path& to, const path& new_symlink) {detail::create_symlink(to, new_symlink);}
inline inline bool create_directory(path const& p)
void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT {
{detail::create_symlink(to, new_symlink, &ec);} return detail::create_directory(p, 0);
inline }
bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
inline inline bool create_directory(path const& p, system::error_code& ec) BOOST_NOEXCEPT
bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::equivalent(p1, p2, &ec);} return detail::create_directory(p, 0, &ec);
inline }
boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
inline inline bool create_directory(path const& p, path const& existing)
boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::file_size(p, &ec);} return detail::create_directory(p, &existing);
inline }
boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
inline inline bool create_directory(path const& p, path const& existing, system::error_code& ec) BOOST_NOEXCEPT
boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::hard_link_count(p, &ec);} return detail::create_directory(p, &existing, &ec);
inline }
std::time_t creation_time(const path& p) { return detail::creation_time(p); }
inline inline void create_directory_symlink(path const& to, path const& from)
std::time_t creation_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{ return detail::creation_time(p, &ec); } detail::create_directory_symlink(to, from);
inline }
std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
inline inline void create_directory_symlink(path const& to, path const& from, system::error_code& ec) BOOST_NOEXCEPT
std::time_t last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::last_write_time(p, &ec);} detail::create_directory_symlink(to, from, &ec);
inline }
void last_write_time(const path& p, const std::time_t new_time)
{detail::last_write_time(p, new_time);}
inline
void last_write_time(const path& p, const std::time_t new_time,
system::error_code& ec) BOOST_NOEXCEPT
{detail::last_write_time(p, new_time, &ec);}
inline
void permissions(const path& p, perms prms)
{detail::permissions(p, prms);}
inline
void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
{detail::permissions(p, prms, &ec);}
inline inline void create_hard_link(path const& to, path const& new_hard_link)
path read_symlink(const path& p) {return detail::read_symlink(p);} {
detail::create_hard_link(to, new_hard_link);
}
inline inline void create_hard_link(path const& to, path const& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
path read_symlink(const path& p, system::error_code& ec) {
{return detail::read_symlink(p, &ec);} detail::create_hard_link(to, new_hard_link, &ec);
}
inline inline void create_symlink(path const& to, path const& new_symlink)
bool remove(const path& p) {return detail::remove(p);} {
detail::create_symlink(to, new_symlink);
}
inline inline void create_symlink(path const& to, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::remove(p, &ec);} detail::create_symlink(to, new_symlink, &ec);
}
inline inline bool equivalent(path const& p1, path const& p2)
boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);} {
return detail::equivalent(p1, p2);
}
inline inline bool equivalent(path const& p1, path const& p2, system::error_code& ec) BOOST_NOEXCEPT
boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::remove_all(p, &ec);} return detail::equivalent(p1, p2, &ec);
inline }
void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
inline inline boost::uintmax_t file_size(path const& p)
void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT {
{detail::rename(old_p, new_p, &ec);} return detail::file_size(p);
inline // name suggested by Scott McMurray }
void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
inline inline boost::uintmax_t file_size(path const& p, system::error_code& ec) BOOST_NOEXCEPT
void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT {
{detail::resize_file(p, size, &ec);} return detail::file_size(p, &ec);
inline }
path relative(const path& p, const path& base=current_path())
{return detail::relative(p, base);} inline boost::uintmax_t hard_link_count(path const& p)
inline {
path relative(const path& p, system::error_code& ec) return detail::hard_link_count(p);
}
inline boost::uintmax_t hard_link_count(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::hard_link_count(p, &ec);
}
inline std::time_t creation_time(path const& p)
{
return detail::creation_time(p);
}
inline std::time_t creation_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::creation_time(p, &ec);
}
inline std::time_t last_write_time(path const& p)
{
return detail::last_write_time(p);
}
inline std::time_t last_write_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::last_write_time(p, &ec);
}
inline void last_write_time(path const& p, const std::time_t new_time)
{
detail::last_write_time(p, new_time);
}
inline void last_write_time(path const& p, const std::time_t new_time, system::error_code& ec) BOOST_NOEXCEPT
{
detail::last_write_time(p, new_time, &ec);
}
inline void permissions(path const& p, perms prms)
{
detail::permissions(p, prms);
}
inline void permissions(path const& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
{
detail::permissions(p, prms, &ec);
}
inline path read_symlink(path const& p)
{
return detail::read_symlink(p);
}
inline path read_symlink(path const& p, system::error_code& ec)
{
return detail::read_symlink(p, &ec);
}
inline bool remove(path const& p)
{
return detail::remove(p);
}
inline bool remove(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::remove(p, &ec);
}
inline boost::uintmax_t remove_all(path const& p)
{
return detail::remove_all(p);
}
inline boost::uintmax_t remove_all(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::remove_all(p, &ec);
}
inline void rename(path const& old_p, path const& new_p)
{
detail::rename(old_p, new_p);
}
inline void rename(path const& old_p, path const& new_p, system::error_code& ec) BOOST_NOEXCEPT
{
detail::rename(old_p, new_p, &ec);
}
// name suggested by Scott McMurray
inline void resize_file(path const& p, uintmax_t size)
{
detail::resize_file(p, size);
}
inline void resize_file(path const& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
{
detail::resize_file(p, size, &ec);
}
inline path relative(path const& p, path const& base = current_path())
{
return detail::relative(p, base);
}
inline path relative(path const& p, system::error_code& ec)
{ {
path base = current_path(ec); path base = current_path(ec);
if (ec) if (ec)
return path(); return path();
return detail::relative(p, base, &ec); return detail::relative(p, base, &ec);
} }
inline
path relative(const path& p, const path& base, system::error_code& ec)
{return detail::relative(p, base, &ec);}
inline
space_info space(const path& p) {return detail::space(p);}
inline inline path relative(path const& p, path const& base, system::error_code& ec)
space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT {
{return detail::space(p, &ec);} return detail::relative(p, base, &ec);
}
inline space_info space(path const& p)
{
return detail::space(p);
}
inline space_info space(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::space(p, &ec);
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool symbolic_link_exists(const path& p) inline bool symbolic_link_exists(path const& p)
{ return is_symlink(filesystem::symlink_status(p)); } {
return is_symlink(filesystem::symlink_status(p));
}
#endif #endif
inline inline path system_complete(path const& p)
path system_complete(const path& p) {return detail::system_complete(p);} {
return detail::system_complete(p);
}
inline inline path system_complete(path const& p, system::error_code& ec)
path system_complete(const path& p, system::error_code& ec) {
{return detail::system_complete(p, &ec);} return detail::system_complete(p, &ec);
inline }
path temp_directory_path() {return detail::temp_directory_path();}
inline inline path temp_directory_path()
path temp_directory_path(system::error_code& ec) {
{return detail::temp_directory_path(&ec);} return detail::temp_directory_path();
inline }
path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
{return detail::unique_path(p);}
inline
path unique_path(const path& p, system::error_code& ec)
{return detail::unique_path(p, &ec);}
inline
path weakly_canonical(const path& p) {return detail::weakly_canonical(p);}
inline inline path temp_directory_path(system::error_code& ec)
path weakly_canonical(const path& p, system::error_code& ec) {
{return detail::weakly_canonical(p, &ec);} return detail::temp_directory_path(&ec);
}
inline path unique_path(path const& p = "%%%%-%%%%-%%%%-%%%%")
{
return detail::unique_path(p);
}
inline path unique_path(path const& p, system::error_code& ec)
{
return detail::unique_path(p, &ec);
}
inline path weakly_canonical(path const& p)
{
return detail::weakly_canonical(p);
}
inline path weakly_canonical(path const& p, system::error_code& ec)
{
return detail::weakly_canonical(p, &ec);
}
// test helper -----------------------------------------------------------------------// // test helper -----------------------------------------------------------------------//
@ -548,4 +711,5 @@ BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
} // namespace boost } // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_OPERATIONS_HPP #endif // BOOST_FILESYSTEM3_OPERATIONS_HPP

View File

@ -43,10 +43,8 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
namespace path_detail // intentionally don't use filesystem::detail to not bring internal Boost.Filesystem functions into ADL via path_constants namespace path_detail // intentionally don't use filesystem::detail to not bring internal Boost.Filesystem functions into ADL via path_constants
{ {
@ -90,15 +88,12 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
> >
{ {
public: public:
// value_type is the character type used by the operating system API to // value_type is the character type used by the operating system API to
// represent paths. // represent paths.
typedef path_constants_base::value_type value_type; typedef path_constants_base::value_type value_type;
typedef std::basic_string< value_type > string_type; typedef std::basic_string< value_type > string_type;
typedef std::codecvt<wchar_t, char, typedef std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type;
std::mbstate_t> codecvt_type;
// ----- character encoding conversions ----- // ----- character encoding conversions -----
@ -158,19 +153,17 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// ----- constructors ----- // ----- constructors -----
path() BOOST_NOEXCEPT {} path() BOOST_NOEXCEPT {}
path(const path& p) : m_pathname(p.m_pathname) {} path(path const& p) : m_pathname(p.m_pathname) {}
template< class Source > template< class Source >
path(Source const& source, path(Source const& source, typename boost::enable_if< path_traits::is_pathable< typename boost::decay< Source >::type > >::type* = 0)
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type> >::type* =0)
{ {
path_traits::dispatch(source, m_pathname); path_traits::dispatch(source, m_pathname);
} }
path(const value_type* s) : m_pathname(s) {} path(const value_type* s) : m_pathname(s) {}
path(value_type* s) : m_pathname(s) {} path(value_type* s) : m_pathname(s) {}
path(const string_type& s) : m_pathname(s) {} path(string_type const& s) : m_pathname(s) {}
path(string_type& s) : m_pathname(s) {} path(string_type& s) : m_pathname(s) {}
// As of October 2015 the interaction between noexcept and =default is so troublesome // As of October 2015 the interaction between noexcept and =default is so troublesome
@ -178,13 +171,18 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// functions. GCC is not even consistent for the same release on different platforms. // functions. GCC is not even consistent for the same release on different platforms.
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
path(path&& p) BOOST_NOEXCEPT : m_pathname(std::move(p.m_pathname)) {} path(path&& p) BOOST_NOEXCEPT : m_pathname(std::move(p.m_pathname))
{
}
path& operator=(path&& p) BOOST_NOEXCEPT path& operator=(path&& p) BOOST_NOEXCEPT
{ m_pathname = std::move(p.m_pathname); return *this; } {
m_pathname = std::move(p.m_pathname);
return *this;
}
#endif #endif
template< class Source > template< class Source >
path(Source const& source, const codecvt_type& cvt) path(Source const& source, codecvt_type const& cvt)
{ {
path_traits::dispatch(source, m_pathname, cvt); path_traits::dispatch(source, m_pathname, cvt);
} }
@ -195,35 +193,32 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
if (begin != end) if (begin != end)
{ {
// convert requires contiguous string, so copy // convert requires contiguous string, so copy
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname);
} }
} }
template< class InputIterator > template< class InputIterator >
path(InputIterator begin, InputIterator end, const codecvt_type& cvt) path(InputIterator begin, InputIterator end, codecvt_type const& cvt)
{ {
if (begin != end) if (begin != end)
{ {
// convert requires contiguous string, so copy // convert requires contiguous string, so copy
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt);
} }
} }
// ----- assignments ----- // ----- assignments -----
path& operator=(const path& p) path& operator=(path const& p)
{ {
m_pathname = p.m_pathname; m_pathname = p.m_pathname;
return *this; return *this;
} }
template< class Source > template< class Source >
typename boost::enable_if<path_traits::is_pathable< typename boost::enable_if< path_traits::is_pathable< typename boost::decay< Source >::type >, path& >::type
typename boost::decay<Source>::type>, path&>::type
operator=(Source const& source) operator=(Source const& source)
{ {
m_pathname.clear(); m_pathname.clear();
@ -234,16 +229,37 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// value_type overloads // value_type overloads
path& operator=(const value_type* ptr) // required in case ptr overlaps *this path& operator=(const value_type* ptr) // required in case ptr overlaps *this
{m_pathname = ptr; return *this;} {
path& operator=(value_type* ptr) // required in case ptr overlaps *this m_pathname = ptr;
{m_pathname = ptr; return *this;} return *this;
path& operator=(const string_type& s) {m_pathname = s; return *this;} }
path& operator=(string_type& s) {m_pathname = s; return *this;}
path& operator=(value_type* ptr) // required in case ptr overlaps *this
{
m_pathname = ptr;
return *this;
}
path& operator=(string_type const& s)
{
m_pathname = s;
return *this;
}
path& operator=(string_type& s)
{
m_pathname = s;
return *this;
}
path& assign(const value_type* ptr, codecvt_type const&) // required in case ptr overlaps *this
{
m_pathname = ptr;
return *this;
}
path& assign(const value_type* ptr, const codecvt_type&) // required in case ptr overlaps *this
{m_pathname = ptr; return *this;}
template< class Source > template< class Source >
path& assign(Source const& source, const codecvt_type& cvt) path& assign(Source const& source, codecvt_type const& cvt)
{ {
m_pathname.clear(); m_pathname.clear();
path_traits::dispatch(source, m_pathname, cvt); path_traits::dispatch(source, m_pathname, cvt);
@ -256,21 +272,19 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
m_pathname.clear(); m_pathname.clear();
if (begin != end) if (begin != end)
{ {
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname);
} }
return *this; return *this;
} }
template< class InputIterator > template< class InputIterator >
path& assign(InputIterator begin, InputIterator end, const codecvt_type& cvt) path& assign(InputIterator begin, InputIterator end, codecvt_type const& cvt)
{ {
m_pathname.clear(); m_pathname.clear();
if (begin != end) if (begin != end)
{ {
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt);
} }
return *this; return *this;
@ -279,20 +293,47 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// ----- concatenation ----- // ----- concatenation -----
template< class Source > template< class Source >
typename boost::enable_if<path_traits::is_pathable< typename boost::enable_if< path_traits::is_pathable< typename boost::decay< Source >::type >, path& >::type
typename boost::decay<Source>::type>, path&>::type
operator+=(Source const& source) operator+=(Source const& source)
{ {
return concat(source); return concat(source);
} }
// value_type overloads. Same rationale as for constructors above // value_type overloads. Same rationale as for constructors above
path& operator+=(const path& p) { m_pathname += p.m_pathname; return *this; } path& operator+=(path const& p)
path& operator+=(const value_type* ptr) { m_pathname += ptr; return *this; } {
path& operator+=(value_type* ptr) { m_pathname += ptr; return *this; } m_pathname += p.m_pathname;
path& operator+=(const string_type& s) { m_pathname += s; return *this; } return *this;
path& operator+=(string_type& s) { m_pathname += s; return *this; } }
path& operator+=(value_type c) { m_pathname += c; return *this; }
path& operator+=(const value_type* ptr)
{
m_pathname += ptr;
return *this;
}
path& operator+=(value_type* ptr)
{
m_pathname += ptr;
return *this;
}
path& operator+=(string_type const& s)
{
m_pathname += s;
return *this;
}
path& operator+=(string_type& s)
{
m_pathname += s;
return *this;
}
path& operator+=(value_type c)
{
m_pathname += c;
return *this;
}
template< class CharT > template< class CharT >
typename boost::enable_if< boost::is_integral< CharT >, path& >::type typename boost::enable_if< boost::is_integral< CharT >, path& >::type
@ -312,7 +353,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
} }
template< class Source > template< class Source >
path& concat(Source const& source, const codecvt_type& cvt) path& concat(Source const& source, codecvt_type const& cvt)
{ {
path_traits::dispatch(source, m_pathname, cvt); path_traits::dispatch(source, m_pathname, cvt);
return *this; return *this;
@ -323,19 +364,17 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
{ {
if (begin == end) if (begin == end)
return *this; return *this;
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname);
return *this; return *this;
} }
template< class InputIterator > template< class InputIterator >
path& concat(InputIterator begin, InputIterator end, const codecvt_type& cvt) path& concat(InputIterator begin, InputIterator end, codecvt_type const& cvt)
{ {
if (begin == end) if (begin == end)
return *this; return *this;
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt);
return *this; return *this;
} }
@ -345,11 +384,10 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// if a separator is added, it is the preferred separator for the platform; // if a separator is added, it is the preferred separator for the platform;
// slash for POSIX, backslash for Windows // slash for POSIX, backslash for Windows
BOOST_FILESYSTEM_DECL path& operator/=(const path& p); BOOST_FILESYSTEM_DECL path& operator/=(path const& p);
template< class Source > template< class Source >
typename boost::enable_if<path_traits::is_pathable< typename boost::enable_if< path_traits::is_pathable< typename boost::decay< Source >::type >, path& >::type
typename boost::decay<Source>::type>, path&>::type
operator/=(Source const& source) operator/=(Source const& source)
{ {
return append(source); return append(source);
@ -360,7 +398,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
{ {
return this->operator/=(const_cast< const value_type* >(ptr)); return this->operator/=(const_cast< const value_type* >(ptr));
} }
path& operator/=(const string_type& s) { return this->operator/=(path(s)); } path& operator/=(string_type const& s) { return this->operator/=(path(s)); }
path& operator/=(string_type& s) { return this->operator/=(path(s)); } path& operator/=(string_type& s) { return this->operator/=(path(s)); }
path& append(const value_type* ptr) // required in case ptr overlaps *this path& append(const value_type* ptr) // required in case ptr overlaps *this
@ -369,7 +407,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
return *this; return *this;
} }
path& append(const value_type* ptr, const codecvt_type&) // required in case ptr overlaps *this path& append(const value_type* ptr, codecvt_type const&) // required in case ptr overlaps *this
{ {
this->operator/=(ptr); this->operator/=(ptr);
return *this; return *this;
@ -379,7 +417,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
path& append(Source const& source); path& append(Source const& source);
template< class Source > template< class Source >
path& append(Source const& source, const codecvt_type& cvt); path& append(Source const& source, codecvt_type const& cvt);
template< class InputIterator > template< class InputIterator >
path& append(InputIterator begin, InputIterator end); path& append(InputIterator begin, InputIterator end);
@ -391,7 +429,11 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
void clear() BOOST_NOEXCEPT { m_pathname.clear(); } void clear() BOOST_NOEXCEPT { m_pathname.clear(); }
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
path& make_preferred() { return *this; } // POSIX no effect path& make_preferred()
{
// No effect on POSIX
return *this;
}
#else // BOOST_WINDOWS_API #else // BOOST_WINDOWS_API
BOOST_FILESYSTEM_DECL path& make_preferred(); // change slashes to backslashes BOOST_FILESYSTEM_DECL path& make_preferred(); // change slashes to backslashes
#endif #endif
@ -429,48 +471,44 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
String string() const; String string() const;
template< class String > template< class String >
String string(const codecvt_type& cvt) const; String string(codecvt_type const& cvt) const;
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::string string() const std::string string() const
{ {
std::string tmp; std::string tmp;
if (!m_pathname.empty()) if (!m_pathname.empty())
path_traits::convert(m_pathname.c_str(), m_pathname.c_str()+m_pathname.size(), path_traits::convert(m_pathname.c_str(), m_pathname.c_str() + m_pathname.size(), tmp);
tmp);
return tmp; return tmp;
} }
std::string string(const codecvt_type& cvt) const std::string string(codecvt_type const& cvt) const
{ {
std::string tmp; std::string tmp;
if (!m_pathname.empty()) if (!m_pathname.empty())
path_traits::convert(m_pathname.c_str(), m_pathname.c_str()+m_pathname.size(), path_traits::convert(m_pathname.c_str(), m_pathname.c_str() + m_pathname.size(), tmp, cvt);
tmp, cvt);
return tmp; return tmp;
} }
// string_type is std::wstring, so there is no conversion // string_type is std::wstring, so there is no conversion
const std::wstring& wstring() const { return m_pathname; } const std::wstring& wstring() const { return m_pathname; }
const std::wstring& wstring(const codecvt_type&) const { return m_pathname; } const std::wstring& wstring(codecvt_type const&) const { return m_pathname; }
#else // BOOST_POSIX_API #else // BOOST_POSIX_API
// string_type is std::string, so there is no conversion // string_type is std::string, so there is no conversion
const std::string& string() const { return m_pathname; } const std::string& string() const { return m_pathname; }
const std::string& string(const codecvt_type&) const { return m_pathname; } const std::string& string(codecvt_type const&) const { return m_pathname; }
std::wstring wstring() const std::wstring wstring() const
{ {
std::wstring tmp; std::wstring tmp;
if (!m_pathname.empty()) if (!m_pathname.empty())
path_traits::convert(m_pathname.c_str(), m_pathname.c_str()+m_pathname.size(), path_traits::convert(m_pathname.c_str(), m_pathname.c_str() + m_pathname.size(), tmp);
tmp);
return tmp; return tmp;
} }
std::wstring wstring(const codecvt_type& cvt) const std::wstring wstring(codecvt_type const& cvt) const
{ {
std::wstring tmp; std::wstring tmp;
if (!m_pathname.empty()) if (!m_pathname.empty())
path_traits::convert(m_pathname.c_str(), m_pathname.c_str()+m_pathname.size(), path_traits::convert(m_pathname.c_str(), m_pathname.c_str() + m_pathname.size(), tmp, cvt);
tmp, cvt);
return tmp; return tmp;
} }
#endif #endif
@ -490,25 +528,25 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
String generic_string() const; String generic_string() const;
template< class String > template< class String >
String generic_string(const codecvt_type& cvt) const; String generic_string(codecvt_type const& cvt) const;
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::string generic_string() const { return generic_path().string(); } std::string generic_string() const { return generic_path().string(); }
std::string generic_string(const codecvt_type& cvt) const { return generic_path().string(cvt); } std::string generic_string(codecvt_type const& cvt) const { return generic_path().string(cvt); }
std::wstring generic_wstring() const { return generic_path().wstring(); } std::wstring generic_wstring() const { return generic_path().wstring(); }
std::wstring generic_wstring(const codecvt_type&) const { return generic_wstring(); } std::wstring generic_wstring(codecvt_type const&) const { return generic_wstring(); }
#else // BOOST_POSIX_API #else // BOOST_POSIX_API
// On POSIX-like systems, the generic format is the same as the native format // On POSIX-like systems, the generic format is the same as the native format
const std::string& generic_string() const { return m_pathname; } const std::string& generic_string() const { return m_pathname; }
const std::string& generic_string(const codecvt_type&) const { return m_pathname; } const std::string& generic_string(codecvt_type const&) const { return m_pathname; }
std::wstring generic_wstring() const { return this->wstring(); } std::wstring generic_wstring() const { return this->wstring(); }
std::wstring generic_wstring(const codecvt_type& cvt) const { return this->wstring(cvt); } std::wstring generic_wstring(codecvt_type const& cvt) const { return this->wstring(cvt); }
#endif #endif
// ----- compare ----- // ----- compare -----
BOOST_FILESYSTEM_DECL int compare(const path& p) const BOOST_NOEXCEPT; // generic, lexicographical BOOST_FILESYSTEM_DECL int compare(path const& p) const BOOST_NOEXCEPT; // generic, lexicographical
int compare(const std::string& s) const { return compare(path(s)); } int compare(std::string const& s) const { return compare(path(s)); }
int compare(const value_type* s) const { return compare(path(s)); } int compare(const value_type* s) const { return compare(path(s)); }
// ----- decomposition ----- // ----- decomposition -----
@ -582,7 +620,8 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
// recently deprecated functions supplied by default // recently deprecated functions supplied by default
path& normalize() { path& normalize()
{
path tmp(lexically_normal()); path tmp(lexically_normal());
m_pathname.swap(tmp.m_pathname); m_pathname.swap(tmp.m_pathname);
return *this; return *this;
@ -622,18 +661,18 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
private: private:
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(push) // Save warning settings #pragma warning(push) // Save warning settings
#pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>' #pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
#endif // needs to have dll-interface... #endif // needs to have dll-interface...
/* /*
m_pathname has the type, encoding, and format required by the native * m_pathname has the type, encoding, and format required by the native
operating system. Thus for POSIX and Windows there is no conversion for * operating system. Thus for POSIX and Windows there is no conversion for
passing m_pathname.c_str() to the O/S API or when obtaining a path from the * passing m_pathname.c_str() to the O/S API or when obtaining a path from the
O/S API. POSIX encoding is unspecified other than for dot and slash * O/S API. POSIX encoding is unspecified other than for dot and slash
characters; POSIX just treats paths as a sequence of bytes. Windows * characters; POSIX just treats paths as a sequence of bytes. Windows
encoding is UCS-2 or UTF-16 depending on the version. * encoding is UCS-2 or UTF-16 depending on the version.
*/ */
string_type m_pathname; // Windows: as input; backslashes NOT converted to slashes, string_type m_pathname; // Windows: as input; backslashes NOT converted to slashes,
// slashes NOT converted to backslashes // slashes NOT converted to backslashes
@ -651,7 +690,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// Was qualified; como433beta8 reports: // Was qualified; como433beta8 reports:
// warning #427-D: qualified name is not allowed in member declaration // warning #427-D: qualified name is not allowed in member declaration
friend class iterator; friend class iterator;
friend bool operator<(const path& lhs, const path& rhs); friend bool operator<(path const& lhs, path const& rhs);
// see path::iterator::increment/decrement comment below // see path::iterator::increment/decrement comment below
static BOOST_FILESYSTEM_DECL void m_path_iterator_increment(path::iterator& it); static BOOST_FILESYSTEM_DECL void m_path_iterator_increment(path::iterator& it);
@ -659,16 +698,11 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
}; // class path }; // class path
namespace detail namespace detail {
{ BOOST_FILESYSTEM_DECL int lex_compare(path::iterator first1, path::iterator last1, path::iterator first2, path::iterator last2);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL const path& dot_path();
int lex_compare(path::iterator first1, path::iterator last1, BOOST_FILESYSTEM_DECL const path& dot_dot_path();
path::iterator first2, path::iterator last2); } // namespace detail
BOOST_FILESYSTEM_DECL
const path& dot_path();
BOOST_FILESYSTEM_DECL
const path& dot_dot_path();
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
typedef path wpath; typedef path wpath;
@ -678,11 +712,12 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// class path::iterator // // class path::iterator //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class path::iterator class path::iterator :
: public boost::iterator_facade< public boost::iterator_facade<
path::iterator, path::iterator,
path const, const path,
boost::bidirectional_traversal_tag > boost::bidirectional_traversal_tag
>
{ {
private: private:
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
@ -703,28 +738,33 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
void increment() { m_path_iterator_increment(*this); } void increment() { m_path_iterator_increment(*this); }
void decrement() { m_path_iterator_decrement(*this); } void decrement() { m_path_iterator_decrement(*this); }
path m_element; // current element private:
const path* m_path_ptr; // path being iterated over // current element
string_type::size_type m_pos; // position of m_element in path m_element;
// m_path_ptr->m_pathname. // path being iterated over
const path* m_path_ptr;
// position of m_element in m_path_ptr->m_pathname.
// if m_element is implicit dot, m_pos is the // if m_element is implicit dot, m_pos is the
// position of the last separator in the path. // position of the last separator in the path.
// end() iterator is indicated by // end() iterator is indicated by
// m_pos == m_path_ptr->m_pathname.size() // m_pos == m_path_ptr->m_pathname.size()
}; // path::iterator string_type::size_type m_pos;
};
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// class path::reverse_iterator // // class path::reverse_iterator //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class path::reverse_iterator class path::reverse_iterator :
: public boost::iterator_facade< public boost::iterator_facade<
path::reverse_iterator, path::reverse_iterator,
path const, const path,
boost::bidirectional_traversal_tag > boost::bidirectional_traversal_tag
>
{ {
public: public:
explicit reverse_iterator(iterator itr) : m_itr(itr) explicit reverse_iterator(iterator itr) :
m_itr(itr)
{ {
if (itr != itr.m_path_ptr->begin()) if (itr != itr.m_path_ptr->begin())
m_element = *--itr; m_element = *--itr;
@ -736,6 +776,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
const path& dereference() const { return m_element; } const path& dereference() const { return m_element; }
bool equal(const reverse_iterator& rhs) const { return m_itr == rhs.m_itr; } bool equal(const reverse_iterator& rhs) const { return m_itr == rhs.m_itr; }
void increment() void increment()
{ {
--m_itr; --m_itr;
@ -745,16 +786,17 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
m_element = *--tmp; m_element = *--tmp;
} }
} }
void decrement() void decrement()
{ {
m_element = *m_itr; m_element = *m_itr;
++m_itr; ++m_itr;
} }
private:
iterator m_itr; iterator m_itr;
path m_element; path m_element;
};
}; // path::reverse_iterator
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// // // //
@ -764,30 +806,81 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// std::lexicographical_compare would infinitely recurse because path iterators // std::lexicographical_compare would infinitely recurse because path iterators
// yield paths, so provide a path aware version // yield paths, so provide a path aware version
inline bool lexicographical_compare(path::iterator first1, path::iterator last1, inline bool lexicographical_compare(path::iterator first1, path::iterator last1, path::iterator first2, path::iterator last2)
path::iterator first2, path::iterator last2) {
{ return detail::lex_compare(first1, last1, first2, last2) < 0; } return detail::lex_compare(first1, last1, first2, last2) < 0;
}
inline bool operator==(const path& lhs, const path& rhs) {return lhs.compare(rhs) == 0;} inline bool operator==(path const& lhs, path const& rhs)
inline bool operator==(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) == 0;} {
inline bool operator==(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) == 0;} return lhs.compare(rhs) == 0;
inline bool operator==(const path& lhs, const path::value_type* rhs) {return lhs.compare(rhs) == 0;} }
inline bool operator==(const path::value_type* lhs, const path& rhs) {return rhs.compare(lhs) == 0;}
inline bool operator!=(const path& lhs, const path& rhs) {return lhs.compare(rhs) != 0;} inline bool operator==(path const& lhs, path::string_type const& rhs)
inline bool operator!=(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) != 0;} {
inline bool operator!=(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) != 0;} return lhs.compare(rhs) == 0;
inline bool operator!=(const path& lhs, const path::value_type* rhs) {return lhs.compare(rhs) != 0;} }
inline bool operator!=(const path::value_type* lhs, const path& rhs) {return rhs.compare(lhs) != 0;}
inline bool operator==(path::string_type const& lhs, path const& rhs)
{
return rhs.compare(lhs) == 0;
}
inline bool operator==(path const& lhs, const path::value_type* rhs)
{
return lhs.compare(rhs) == 0;
}
inline bool operator==(const path::value_type* lhs, path const& rhs)
{
return rhs.compare(lhs) == 0;
}
inline bool operator!=(path const& lhs, path const& rhs)
{
return lhs.compare(rhs) != 0;
}
inline bool operator!=(path const& lhs, path::string_type const& rhs)
{
return lhs.compare(rhs) != 0;
}
inline bool operator!=(path::string_type const& lhs, path const& rhs)
{
return rhs.compare(lhs) != 0;
}
inline bool operator!=(path const& lhs, const path::value_type* rhs)
{
return lhs.compare(rhs) != 0;
}
inline bool operator!=(const path::value_type* lhs, path const& rhs)
{
return rhs.compare(lhs) != 0;
}
// TODO: why do == and != have additional overloads, but the others don't? // TODO: why do == and != have additional overloads, but the others don't?
inline bool operator<(const path& lhs, const path& rhs) {return lhs.compare(rhs) < 0;} inline bool operator<(path const& lhs, path const& rhs)
inline bool operator<=(const path& lhs, const path& rhs) {return !(rhs < lhs);} {
inline bool operator> (const path& lhs, const path& rhs) {return rhs < lhs;} return lhs.compare(rhs) < 0;
inline bool operator>=(const path& lhs, const path& rhs) {return !(lhs < rhs);} }
inline bool operator<=(path const& lhs, path const& rhs)
{
return !(rhs < lhs);
}
inline bool operator>(path const& lhs, path const& rhs)
{
return rhs < lhs;
}
inline bool operator>=(path const& lhs, path const& rhs)
{
return !(lhs < rhs);
}
inline std::size_t hash_value(const path& x) BOOST_NOEXCEPT inline std::size_t hash_value(path const& x) BOOST_NOEXCEPT
{ {
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::size_t seed = 0; std::size_t seed = 0;
@ -799,16 +892,20 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
#endif #endif
} }
inline void swap(path& lhs, path& rhs) BOOST_NOEXCEPT { lhs.swap(rhs); } inline void swap(path& lhs, path& rhs) BOOST_NOEXCEPT
{
lhs.swap(rhs);
}
inline path operator/(const path& lhs, const path& rhs) inline path operator/(path const& lhs, path const& rhs)
{ {
path p = lhs; path p = lhs;
p /= rhs; p /= rhs;
return p; return p;
} }
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
inline path operator/(path&& lhs, const path& rhs) inline path operator/(path&& lhs, path const& rhs)
{ {
lhs /= rhs; lhs /= rhs;
return std::move(lhs); return std::move(lhs);
@ -821,10 +918,9 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
template< class Char, class Traits > template< class Char, class Traits >
inline std::basic_ostream< Char, Traits >& inline std::basic_ostream< Char, Traits >&
operator<<(std::basic_ostream<Char, Traits>& os, const path& p) operator<<(std::basic_ostream< Char, Traits >& os, path const& p)
{ {
return os return os << boost::io::quoted(p.template string< std::basic_string< Char > >(), static_cast< Char >('&'));
<< boost::io::quoted(p.template string<std::basic_string<Char> >(), static_cast<Char>('&'));
} }
template< class Char, class Traits > template< class Char, class Traits >
@ -842,20 +938,19 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// These functions are holdovers from version 1. It isn't clear they have much // These functions are holdovers from version 1. It isn't clear they have much
// usefulness, or how to generalize them for later versions. // usefulness, or how to generalize them for later versions.
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name); BOOST_FILESYSTEM_DECL bool portable_posix_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name); BOOST_FILESYSTEM_DECL bool windows_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name); BOOST_FILESYSTEM_DECL bool portable_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name); BOOST_FILESYSTEM_DECL bool portable_directory_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name); BOOST_FILESYSTEM_DECL bool portable_file_name(std::string const& name);
BOOST_FILESYSTEM_DECL bool native(const std::string & name); BOOST_FILESYSTEM_DECL bool native(std::string const& name);
namespace detail {
namespace detail
{
// For POSIX, is_directory_separator() and is_element_separator() are identical since // For POSIX, is_directory_separator() and is_element_separator() are identical since
// a forward slash is the only valid directory separator and also the only valid // a forward slash is the only valid directory separator and also the only valid
// element separator. For Windows, forward slash and back slash are the possible // element separator. For Windows, forward slash and back slash are the possible
// directory separators, but colon (example: "c:foo") is also an element separator. // directory separators, but colon (example: "c:foo") is also an element separator.
inline bool is_directory_separator(path::value_type c) BOOST_NOEXCEPT inline bool is_directory_separator(path::value_type c) BOOST_NOEXCEPT
{ {
return c == path::separator return c == path::separator
@ -864,6 +959,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
#endif #endif
; ;
} }
inline bool is_element_separator(path::value_type c) BOOST_NOEXCEPT inline bool is_element_separator(path::value_type c) BOOST_NOEXCEPT
{ {
return c == path::separator return c == path::separator
@ -872,14 +968,21 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
#endif #endif
; ;
} }
} // namespace detail } // namespace detail
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// class path miscellaneous function implementations // // class path miscellaneous function implementations //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
inline path::reverse_iterator path::rbegin() const { return reverse_iterator(end()); } inline path::reverse_iterator path::rbegin() const
inline path::reverse_iterator path::rend() const { return reverse_iterator(begin()); } {
return reverse_iterator(end());
}
inline path::reverse_iterator path::rend() const
{
return reverse_iterator(begin());
}
inline bool path::filename_is_dot() const inline bool path::filename_is_dot() const
{ {
@ -891,8 +994,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
inline bool path::filename_is_dot_dot() const inline bool path::filename_is_dot_dot() const
{ {
return size() >= 2 && m_pathname[size()-1] == dot && m_pathname[size()-2] == dot return size() >= 2 && m_pathname[size() - 1] == dot && m_pathname[size() - 2] == dot && (m_pathname.size() == 2 || detail::is_element_separator(m_pathname[size() - 3]));
&& (m_pathname.size() == 2 || detail::is_element_separator(m_pathname[size()-3]));
// use detail::is_element_separator() rather than detail::is_directory_separator // use detail::is_element_separator() rather than detail::is_directory_separator
// to deal with "c:.." edge case on Windows when ':' acts as a separator // to deal with "c:.." edge case on Windows when ':' acts as a separator
} }
@ -907,8 +1009,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
if (begin == end) if (begin == end)
return *this; return *this;
string_type::size_type sep_pos(m_append_separator_if_needed()); string_type::size_type sep_pos(m_append_separator_if_needed());
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname);
if (sep_pos) if (sep_pos)
m_erase_redundant_separator(sep_pos); m_erase_redundant_separator(sep_pos);
@ -916,13 +1017,12 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
} }
template< class InputIterator > template< class InputIterator >
path& path::append(InputIterator begin, InputIterator end, const codecvt_type& cvt) path& path::append(InputIterator begin, InputIterator end, codecvt_type const& cvt)
{ {
if (begin == end) if (begin == end)
return *this; return *this;
string_type::size_type sep_pos(m_append_separator_if_needed()); string_type::size_type sep_pos(m_append_separator_if_needed());
std::basic_string<typename std::iterator_traits<InputIterator>::value_type> std::basic_string< typename std::iterator_traits< InputIterator >::value_type > seq(begin, end);
seq(begin, end);
path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt); path_traits::convert(seq.c_str(), seq.c_str() + seq.size(), m_pathname, cvt);
if (sep_pos) if (sep_pos)
m_erase_redundant_separator(sep_pos); m_erase_redundant_separator(sep_pos);
@ -942,7 +1042,7 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
} }
template< class Source > template< class Source >
path& path::append(Source const& source, const codecvt_type& cvt) path& path::append(Source const& source, codecvt_type const& cvt)
{ {
if (path_traits::empty(source)) if (path_traits::empty(source))
return *this; return *this;
@ -957,45 +1057,60 @@ namespace path_detail // intentionally don't use filesystem::detail to not bring
// class path member template specializations // // class path member template specializations //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
template <> inline template<>
std::string path::string<std::string>() const inline std::string path::string< std::string >() const
{ return string(); } {
return string();
}
template <> inline template<>
std::wstring path::string<std::wstring>() const inline std::wstring path::string< std::wstring >() const
{ return wstring(); } {
return wstring();
}
template <> inline template<>
std::string path::string<std::string>(const codecvt_type& cvt) const inline std::string path::string< std::string >(const codecvt_type& cvt) const
{ return string(cvt); } {
return string(cvt);
}
template <> inline template<>
std::wstring path::string<std::wstring>(const codecvt_type& cvt) const inline std::wstring path::string< std::wstring >(const codecvt_type& cvt) const
{ return wstring(cvt); } {
return wstring(cvt);
}
template <> inline template<>
std::string path::generic_string<std::string>() const inline std::string path::generic_string< std::string >() const
{ return generic_string(); } {
return generic_string();
}
template <> inline template<>
std::wstring path::generic_string<std::wstring>() const inline std::wstring path::generic_string< std::wstring >() const
{ return generic_wstring(); } {
return generic_wstring();
}
template <> inline template<>
std::string path::generic_string<std::string>(const codecvt_type& cvt) const inline std::string path::generic_string< std::string >(codecvt_type const& cvt) const
{ return generic_string(cvt); } {
return generic_string(cvt);
}
template <> inline template<>
std::wstring path::generic_string<std::wstring>(const codecvt_type& cvt) const inline std::wstring path::generic_string< std::wstring >(codecvt_type const& cvt) const
{ return generic_wstring(cvt); } {
return generic_wstring(cvt);
}
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// path_traits convert function implementations // // path_traits convert function implementations //
// requiring path::codecvt() be visable // // requiring path::codecvt() be visable //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace path_traits namespace path_traits { // without codecvt
{ // without codecvt
inline void convert(const char* from, inline void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
@ -1011,19 +1126,18 @@ namespace path_traits
convert(from, from_end, to, path::codecvt()); convert(from, from_end, to, path::codecvt());
} }
inline void convert(const char* from, inline void convert(const char* from, std::wstring& to)
std::wstring & to)
{ {
BOOST_ASSERT(!!from); BOOST_ASSERT(!!from);
convert(from, 0, to, path::codecvt()); convert(from, 0, to, path::codecvt());
} }
inline void convert(const wchar_t* from, inline void convert(const wchar_t* from, std::string& to)
std::string & to)
{ {
BOOST_ASSERT(!!from); BOOST_ASSERT(!!from);
convert(from, 0, to, path::codecvt()); convert(from, 0, to, path::codecvt());
} }
} // namespace path_traits } // namespace path_traits
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost

View File

@ -21,6 +21,7 @@
#include <boost/type_traits/decay.hpp> #include <boost/type_traits/decay.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/core/enable_if.hpp> #include <boost/core/enable_if.hpp>
#include <cstddef>
#include <cwchar> // for mbstate_t #include <cwchar> // for mbstate_t
#include <string> #include <string>
#include <vector> #include <vector>
@ -32,7 +33,8 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost { namespace filesystem { namespace boost {
namespace filesystem {
BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category(); BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
// uses std::codecvt_base::result used for error codes: // uses std::codecvt_base::result used for error codes:
@ -54,39 +56,101 @@ namespace path_traits {
// is_pathable type trait; allows disabling over-agressive class path member templates // is_pathable type trait; allows disabling over-agressive class path member templates
template< class T > template< class T >
struct is_pathable { static const bool value = false; }; struct is_pathable
{
static const bool value = false;
};
template<> struct is_pathable<char*> { static const bool value = true; }; template<>
template<> struct is_pathable<const char*> { static const bool value = true; }; struct is_pathable< char* >
template<> struct is_pathable<wchar_t*> { static const bool value = true; }; {
template<> struct is_pathable<const wchar_t*> { static const bool value = true; }; static const bool value = true;
template<> struct is_pathable<std::string> { static const bool value = true; }; };
template<> struct is_pathable<std::wstring> { static const bool value = true; };
template<> struct is_pathable<std::vector<char> > { static const bool value = true; }; template<>
template<> struct is_pathable<std::vector<wchar_t> > { static const bool value = true; }; struct is_pathable< const char* >
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; }; static const bool value = true;
template<> struct is_pathable<directory_entry> { 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;
};
// Pathable empty // Pathable empty
template <class Container> inline template< class Container >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "bool" at some future date (2012?) // conforming compilers. Replace by plain "bool" at some future date (2012?)
typename boost::disable_if< boost::is_array< Container >, bool >::type typename boost::disable_if< boost::is_array< Container >, bool >::type
empty(const Container & c) empty(Container const& c)
{ return c.begin() == c.end(); } {
return c.begin() == c.end();
}
template <class T> inline template< class T >
bool empty(T * const & c_str) inline bool empty(T* const& c_str)
{ {
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
return !*c_str; return !*c_str;
} }
template <typename T, size_t N> inline template< typename T, std::size_t N >
bool empty(T (&x)[N]) inline bool empty(T (&x)[N])
{ return !x[0]; } {
return !x[0];
}
// value types differ ---------------------------------------------------------------// // value types differ ---------------------------------------------------------------//
// //
@ -97,28 +161,20 @@ namespace path_traits {
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const char* from, void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
std::wstring & to, std::wstring& to, codecvt_type const& cvt);
const codecvt_type& cvt);
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to, std::string& to, codecvt_type const& cvt);
const codecvt_type& cvt);
inline inline void convert(const char* from, std::wstring& to, codecvt_type const& cvt)
void convert(const char* from,
std::wstring & to,
const codecvt_type& cvt)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
convert(from, 0, to, cvt); convert(from, 0, to, cvt);
} }
inline inline void convert(const wchar_t* from, std::string& to, codecvt_type const& cvt)
void convert(const wchar_t* from,
std::string & to,
const codecvt_type& cvt)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
convert(from, 0, to, cvt); convert(from, 0, to, cvt);
@ -126,41 +182,30 @@ namespace path_traits {
// without codecvt // without codecvt
inline inline void convert(const char* from,
void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
std::wstring& to); std::wstring& to);
inline inline void convert(const wchar_t* from,
void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS const wchar_t* from_end, // 0 for null terminated MBCS
std::string& to); std::string& to);
inline inline void convert(const char* from, std::wstring& to);
void convert(const char* from,
std::wstring & to);
inline inline void convert(const wchar_t* from, std::string& to);
void convert(const wchar_t* from,
std::string & to);
// value types same -----------------------------------------------------------------// // value types same -----------------------------------------------------------------//
// char with codecvt // char with codecvt
inline inline void convert(const char* from, const char* from_end, std::string& to, codecvt_type const&)
void convert(const char* from, const char* from_end, std::string & to,
const codecvt_type&)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const char* from, std::string& to, codecvt_type const&)
void convert(const char* from,
std::string & to,
const codecvt_type&)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
@ -168,19 +213,14 @@ namespace path_traits {
// wchar_t with codecvt // wchar_t with codecvt
inline inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to, codecvt_type const&)
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to,
const codecvt_type&)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const wchar_t* from, std::wstring& to, codecvt_type const&)
void convert(const wchar_t* from,
std::wstring & to,
const codecvt_type&)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
@ -188,16 +228,14 @@ namespace path_traits {
// char without codecvt // char without codecvt
inline inline void convert(const char* from, const char* from_end, std::string& to)
void convert(const char* from, const char* from_end, std::string & to)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const char* from, std::string& to)
void convert(const char* from, std::string & to)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
@ -205,16 +243,14 @@ namespace path_traits {
// wchar_t without codecvt // wchar_t without codecvt
inline inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to)
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
BOOST_ASSERT(from_end); BOOST_ASSERT(from_end);
to.append(from, from_end); to.append(from, from_end);
} }
inline inline void convert(const wchar_t* from, std::wstring& to)
void convert(const wchar_t* from, std::wstring & to)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
to += from; to += from;
@ -223,63 +259,64 @@ namespace path_traits {
// Source dispatch -----------------------------------------------------------------// // Source dispatch -----------------------------------------------------------------//
// contiguous containers with codecvt // contiguous containers with codecvt
template <class U> inline template< class U >
void dispatch(const std::string& c, U& to, const codecvt_type& cvt) inline void dispatch(std::string const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt) inline void dispatch(std::wstring const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt) inline void dispatch(std::vector< char > const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt) inline void dispatch(std::vector< wchar_t > const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt); convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
} }
// contiguous containers without codecvt // contiguous containers without codecvt
template <class U> inline template< class U >
void dispatch(const std::string& c, U& to) inline void dispatch(std::string const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::wstring& c, U& to) inline void dispatch(std::wstring const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<char>& c, U& to) inline void dispatch(std::vector< char > const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
template <class U> inline template< class U >
void dispatch(const std::vector<wchar_t>& c, U& to) inline void dispatch(std::vector< wchar_t > const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to); convert(&*c.begin(), &*c.begin() + c.size(), to);
} }
// non-contiguous containers with codecvt // non-contiguous containers with codecvt
template <class Container, class U> inline template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?) // conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if< boost::is_array< Container >, void >::type typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(const Container & c, U& to, const codecvt_type& cvt) dispatch(Container const& c, U& to, codecvt_type const& cvt)
{ {
if (!c.empty()) if (!c.empty())
{ {
@ -289,8 +326,8 @@ namespace path_traits {
} }
// c_str // c_str
template <class T, class U> inline template< class T, class U >
void dispatch(T * const & c_str, U& to, const codecvt_type& cvt) inline void dispatch(T* const& c_str, U& to, codecvt_type const& cvt)
{ {
// std::cout << "dispatch() const T *\n"; // std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
@ -301,20 +338,21 @@ namespace path_traits {
// contain a string smaller than the array size. // contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de, void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring& to, std::wstring& to,
#else #else
std::string& to, std::string& to,
#endif #endif
const codecvt_type&); codecvt_type const&);
// non-contiguous containers without codecvt // non-contiguous containers without codecvt
template <class Container, class U> inline template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?) // conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if< boost::is_array< Container >, void >::type typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(const Container & c, U& to) dispatch(Container const& c, U& to)
{ {
if (!c.empty()) if (!c.empty())
{ {
@ -324,8 +362,8 @@ namespace path_traits {
} }
// c_str // c_str
template <class T, class U> inline template< class T, class U >
void dispatch(T * const & c_str, U& to) inline void dispatch(T* const& c_str, U& to)
{ {
// std::cout << "dispatch() const T *\n"; // std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str); BOOST_ASSERT(c_str);
@ -336,7 +374,7 @@ namespace path_traits {
// contain a string smaller than the array size. // contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de, void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring& to std::wstring& to
#else #else
@ -344,8 +382,9 @@ namespace path_traits {
#endif #endif
); );
} // namespace path_traits
}}} // namespace boost::filesystem::path_traits } // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas

View File

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

View File

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

View File

@ -13,6 +13,7 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/directory.hpp> #include <boost/filesystem/directory.hpp>
#include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
@ -36,14 +37,13 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS+0 >= 0)\ #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS + 0 >= 0) && defined(_SC_THREAD_SAFE_FUNCTIONS) && \
&& defined(_SC_THREAD_SAFE_FUNCTIONS)\ !defined(__CYGWIN__) && \
&& !defined(__CYGWIN__)\ !(defined(linux) || defined(__linux) || defined(__linux__)) && \
&& !(defined(linux) || defined(__linux) || defined(__linux__))\ !defined(__ANDROID__) && \
&& !defined(__ANDROID__)\ (!defined(__hpux) || defined(_REENTRANT)) && \
&& (!defined(__hpux) || defined(_REENTRANT)) \ (!defined(_AIX) || defined(__THREAD_SAFE)) && \
&& (!defined(_AIX) || defined(__THREAD_SAFE))\ !defined(__wasm)
&& !defined(__wasm)
#define BOOST_FILESYSTEM_USE_READDIR_R #define BOOST_FILESYSTEM_USE_READDIR_R
#endif #endif
@ -63,8 +63,7 @@
// macros being tested come from dirent.h. // macros being tested come from dirent.h.
// //
// TODO: find out what macros indicate dirent::d_type present in more libraries // TODO: find out what macros indicate dirent::d_type present in more libraries
#if defined(BOOST_WINDOWS_API)\ #if defined(BOOST_WINDOWS_API) || defined(_DIRENT_HAVE_D_TYPE) // defined by GNU C library if d_type present
|| defined(_DIRENT_HAVE_D_TYPE)// defined by GNU C library if d_type present
#define BOOST_FILESYSTEM_STATUS_CACHE #define BOOST_FILESYSTEM_STATUS_CACHE
#endif #endif
@ -125,18 +124,20 @@ file_status directory_entry::get_symlink_status(system::error_code* ec) const
namespace path_traits { namespace path_traits {
void dispatch(const directory_entry& de, BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring& to, std::wstring& to,
#else #else
std::string& to, std::string& to,
#endif #endif
const codecvt_type&) codecvt_type const&)
{ {
to = de.path().native(); to = de.path().native();
} }
void dispatch(const directory_entry& de, BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::wstring& to std::wstring& to
#else #else
@ -203,9 +204,7 @@ inline std::size_t path_max()
#endif // BOOST_FILESYSTEM_USE_READDIR_R #endif // BOOST_FILESYSTEM_USE_READDIR_R
error_code dir_itr_first(void*& handle, void*& buffer, error_code dir_itr_first(void*& handle, void*& buffer, const char* dir, std::string& target, fs::file_status&, fs::file_status&)
const char* dir, std::string& target,
fs::file_status&, fs::file_status&)
{ {
if ((handle = ::opendir(dir)) == 0) if ((handle = ::opendir(dir)) == 0)
{ {
@ -255,8 +254,7 @@ inline int readdir_r_simulator(DIR* dirp, void*& buffer, struct dirent** result)
return 0; return 0;
} }
error_code dir_itr_increment(void*& handle, void*& buffer, error_code dir_itr_increment(void*& handle, void*& buffer, std::string& target, fs::file_status& sf, fs::file_status& symlink_sf)
std::string& target, fs::file_status& sf, fs::file_status& symlink_sf)
{ {
dirent* result = NULL; dirent* result = NULL;
int err = readdir_r_simulator(static_cast< DIR* >(handle), buffer, &result); int err = readdir_r_simulator(static_cast< DIR* >(handle), buffer, &result);
@ -294,29 +292,26 @@ error_code dir_itr_increment(void*& handle, void*& buffer,
#else // BOOST_WINDOWS_API #else // BOOST_WINDOWS_API
error_code dir_itr_first(void*& handle, const fs::path& dir, error_code dir_itr_first(void*& handle, fs::path const& dir, std::wstring& target, fs::file_status& sf, fs::file_status& symlink_sf)
std::wstring& target, fs::file_status& sf, fs::file_status& symlink_sf)
// Note: an empty root directory has no "." or ".." entries, so this // Note: an empty root directory has no "." or ".." entries, so this
// causes a ERROR_FILE_NOT_FOUND error which we do not considered an // causes a ERROR_FILE_NOT_FOUND error which we do not considered an
// error. It is treated as eof instead. // error. It is treated as eof instead.
{ {
// use a form of search Sebastian Martel reports will work with Win98 // use a form of search Sebastian Martel reports will work with Win98
std::wstring dirpath(dir.wstring()); std::wstring dirpath(dir.wstring());
dirpath += (dirpath.empty() dirpath += (dirpath.empty() || (dirpath[dirpath.size() - 1] != L'\\' && dirpath[dirpath.size() - 1] != L'/' && dirpath[dirpath.size() - 1] != L':')) ? L"\\*" : L"*";
|| (dirpath[dirpath.size()-1] != L'\\'
&& dirpath[dirpath.size()-1] != L'/'
&& dirpath[dirpath.size()-1] != L':'))? L"\\*" : L"*";
WIN32_FIND_DATAW data; WIN32_FIND_DATAW data;
if ((handle = ::FindFirstFileW(dirpath.c_str(), &data)) if ((handle = ::FindFirstFileW(dirpath.c_str(), &data)) == INVALID_HANDLE_VALUE)
== INVALID_HANDLE_VALUE)
{ {
handle = 0; // signal eof handle = 0; // signal eof
DWORD error = ::GetLastError(); DWORD error = ::GetLastError();
return error_code((error == ERROR_FILE_NOT_FOUND return error_code((error == ERROR_FILE_NOT_FOUND
// Windows Mobile returns ERROR_NO_MORE_FILES; see ticket #3551 // Windows Mobile returns ERROR_NO_MORE_FILES; see ticket #3551
|| error == ERROR_NO_MORE_FILES) || error == ERROR_NO_MORE_FILES) ?
? 0 : error, system_category() ); 0 :
error,
system_category());
} }
target = data.cFileName; target = data.cFileName;
if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@ -437,10 +432,9 @@ system::error_code dir_itr_close( // never throws
} }
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec) void directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec)
{ {
if (error(p.empty() ? not_found_error_code : 0, p, ec, if (error(p.empty() ? not_found_error_code : 0, p, ec, "boost::filesystem::directory_iterator::construct"))
"boost::filesystem::directory_iterator::construct"))
{ {
return; return;
} }
@ -475,8 +469,7 @@ void directory_iterator_construct(directory_iterator& it, const path& p, unsigne
if (result != make_error_condition(system::errc::permission_denied) || if (result != make_error_condition(system::errc::permission_denied) ||
(opts & static_cast< unsigned int >(directory_options::skip_permission_denied)) == 0u) (opts & static_cast< unsigned int >(directory_options::skip_permission_denied)) == 0u)
{ {
error(result.value(), p, error(result.value(), p, ec, "boost::filesystem::directory_iterator::construct");
ec, "boost::filesystem::directory_iterator::construct");
} }
return; return;
@ -536,9 +529,7 @@ void directory_iterator_increment(directory_iterator& it, system::error_code* ec
if (ec == NULL) if (ec == NULL)
{ {
BOOST_FILESYSTEM_THROW( BOOST_FILESYSTEM_THROW(
filesystem_error("boost::filesystem::directory_iterator::operator++", filesystem_error("boost::filesystem::directory_iterator::operator++", error_path, increment_ec));
error_path,
increment_ec));
} }
*ec = increment_ec; *ec = increment_ec;
return; return;
@ -577,7 +568,7 @@ void directory_iterator_increment(directory_iterator& it, system::error_code* ec
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec) void recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec)
{ {
if (ec) if (ec)
ec->clear(); ec->clear();
@ -748,8 +739,7 @@ inline push_directory_result recursive_directory_iterator_push_directory(detail:
if (BOOST_UNLIKELY(!!ec)) if (BOOST_UNLIKELY(!!ec))
{ {
if (ec == make_error_condition(system::errc::no_such_file_or_directory) && fs::is_symlink(symlink_stat) && if (ec == make_error_condition(system::errc::no_such_file_or_directory) && fs::is_symlink(symlink_stat) &&
(imp->m_options & static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks)) (imp->m_options & static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks)) == static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks))
== static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks))
{ {
// Skip dangling symlink and continue iteration on the current depth level // Skip dangling symlink and continue iteration on the current depth level
ec = error_code(); ec = error_code();

View File

@ -55,8 +55,8 @@ typedef boost::winapi::DWORD_ err_t;
// Implemented in exception.cpp // Implemented in exception.cpp
void emit_error(err_t error_num, system::error_code* ec, const char* message); void emit_error(err_t error_num, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message); void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message); void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message);
inline bool error(err_t error_num, system::error_code* ec, const char* message) inline bool error(err_t error_num, system::error_code* ec, const char* message)
{ {
@ -73,7 +73,7 @@ inline bool error(err_t error_num, system::error_code* ec, const char* message)
} }
} }
inline bool error(err_t error_num, const path& p, system::error_code* ec, const char* message) inline bool error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{ {
if (BOOST_LIKELY(!error_num)) if (BOOST_LIKELY(!error_num))
{ {
@ -88,7 +88,7 @@ inline bool error(err_t error_num, const path& p, system::error_code* ec, const
} }
} }
inline bool error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message) inline bool error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{ {
if (BOOST_LIKELY(!error_num)) if (BOOST_LIKELY(!error_num))
{ {

View File

@ -35,7 +35,7 @@ BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what
} }
} }
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, system::error_code ec) :
system::system_error(ec, what_arg) system::system_error(ec, what_arg)
{ {
try try
@ -48,7 +48,7 @@ BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what
} }
} }
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec) : BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
system::system_error(ec, what_arg) system::system_error(ec, what_arg)
{ {
try try
@ -80,7 +80,8 @@ BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NO
BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
{ {
if (m_imp_ptr.get()) try if (m_imp_ptr.get())
try
{ {
if (m_imp_ptr->m_what.empty()) if (m_imp_ptr->m_what.empty())
{ {
@ -109,7 +110,7 @@ BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_
return system::system_error::what(); return system::system_error::what();
} }
BOOST_FILESYSTEM_DECL const path& filesystem_error::get_empty_path() BOOST_NOEXCEPT BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() BOOST_NOEXCEPT
{ {
static const path empty_path; static const path empty_path;
return empty_path; return empty_path;
@ -125,7 +126,7 @@ void emit_error(err_t error_num, system::error_code* ec, const char* message)
ec->assign(error_num, system::system_category()); ec->assign(error_num, system::system_category());
} }
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message) void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{ {
if (!ec) if (!ec)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category()))); BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
@ -133,7 +134,7 @@ void emit_error(err_t error_num, const path& p, system::error_code* ec, const ch
ec->assign(error_num, system::system_category()); ec->assign(error_num, system::system_category());
} }
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message) void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{ {
if (ec == 0) if (ec == 0)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category()))); BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support #error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif #endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp> // for filesystem_error #include <boost/filesystem/operations.hpp> // for filesystem_error
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
@ -31,8 +32,7 @@
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
#include "windows_file_codecvt.hpp" #include "windows_file_codecvt.hpp"
#include <windows.h> #include <windows.h>
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) \ #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__)
|| defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__)
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp> #include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
#endif #endif
@ -56,8 +56,7 @@ using boost::system::error_code;
// // // //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace namespace {
{
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// miscellaneous class path helpers // // miscellaneous class path helpers //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
@ -87,18 +86,18 @@ namespace
#endif #endif
bool is_root_separator(const string_type& str, size_type pos);
// pos is position of the separator // pos is position of the separator
bool is_root_separator(string_type const& str, size_type pos);
size_type filename_pos(const string_type& str,
size_type end_pos); // end_pos is past-the-end position
// Returns: 0 if str itself is filename (or empty) // Returns: 0 if str itself is filename (or empty)
// end_pos is past-the-end position
size_type filename_pos(string_type const& str, size_type end_pos);
size_type root_directory_start(const string_type& path, size_type size);
// Returns: npos if no root_directory found // Returns: npos if no root_directory found
size_type root_directory_start(string_type const& path, size_type size);
void first_element( void first_element(
const string_type& src, string_type const& src,
size_type& element_pos, size_type& element_pos,
size_type& element_size, size_type& element_size,
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) // VC++ 7.1 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) // VC++ 7.1
@ -116,10 +115,8 @@ namespace
// // // //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
BOOST_FILESYSTEM_DECL path& path::operator/=(const path& p) BOOST_FILESYSTEM_DECL path& path::operator/=(const path& p)
{ {
@ -145,8 +142,7 @@ namespace filesystem
{ {
if (!*ptr) if (!*ptr)
return *this; return *this;
if (ptr >= m_pathname.data() if (ptr >= m_pathname.data() && ptr < m_pathname.data() + m_pathname.size()) // overlapping source
&& ptr < m_pathname.data() + m_pathname.size()) // overlapping source
{ {
path rhs(ptr); path rhs(ptr);
if (!detail::is_directory_separator(rhs.m_pathname[0])) if (!detail::is_directory_separator(rhs.m_pathname[0]))
@ -205,8 +201,7 @@ namespace filesystem
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
|| m_pathname[sep_pos + 1] == preferred_separator // or preferred_separator || m_pathname[sep_pos + 1] == preferred_separator // or preferred_separator
#endif #endif
) ))
)
{ {
m_pathname.erase(m_pathname.begin() + sep_pos); // erase the added separator m_pathname.erase(m_pathname.begin() + sep_pos); // erase the added separator
} }
@ -233,8 +228,7 @@ namespace filesystem
BOOST_FILESYSTEM_DECL path& path::remove_trailing_separator() BOOST_FILESYSTEM_DECL path& path::remove_trailing_separator()
{ {
if (!m_pathname.empty() if (!m_pathname.empty() && detail::is_directory_separator(m_pathname[m_pathname.size() - 1]))
&& detail::is_directory_separator(m_pathname[m_pathname.size() - 1]))
m_pathname.erase(m_pathname.end() - 1); m_pathname.erase(m_pathname.end() - 1);
return *this; return *this;
} }
@ -260,7 +254,8 @@ namespace filesystem
BOOST_FILESYSTEM_DECL path path::root_path() const BOOST_FILESYSTEM_DECL path path::root_path() const
{ {
path temp(root_name()); path temp(root_name());
if (!root_directory().empty()) temp.m_pathname += root_directory().c_str(); if (!root_directory().empty())
temp.m_pathname += root_directory().c_str();
return temp; return temp;
} }
@ -268,38 +263,39 @@ namespace filesystem
{ {
iterator itr(begin()); iterator itr(begin());
return (itr.m_pos != m_pathname.size() return
&& ( (
(itr.m_element.m_pathname.size() > 1 itr.m_pos != m_pathname.size() &&
&& detail::is_directory_separator(itr.m_element.m_pathname[0]) (
&& detail::is_directory_separator(itr.m_element.m_pathname[1])) (itr.m_element.m_pathname.size() > 1 && detail::is_directory_separator(itr.m_element.m_pathname[0]) && detail::is_directory_separator(itr.m_element.m_pathname[1]))
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
|| itr.m_element.m_pathname[itr.m_element.m_pathname.size() - 1] == colon || itr.m_element.m_pathname[itr.m_element.m_pathname.size() - 1] == colon
#endif #endif
)) )
? itr.m_element ) ? itr.m_element : path();
: path();
} }
BOOST_FILESYSTEM_DECL path path::root_directory() const BOOST_FILESYSTEM_DECL path path::root_directory() const
{ {
size_type pos(root_directory_start(m_pathname, m_pathname.size())); size_type pos(root_directory_start(m_pathname, m_pathname.size()));
return pos == string_type::npos ? path() : path(m_pathname.c_str() + pos, m_pathname.c_str() + pos + 1);
return pos == string_type::npos
? path()
: path(m_pathname.c_str() + pos, m_pathname.c_str() + pos + 1);
} }
BOOST_FILESYSTEM_DECL path path::relative_path() const BOOST_FILESYSTEM_DECL path path::relative_path() const
{ {
iterator itr(begin()); iterator itr(begin());
for (; itr.m_pos != m_pathname.size() for (;
&& (detail::is_directory_separator(itr.m_element.m_pathname[0]) itr.m_pos != m_pathname.size() &&
(
detail::is_directory_separator(itr.m_element.m_pathname[0])
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
|| itr.m_element.m_pathname[itr.m_element.m_pathname.size() - 1] == colon || itr.m_element.m_pathname[itr.m_element.m_pathname.size() - 1] == colon
#endif #endif
); ++itr) {} );
++itr)
{
}
return path(m_pathname.c_str() + itr.m_pos); return path(m_pathname.c_str() + itr.m_pos);
} }
@ -308,71 +304,55 @@ namespace filesystem
{ {
size_type end_pos(filename_pos(m_pathname, m_pathname.size())); size_type end_pos(filename_pos(m_pathname, m_pathname.size()));
bool filename_was_separator = !m_pathname.empty() bool filename_was_separator = !m_pathname.empty() && detail::is_directory_separator(m_pathname[end_pos]);
&& detail::is_directory_separator(m_pathname[end_pos]);
// skip separators unless root directory // skip separators unless root directory
size_type root_dir_pos(root_directory_start(m_pathname, end_pos)); size_type root_dir_pos(root_directory_start(m_pathname, end_pos));
for (; for (;
end_pos > 0 end_pos > 0 && (end_pos - 1) != root_dir_pos && detail::is_directory_separator(m_pathname[end_pos - 1]);
&& (end_pos-1) != root_dir_pos --end_pos)
&& detail::is_directory_separator(m_pathname[end_pos-1]) {
; }
--end_pos) {}
return (end_pos == 1 && root_dir_pos == 0 && filename_was_separator) return (end_pos == 1 && root_dir_pos == 0 && filename_was_separator) ? string_type::npos : end_pos;
? string_type::npos
: end_pos;
} }
BOOST_FILESYSTEM_DECL path path::parent_path() const BOOST_FILESYSTEM_DECL path path::parent_path() const
{ {
size_type end_pos(m_parent_path_end()); size_type end_pos(m_parent_path_end());
return end_pos == string_type::npos return end_pos == string_type::npos ? path() : path(m_pathname.c_str(), m_pathname.c_str() + end_pos);
? path()
: path(m_pathname.c_str(), m_pathname.c_str() + end_pos);
} }
BOOST_FILESYSTEM_DECL path path::filename() const BOOST_FILESYSTEM_DECL path path::filename() const
{ {
size_type pos(filename_pos(m_pathname, m_pathname.size())); size_type pos(filename_pos(m_pathname, m_pathname.size()));
return (!m_pathname.empty() return (!m_pathname.empty() && pos && detail::is_directory_separator(m_pathname[pos]) && !is_root_separator(m_pathname, pos)) ? detail::dot_path() : path(m_pathname.c_str() + pos);
&& pos
&& detail::is_directory_separator(m_pathname[pos])
&& !is_root_separator(m_pathname, pos))
? detail::dot_path()
: path(m_pathname.c_str() + pos);
} }
BOOST_FILESYSTEM_DECL path path::stem() const BOOST_FILESYSTEM_DECL path path::stem() const
{ {
path name(filename()); path name(filename());
if (name == detail::dot_path() || name == detail::dot_dot_path()) return name; if (name == detail::dot_path() || name == detail::dot_dot_path())
return name;
size_type pos(name.m_pathname.rfind(dot)); size_type pos(name.m_pathname.rfind(dot));
return pos == string_type::npos return pos == string_type::npos ? name : path(name.m_pathname.c_str(), name.m_pathname.c_str() + pos);
? name
: path(name.m_pathname.c_str(), name.m_pathname.c_str() + pos);
} }
BOOST_FILESYSTEM_DECL path path::extension() const BOOST_FILESYSTEM_DECL path path::extension() const
{ {
path name(filename()); path name(filename());
if (name == detail::dot_path() || name == detail::dot_dot_path()) return path(); if (name == detail::dot_path() || name == detail::dot_dot_path())
return path();
size_type pos(name.m_pathname.rfind(dot)); size_type pos(name.m_pathname.rfind(dot));
return pos == string_type::npos return pos == string_type::npos ? path() : path(name.m_pathname.c_str() + pos);
? path()
: path(name.m_pathname.c_str() + pos);
} }
// lexical operations --------------------------------------------------------------// // lexical operations --------------------------------------------------------------//
namespace detail namespace detail {
{
// C++14 provides a mismatch algorithm with four iterator arguments(), but earlier // C++14 provides a mismatch algorithm with four iterator arguments(), but earlier
// standard libraries didn't, so provide this needed functionality. // standard libraries didn't, so provide this needed functionality.
inline inline std::pair< path::iterator, path::iterator > mismatch(path::iterator it1, path::iterator it1end, path::iterator it2, path::iterator it2end)
std::pair<path::iterator, path::iterator> mismatch(path::iterator it1,
path::iterator it1end, path::iterator it2, path::iterator it2end)
{ {
for (; it1 != it1end && it2 != it2end && *it1 == *it2;) for (; it1 != it1end && it2 != it2end && *it1 == *it2;)
{ {
@ -381,7 +361,7 @@ namespace filesystem
} }
return std::make_pair(it1, it2); return std::make_pair(it1, it2);
} }
} } // namespace detail
BOOST_FILESYSTEM_DECL path path::lexically_relative(const path& base) const BOOST_FILESYSTEM_DECL path path::lexically_relative(const path& base) const
{ {
@ -428,32 +408,19 @@ namespace filesystem
for (iterator itr(start); itr != stop; ++itr) for (iterator itr(start); itr != stop; ++itr)
{ {
// ignore "." except at start and last // ignore "." except at start and last
if (itr->native().size() == 1 if (itr->native().size() == 1 && (itr->native())[0] == dot && itr != start && itr != last)
&& (itr->native())[0] == dot continue;
&& itr != start
&& itr != last) continue;
// ignore a name and following ".." // ignore a name and following ".."
if (!temp.empty() if (!temp.empty() && itr->native().size() == 2 && (itr->native())[0] == dot && (itr->native())[1] == dot) // dot dot
&& itr->native().size() == 2
&& (itr->native())[0] == dot
&& (itr->native())[1] == dot) // dot dot
{ {
string_type lf(temp.filename().native()); string_type lf(temp.filename().native());
string_type::size_type lf_size = lf.size(); string_type::size_type lf_size = lf.size();
if (lf_size > 0 if (lf_size > 0 && (lf_size != 1 || (lf[0] != dot && lf[0] != separator)) && (lf_size != 2 || (lf[0] != dot && lf[1] != dot
&& (lf_size != 1
|| (lf[0] != dot
&& lf[0] != separator))
&& (lf_size != 2
|| (lf[0] != dot
&& lf[1] != dot
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
&& lf[1] != colon && lf[1] != colon
#endif #endif
) )))
)
)
{ {
temp.remove_filename(); temp.remove_filename();
//// if not root directory, must also remove "/" if any //// if not root directory, must also remove "/" if any
@ -471,8 +438,7 @@ namespace filesystem
//} //}
iterator next(itr); iterator next(itr);
if (temp.empty() && ++next != stop if (temp.empty() && ++next != stop && next == last && *last == detail::dot_path())
&& next == last && *last == detail::dot_path())
{ {
temp /= detail::dot_path(); temp /= detail::dot_path();
} }
@ -497,16 +463,14 @@ namespace filesystem
// // // //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace namespace {
{
// is_root_separator ---------------------------------------------------------------// // is_root_separator ---------------------------------------------------------------//
bool is_root_separator(const string_type & str, size_type pos)
// pos is position of the separator // pos is position of the separator
bool is_root_separator(string_type const& str, size_type pos)
{ {
BOOST_ASSERT_MSG(!str.empty() && fs::detail::is_directory_separator(str[pos]), BOOST_ASSERT_MSG(!str.empty() && fs::detail::is_directory_separator(str[pos]), "precondition violation");
"precondition violation");
// subsequent logic expects pos to be for leftmost slash of a set // subsequent logic expects pos to be for leftmost slash of a set
while (pos > 0 && fs::detail::is_directory_separator(str[pos - 1])) while (pos > 0 && fs::detail::is_directory_separator(str[pos - 1]))
@ -523,8 +487,7 @@ namespace
#endif #endif
// "//" name "/" // "//" name "/"
if (pos < 3 || !fs::detail::is_directory_separator(str[0]) if (pos < 3 || !fs::detail::is_directory_separator(str[0]) || !fs::detail::is_directory_separator(str[1]))
|| !fs::detail::is_directory_separator(str[1]))
return false; return false;
return str.find_first_of(separators, 2) == pos; return str.find_first_of(separators, 2) == pos;
@ -532,14 +495,13 @@ namespace
// filename_pos --------------------------------------------------------------------// // filename_pos --------------------------------------------------------------------//
size_type filename_pos(const string_type & str, // end_pos is past-the-end position
size_type end_pos) // end_pos is past-the-end position
// return 0 if str itself is filename (or empty) // return 0 if str itself is filename (or empty)
size_type filename_pos(string_type const& str, size_type end_pos)
{ {
// case: "//" // case: "//"
if (end_pos == 2 if (end_pos == 2 && fs::detail::is_directory_separator(str[0]) && fs::detail::is_directory_separator(str[1]))
&& fs::detail::is_directory_separator(str[0]) return 0;
&& fs::detail::is_directory_separator(str[1])) return 0;
// case: ends in "/" // case: ends in "/"
if (end_pos && fs::detail::is_directory_separator(str[end_pos - 1])) if (end_pos && fs::detail::is_directory_separator(str[end_pos - 1]))
@ -555,35 +517,31 @@ namespace
return (pos == string_type::npos // path itself must be a filename (or empty) return (pos == string_type::npos // path itself must be a filename (or empty)
|| (pos == 1 && fs::detail::is_directory_separator(str[0]))) // or net || (pos == 1 && fs::detail::is_directory_separator(str[0]))) // or net
? 0 // so filename is entire string ?
: pos + 1; // or starts after delimiter 0 // so filename is entire string
:
pos + 1; // or starts after delimiter
} }
// root_directory_start ------------------------------------------------------------// // root_directory_start ------------------------------------------------------------//
size_type root_directory_start(const string_type & path, size_type size)
// return npos if no root_directory found // return npos if no root_directory found
size_type root_directory_start(string_type const& path, size_type size)
{ {
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
// case "c:/" // case "c:/"
if (size > 2 if (size > 2 && path[1] == colon && fs::detail::is_directory_separator(path[2]))
&& path[1] == colon return 2;
&& fs::detail::is_directory_separator(path[2])) return 2;
#endif #endif
// case "//" // case "//"
if (size == 2 if (size == 2 && fs::detail::is_directory_separator(path[0]) && fs::detail::is_directory_separator(path[1]))
&& fs::detail::is_directory_separator(path[0]) return string_type::npos;
&& fs::detail::is_directory_separator(path[1])) return string_type::npos;
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
// case "\\?\" // case "\\?\"
if (size > 4 if (size > 4 && fs::detail::is_directory_separator(path[0]) && fs::detail::is_directory_separator(path[1]) && path[2] == questionmark && fs::detail::is_directory_separator(path[3]))
&& fs::detail::is_directory_separator(path[0])
&& fs::detail::is_directory_separator(path[1])
&& path[2] == questionmark
&& fs::detail::is_directory_separator(path[3]))
{ {
string_type::size_type pos(path.find_first_of(separators, 4)); string_type::size_type pos(path.find_first_of(separators, 4));
return pos < size ? pos : string_type::npos; return pos < size ? pos : string_type::npos;
@ -591,44 +549,40 @@ namespace
#endif #endif
// case "//net {/}" // case "//net {/}"
if (size > 3 if (size > 3 && fs::detail::is_directory_separator(path[0]) && fs::detail::is_directory_separator(path[1]) && !fs::detail::is_directory_separator(path[2]))
&& fs::detail::is_directory_separator(path[0])
&& fs::detail::is_directory_separator(path[1])
&& !fs::detail::is_directory_separator(path[2]))
{ {
string_type::size_type pos(path.find_first_of(separators, 2)); string_type::size_type pos(path.find_first_of(separators, 2));
return pos < size ? pos : string_type::npos; return pos < size ? pos : string_type::npos;
} }
// case "/" // case "/"
if (size > 0 && fs::detail::is_directory_separator(path[0])) return 0; if (size > 0 && fs::detail::is_directory_separator(path[0]))
return 0;
return string_type::npos; return string_type::npos;
} }
// first_element --------------------------------------------------------------------// // first_element --------------------------------------------------------------------//
// sets pos and len of first element, excluding extra separators // sets pos and len of first element, excluding extra separators
// if src.empty(), sets pos,len, to 0,0. // if src.empty(), sets pos,len, to 0,0.
void first_element( void first_element(
const string_type & src, string_type const& src,
size_type& element_pos, size_type& element_pos,
size_type& element_size, size_type& element_size,
size_type size size_type size)
)
{ {
if (size == string_type::npos) size = src.size(); if (size == string_type::npos)
size = src.size();
element_pos = 0; element_pos = 0;
element_size = 0; element_size = 0;
if (src.empty()) return; if (src.empty())
return;
string_type::size_type cur(0); string_type::size_type cur(0);
// deal with // [network] // deal with // [network]
if (size >= 2 && fs::detail::is_directory_separator(src[0]) if (size >= 2 && fs::detail::is_directory_separator(src[0]) && fs::detail::is_directory_separator(src[1]) && (size == 2 || !fs::detail::is_directory_separator(src[2])))
&& fs::detail::is_directory_separator(src[1])
&& (size == 2
|| !fs::detail::is_directory_separator(src[2])))
{ {
cur += 2; cur += 2;
element_size += 2; element_size += 2;
@ -639,8 +593,7 @@ namespace
{ {
++element_size; ++element_size;
// bypass extra leading separators // bypass extra leading separators
while (cur+1 < size while (cur + 1 < size && fs::detail::is_directory_separator(src[cur + 1]))
&& fs::detail::is_directory_separator(src[cur+1]))
{ {
++cur; ++cur;
++element_pos; ++element_pos;
@ -663,30 +616,31 @@ namespace
} }
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
if (cur == size) return; if (cur == size)
return;
// include device delimiter // include device delimiter
if (src[cur] == colon) if (src[cur] == colon)
{ ++element_size; } {
++element_size;
}
#endif #endif
} }
} // unnamed namespace } // unnamed namespace
namespace boost {
namespace filesystem {
namespace detail {
namespace boost
{
namespace filesystem
{
namespace detail
{
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
int lex_compare(path::iterator first1, path::iterator last1, int lex_compare(path::iterator first1, path::iterator last1, path::iterator first2, path::iterator last2)
path::iterator first2, path::iterator last2)
{ {
for (; first1 != last1 && first2 != last2;) for (; first1 != last1 && first2 != last2;)
{ {
if (first1->native() < first2->native()) return -1; if (first1->native() < first2->native())
if (first2->native() < first1->native()) return 1; return -1;
if (first2->native() < first1->native())
return 1;
BOOST_ASSERT(first2->native() == first1->native()); BOOST_ASSERT(first2->native() == first1->native());
++first1; ++first1;
++first2; ++first2;
@ -717,7 +671,8 @@ namespace filesystem
#endif #endif
return dot_dot; return dot_dot;
} }
}
} // namespace detail
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -747,8 +702,7 @@ namespace filesystem
BOOST_FILESYSTEM_DECL void path::m_path_iterator_increment(path::iterator& it) BOOST_FILESYSTEM_DECL void path::m_path_iterator_increment(path::iterator& it)
{ {
BOOST_ASSERT_MSG(it.m_pos < it.m_path_ptr->m_pathname.size(), BOOST_ASSERT_MSG(it.m_pos < it.m_path_ptr->m_pathname.size(), "path::basic_iterator increment past end()");
"path::basic_iterator increment past end()");
// increment to position past current element; if current element is implicit dot, // increment to position past current element; if current element is implicit dot,
// this will cause it.m_pos to represent the end iterator // this will cause it.m_pos to represent the end iterator
@ -762,10 +716,10 @@ namespace filesystem
} }
// both POSIX and Windows treat paths that begin with exactly two separators specially // both POSIX and Windows treat paths that begin with exactly two separators specially
bool was_net(it.m_element.m_pathname.size() > 2 bool was_net = it.m_element.m_pathname.size() > 2 &&
&& detail::is_directory_separator(it.m_element.m_pathname[0]) detail::is_directory_separator(it.m_element.m_pathname[0]) &&
&& detail::is_directory_separator(it.m_element.m_pathname[1]) detail::is_directory_separator(it.m_element.m_pathname[1]) &&
&& !detail::is_directory_separator(it.m_element.m_pathname[2])); !detail::is_directory_separator(it.m_element.m_pathname[2]);
// process separator (Windows drive spec is only case not a separator) // process separator (Windows drive spec is only case not a separator)
if (detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos])) if (detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos]))
@ -783,13 +737,13 @@ namespace filesystem
} }
// skip separators until it.m_pos points to the start of the next element // skip separators until it.m_pos points to the start of the next element
while (it.m_pos != it.m_path_ptr->m_pathname.size() while (it.m_pos != it.m_path_ptr->m_pathname.size() && detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos]))
&& detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos])) {
{ ++it.m_pos; } ++it.m_pos;
}
// detect trailing separator, and treat it as ".", per POSIX spec // detect trailing separator, and treat it as ".", per POSIX spec
if (it.m_pos == it.m_path_ptr->m_pathname.size() if (it.m_pos == it.m_path_ptr->m_pathname.size() && !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos - 1))
&& !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1))
{ {
--it.m_pos; --it.m_pos;
it.m_element = detail::dot_path(); it.m_element = detail::dot_path();
@ -798,7 +752,7 @@ namespace filesystem
} }
// get m_element // get m_element
size_type end_pos(it.m_path_ptr->m_pathname.find_first_of(separators, it.m_pos)); size_type end_pos = it.m_path_ptr->m_pathname.find_first_of(separators, it.m_pos);
if (end_pos == string_type::npos) if (end_pos == string_type::npos)
end_pos = it.m_path_ptr->m_pathname.size(); end_pos = it.m_path_ptr->m_pathname.size();
it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos); it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
@ -808,30 +762,24 @@ namespace filesystem
{ {
BOOST_ASSERT_MSG(it.m_pos, "path::iterator decrement past begin()"); BOOST_ASSERT_MSG(it.m_pos, "path::iterator decrement past begin()");
size_type end_pos(it.m_pos); size_type end_pos = it.m_pos;
// if at end and there was a trailing non-root '/', return "." // if at end and there was a trailing non-root '/', return "."
if (it.m_pos == it.m_path_ptr->m_pathname.size() if (it.m_pos == it.m_path_ptr->m_pathname.size() && it.m_path_ptr->m_pathname.size() > 1 && detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos - 1]) && !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos - 1))
&& it.m_path_ptr->m_pathname.size() > 1
&& detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos-1])
&& !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1)
)
{ {
--it.m_pos; --it.m_pos;
it.m_element = detail::dot_path(); it.m_element = detail::dot_path();
return; return;
} }
size_type root_dir_pos(root_directory_start(it.m_path_ptr->m_pathname, end_pos)); size_type root_dir_pos = root_directory_start(it.m_path_ptr->m_pathname, end_pos);
// skip separators unless root directory // skip separators unless root directory
for ( for (;
; end_pos > 0 && (end_pos - 1) != root_dir_pos && detail::is_directory_separator(it.m_path_ptr->m_pathname[end_pos - 1]);
end_pos > 0 --end_pos)
&& (end_pos-1) != root_dir_pos {
&& detail::is_directory_separator(it.m_path_ptr->m_pathname[end_pos-1]) }
;
--end_pos) {}
it.m_pos = filename_pos(it.m_path_ptr->m_pathname, end_pos); it.m_pos = filename_pos(it.m_path_ptr->m_pathname, end_pos);
it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos); it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
@ -842,8 +790,7 @@ namespace filesystem
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
namespace namespace {
{
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// locale helpers // // locale helpers //
@ -870,8 +817,7 @@ namespace
#if defined(BOOST_WINDOWS_API) #if defined(BOOST_WINDOWS_API)
std::locale global_loc = std::locale(); std::locale global_loc = std::locale();
return std::locale(global_loc, new windows_file_codecvt); return std::locale(global_loc, new windows_file_codecvt);
# elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) \ #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__)
|| defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__)
// "All BSD system functions expect their string parameters to be in UTF-8 encoding // "All BSD system functions expect their string parameters to be in UTF-8 encoding
// and nothing else." See // and nothing else." See
// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html // http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html
@ -900,7 +846,6 @@ namespace
#endif #endif
} }
std::locale& path_locale()
// std::locale("") construction, needed on non-Apple POSIX systems, can throw // std::locale("") construction, needed on non-Apple POSIX systems, can throw
// (if environmental variables LC_MESSAGES or LANG are wrong, for example), so // (if environmental variables LC_MESSAGES or LANG are wrong, for example), so
// path_locale() provides lazy initialization via a local static to ensure that any // path_locale() provides lazy initialization via a local static to ensure that any
@ -908,6 +853,7 @@ namespace
// path_locale() is only called if path::codecvt() or path::imbue() are themselves // path_locale() is only called if path::codecvt() or path::imbue() are themselves
// actually called, ensuring that an exception will only be thrown if std::locale("") // actually called, ensuring that an exception will only be thrown if std::locale("")
// is really needed. // is really needed.
std::locale& path_locale()
{ {
// [locale] paragraph 6: Once a facet reference is obtained from a locale object by // [locale] paragraph 6: Once a facet reference is obtained from a locale object by
// calling use_facet<>, that reference remains usable, and the results from member // calling use_facet<>, that reference remains usable, and the results from member
@ -919,17 +865,15 @@ namespace
#endif #endif
return loc; return loc;
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// path::codecvt() and path::imbue() implementation // // path::codecvt() and path::imbue() implementation //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
// See comments above
BOOST_FILESYSTEM_DECL const path::codecvt_type& path::codecvt() BOOST_FILESYSTEM_DECL const path::codecvt_type& path::codecvt()
{ {

View File

@ -11,12 +11,16 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp> #include <boost/filesystem/path_traits.hpp>
#include <boost/system/system_error.hpp> #include <boost/system/system_error.hpp>
#include <boost/scoped_array.hpp> #include <boost/smart_ptr/scoped_array.hpp>
#include <boost/assert.hpp>
#include <string>
#include <locale> // for codecvt_base::result #include <locale> // for codecvt_base::result
#include <cstring> // for strlen #include <cstring> // for strlen
#include <cwchar> // for wcslen #include <cwchar> // for wcslen
#include <cstddef>
namespace pt = boost::filesystem::path_traits; namespace pt = boost::filesystem::path_traits;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -32,8 +36,7 @@ namespace bs = boost::system;
namespace { namespace {
const std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE; BOOST_CONSTEXPR_OR_CONST std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// // // //
@ -51,7 +54,7 @@ namespace {
const char* from_end, const char* from_end,
wchar_t* to, wchar_t* to_end, wchar_t* to, wchar_t* to_end,
std::wstring& target, std::wstring& target,
const pt::codecvt_type & cvt) pt::codecvt_type const& cvt)
{ {
//std::cout << std::hex //std::cout << std::hex
// << " from=" << std::size_t(from) // << " from=" << std::size_t(from)
@ -66,12 +69,10 @@ namespace {
std::codecvt_base::result res; std::codecvt_base::result res;
if ((res=cvt.in(state, from, from_end, from_next, if ((res = cvt.in(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
to, to_end, to_next)) != std::codecvt_base::ok)
{ {
//std::cout << " result is " << static_cast<int>(res) << std::endl; //std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to wstring"));
"boost::filesystem::path codecvt to wstring"));
} }
target.append(to, to_next); target.append(to, to_next);
} }
@ -85,7 +86,7 @@ namespace {
const wchar_t* from_end, const wchar_t* from_end,
char* to, char* to_end, char* to, char* to_end,
std::string& target, std::string& target,
const pt::codecvt_type & cvt) pt::codecvt_type const& cvt)
{ {
//std::cout << std::hex //std::cout << std::hex
// << " from=" << std::size_t(from) // << " from=" << std::size_t(from)
@ -100,12 +101,10 @@ namespace {
std::codecvt_base::result res; std::codecvt_base::result res;
if ((res=cvt.out(state, from, from_end, from_next, if ((res = cvt.out(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
to, to_end, to_next)) != std::codecvt_base::ok)
{ {
//std::cout << " result is " << static_cast<int>(res) << std::endl; //std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to string"));
"boost::filesystem::path codecvt to string"));
} }
target.append(to, to_next); target.append(to, to_next);
} }
@ -116,7 +115,9 @@ namespace {
// path_traits // // path_traits //
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace boost { namespace filesystem { namespace path_traits { namespace boost {
namespace filesystem {
namespace path_traits {
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// convert const char* to wstring // // convert const char* to wstring //
@ -125,8 +126,7 @@ namespace boost { namespace filesystem { namespace path_traits {
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const char* from, void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS const char* from_end, // 0 for null terminated MBCS
std::wstring & to, std::wstring& to, codecvt_type const& cvt)
const codecvt_type & cvt)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
@ -135,7 +135,8 @@ namespace boost { namespace filesystem { namespace path_traits {
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
@ -159,8 +160,7 @@ namespace boost { namespace filesystem { namespace path_traits {
BOOST_FILESYSTEM_DECL BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to, std::string& to, codecvt_type const& cvt)
const codecvt_type & cvt)
{ {
BOOST_ASSERT(from); BOOST_ASSERT(from);
@ -169,7 +169,8 @@ namespace boost { namespace filesystem { namespace path_traits {
from_end = from + std::wcslen(from); from_end = from + std::wcslen(from);
} }
if (from == from_end) return; if (from == from_end)
return;
// The codecvt length functions may not be implemented, and I don't really // The codecvt length functions may not be implemented, and I don't really
// understand them either. Thus this code is just a guess; if it turns // understand them either. Thus this code is just a guess; if it turns
@ -190,4 +191,7 @@ namespace boost { namespace filesystem { namespace path_traits {
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt); convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
} }
} }
}}} // namespace boost::filesystem::path_traits
} // namespace path_traits
} // namespace filesystem
} // namespace boost

View File

@ -11,21 +11,25 @@
#include "platform_config.hpp" #include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
#include <cstring> // SGI MIPSpro compilers need this #include <cstring> // SGI MIPSpro compilers need this
#include <string>
#ifdef BOOST_NO_STDC_NAMESPACE #ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::strerror; } namespace std {
using ::strerror;
}
#endif #endif
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
namespace namespace {
{
const char invalid_chars[] = BOOST_CONSTEXPR_OR_CONST char invalid_chars[] =
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
"<>:\"/\\|"; "<>:\"/\\|";
@ -38,10 +42,8 @@ namespace
} // unnamed namespace } // unnamed namespace
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
// name_check functions ----------------------------------------------// // name_check functions ----------------------------------------------//
@ -53,57 +55,34 @@ namespace boost
#else #else
BOOST_FILESYSTEM_DECL bool native(const std::string& name) BOOST_FILESYSTEM_DECL bool native(const std::string& name)
{ {
return !name.empty() return !name.empty() && name[0] != ' ' && name.find('/') == std::string::npos;
&& name[0] != ' '
&& name.find('/') == std::string::npos;
} }
#endif #endif
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string& name) BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string& name)
{ {
return !name.empty() return !name.empty() && name.find_first_not_of(valid_posix) == std::string::npos;
&& name.find_first_not_of(valid_posix) == std::string::npos;
} }
BOOST_FILESYSTEM_DECL bool windows_name(const std::string& name) BOOST_FILESYSTEM_DECL bool windows_name(const std::string& name)
{ {
return !name.empty() 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 == "..");
&& name[0] != ' '
&& name.find_first_of(windows_invalid_chars) == std::string::npos
&& *(name.end()-1) != ' '
&& (*(name.end()-1) != '.'
|| name.size() == 1 || name == "..");
} }
BOOST_FILESYSTEM_DECL bool portable_name(const std::string& name) BOOST_FILESYSTEM_DECL bool portable_name(const std::string& name)
{ {
return !name.empty() return !name.empty() && (name == "." || name == ".." || (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-'));
&& (name == "."
|| name == ".."
|| (windows_name(name)
&& portable_posix_name(name)
&& name[0] != '.' && name[0] != '-'));
} }
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string& name) BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string& name)
{ {
return return name == "." || name == ".." || (portable_name(name) && name.find('.') == std::string::npos);
name == "."
|| name == ".."
|| (portable_name(name)
&& name.find('.') == std::string::npos);
} }
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string& name) BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string& name)
{ {
std::string::size_type pos; std::string::size_type pos;
return return portable_name(name) && name != "." && name != ".." && ((pos = name.find('.')) == std::string::npos || (name.find('.', pos + 1) == std::string::npos && (pos + 5) > name.size()));
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

View File

@ -17,17 +17,23 @@
#include <boost/predef/os/bsd/free.h> #include <boost/predef/os/bsd/free.h>
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
#include <cerrno> #include <cerrno>
#include <stddef.h> #include <stddef.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef BOOST_HAS_UNISTD_H #ifdef BOOST_HAS_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
# if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || BOOST_LIB_C_CLOUDABI
#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> #include <stdlib.h>
#define BOOST_FILESYSTEM_HAS_ARC4RANDOM #define BOOST_FILESYSTEM_HAS_ARC4RANDOM
#endif #endif
# if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#if (defined(__linux__) || defined(__linux) || defined(linux)) && \
(!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#include <sys/syscall.h> #include <sys/syscall.h>
#if defined(SYS_getrandom) #if defined(SYS_getrandom)
#define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM #define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM
@ -40,12 +46,14 @@
#if __GLIBC_PREREQ(2, 25) #if __GLIBC_PREREQ(2, 25)
#define BOOST_FILESYSTEM_HAS_GETRANDOM #define BOOST_FILESYSTEM_HAS_GETRANDOM
#endif #endif
# endif #endif // BOOST_FILESYSTEM_HAS_GETRANDOM definition
#if defined(BOOST_FILESYSTEM_HAS_GETRANDOM) #if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
#include <sys/random.h> #include <sys/random.h>
#endif #endif
#endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28) #endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#else // BOOST_WINDOWS_API #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. // 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), // 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, // which makes it non-trivial for users to discover the libraries they need. This feature is deprecated and may be removed in the future,
@ -53,6 +61,7 @@
// Note that the library build system is the principal source of linking the library, which must work regardless of auto-linking. // 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/predef/platform.h>
#include <boost/winapi/basic_types.hpp> #include <boost/winapi/basic_types.hpp>
#if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project #if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project
#include <boost/winapi/error_codes.hpp> #include <boost/winapi/error_codes.hpp>
#include <boost/winapi/bcrypt.hpp> #include <boost/winapi/bcrypt.hpp>
@ -70,9 +79,11 @@
#endif #endif
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER) #endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT) #endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#endif
#endif // BOOST_POSIX_API
#include <cstddef> #include <cstddef>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include "error_handling.hpp" #include "error_handling.hpp"
@ -83,7 +94,9 @@
#endif #endif
#endif // defined(BOOST_POSIX_API) #endif // defined(BOOST_POSIX_API)
namespace boost { namespace filesystem { namespace detail { namespace boost {
namespace filesystem {
namespace detail {
namespace { namespace {
@ -264,9 +277,12 @@ path unique_path(const path& model, system::error_code* ec)
} }
} }
if (ec != 0) ec->clear(); if (ec != 0)
ec->clear();
return s; return s;
} }
}}} } // namespace detail
} // namespace filesystem
} // namespace boost

View File

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

View File

@ -27,8 +27,7 @@ std::codecvt_base::result windows_file_codecvt::do_in(
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count; int count;
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0)
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
{ {
return error; // conversion failed return error; // conversion failed
} }
@ -47,8 +46,7 @@ std::codecvt_base::result windows_file_codecvt::do_out(
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count; int count;
if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to), 0, 0)) == 0)
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
{ {
return error; // conversion failed return error; // conversion failed
} }

View File

@ -23,34 +23,25 @@
// // // //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class BOOST_SYMBOL_VISIBLE windows_file_codecvt class BOOST_SYMBOL_VISIBLE windows_file_codecvt :
: public std::codecvt< wchar_t, char, std::mbstate_t > public std::codecvt< wchar_t, char, std::mbstate_t >
{ {
public: public:
explicit windows_file_codecvt(std::size_t refs = 0) explicit windows_file_codecvt(std::size_t refs = 0) :
: std::codecvt<wchar_t, char, std::mbstate_t>(refs) {} std::codecvt< wchar_t, char, std::mbstate_t >(refs)
protected: {
}
protected:
virtual bool do_always_noconv() const throw() { return false; } virtual bool do_always_noconv() const throw() { return false; }
// seems safest to assume variable number of characters since we don't // seems safest to assume variable number of characters since we don't
// actually know what codepage is active // actually know what codepage is active
virtual int do_encoding() const throw() { return 0; } 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_in(std::mbstate_t& state, 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;
const char* from, const char* from_end, const char*& from_next, virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const; 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_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; } virtual int do_max_length() const throw() { return 0; }
}; };

View File

@ -24,8 +24,7 @@ namespace detail {
inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5]) inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5])
{ {
return return (p[0] == x1[0] || p[0] == x2[0]) &&
(p[0] == x1[0] || p[0] == x2[0]) &&
(p[1] == x1[1] || p[1] == x2[1]) && (p[1] == x1[1] || p[1] == x2[1]) &&
(p[2] == x1[2] || p[2] == x2[2]) && (p[2] == x1[2] || p[2] == x2[2]) &&
(p[3] == x1[3] || p[3] == x2[3]) && (p[3] == x1[3] || p[3] == x2[3]) &&
@ -39,10 +38,7 @@ inline boost::filesystem::perms make_permissions(const boost::filesystem::path&
prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write; prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
boost::filesystem::path ext = p.extension(); boost::filesystem::path ext = p.extension();
wchar_t const* q = ext.c_str(); wchar_t const* q = ext.c_str();
if (equal_extension(q, L".exe", L".EXE") if (equal_extension(q, L".exe", L".EXE") || equal_extension(q, L".com", L".COM") || equal_extension(q, L".bat", L".BAT") || equal_extension(q, L".cmd", L".CMD"))
|| equal_extension(q, L".com", L".COM")
|| 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; prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
return prms; return prms;
} }

View File

@ -16,7 +16,6 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
int main() int main()
{ {
cout << "Verify macro reporting works correctly\n"; cout << "Verify macro reporting works correctly\n";
@ -47,6 +46,5 @@ int main()
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl; //cout << " : " << BOOST_MACRO_VALUE() << endl;
return 0; return 0;
} }

View File

@ -37,12 +37,14 @@ namespace fs = boost::filesystem;
using fs::path; using fs::path;
namespace sys = boost::system; namespace sys = boost::system;
namespace namespace {
{
template< typename F > template< typename F >
bool throws_fs_error(F func) bool throws_fs_error(F func)
{ {
try { func(); } try
{
func();
}
catch (const fs::filesystem_error&) catch (const fs::filesystem_error&)
{ {
@ -55,7 +57,7 @@ namespace
{ {
fs::recursive_directory_iterator it(ph); fs::recursive_directory_iterator it(ph);
} }
} } // namespace
// ------------------------------------------------------------------------------------// // ------------------------------------------------------------------------------------//
@ -117,7 +119,9 @@ int cpp_main(int, char*[])
for (it = fs::recursive_directory_iterator(unique_dir); for (it = fs::recursive_directory_iterator(unique_dir);
it != fs::recursive_directory_iterator(); ++it) it != fs::recursive_directory_iterator(); ++it)
{ std::cout << it->path() << '\n'; } {
std::cout << it->path() << '\n';
}
it = fs::recursive_directory_iterator(unique_dir); it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy); BOOST_TEST(it->path() == unique_yy);
@ -169,8 +173,7 @@ int cpp_main(int, char*[])
ec.clear(); ec.clear();
BOOST_TEST(!ec); BOOST_TEST(!ec);
// check that two argument failed constructor creates the end iterator // check that two argument failed constructor creates the end iterator
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator());
== fs::recursive_directory_iterator());
BOOST_TEST(ec); BOOST_TEST(ec);
fs::remove_all(unique_dir); // clean up behind ourselves fs::remove_all(unique_dir); // clean up behind ourselves

View File

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

View File

@ -28,14 +28,13 @@ using boost::filesystem::path;
#define PATH_CHECK(a, b) check(a, b, __LINE__) #define PATH_CHECK(a, b) check(a, b, __LINE__)
namespace namespace {
{
std::string platform(BOOST_PLATFORM); std::string platform(BOOST_PLATFORM);
void check(const fs::path & source, void check(const fs::path& source, const std::string& expected, int line)
const std::string & expected, int line)
{ {
if (source.generic_string()== expected) return; if (source.generic_string() == expected)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
@ -186,7 +185,6 @@ namespace
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
int cpp_main(int /*argc*/, char* /*argv*/[]) int cpp_main(int /*argc*/, char* /*argv*/[])
@ -194,9 +192,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
// The choice of platform is make at runtime rather than compile-time // The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though // so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested. // only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
? "Windows"
: "POSIX";
std::cout << "Platform is " << platform << '\n'; std::cout << "Platform is " << platform << '\n';
BOOST_TEST(fs::initial_path() == fs::current_path()); BOOST_TEST(fs::initial_path() == fs::current_path());

View File

@ -35,14 +35,15 @@ namespace fs = boost::filesystem;
#include <boost/config.hpp> #include <boost/config.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE #ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::remove; } namespace std {
using ::remove;
}
#endif #endif
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
namespace namespace {
{
bool cleanup = true; bool cleanup = true;
void test(const fs::path& p) void test(const fs::path& p)
@ -140,7 +141,8 @@ namespace
int cpp_main(int argc, char*[]) int cpp_main(int argc, char*[])
{ {
if (argc > 1) cleanup = false; if (argc > 1)
cleanup = false;
std::cout << "BOOST_FILESYSTEM_C_STR defined as \"" std::cout << "BOOST_FILESYSTEM_C_STR defined as \""
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n"; << BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n";
@ -149,7 +151,6 @@ int cpp_main(int argc, char*[])
std::cout << "narrow character tests:\n"; std::cout << "narrow character tests:\n";
test("narrow_fstream_test"); test("narrow_fstream_test");
// So that tests are run with known encoding, use Boost UTF-8 codecvt // So that tests are run with known encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale(); std::locale global_loc = std::locale();
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet); std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);

View File

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

View File

@ -11,10 +11,12 @@ int main(int argc, char** argv)
cout << "current path is " << my_path << endl; cout << "current path is " << my_path << endl;
cout << "parent path is " << my_path.parent_path() << endl; cout << "parent path is " << my_path.parent_path() << endl;
} }
catch(std::exception& e) { catch (std::exception& e)
cerr << endl << "Error during execution: " << e.what() << endl << endl; {
cerr << endl
<< "Error during execution: " << e.what() << endl
<< endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

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

View File

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

View File

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

View File

@ -16,5 +16,3 @@ int main()
std::cout << path("a/b/c/d/e/").stem() << std::endl; std::cout << path("a/b/c/d/e/").stem() << std::endl;
return 0; return 0;
} }

View File

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

View File

@ -7,4 +7,3 @@ int main()
{ {
return 0; return 0;
} }

View File

@ -22,7 +22,8 @@ namespace fs = boost::filesystem;
struct TmpDir struct TmpDir
{ {
fs::path path; fs::path path;
TmpDir(const fs::path& base): path(fs::absolute(base) / fs::unique_path()) TmpDir(const fs::path& base) :
path(fs::absolute(base) / fs::unique_path())
{ {
fs::create_directories(path); fs::create_directories(path);
} }
@ -82,4 +83,3 @@ int main()
} }
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK) #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@ -24,7 +24,10 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
{ std::ofstream file("out"); file << "contents"; } {
std::ofstream file("out");
file << "contents";
}
assert(!::symlink("out", "sym")); assert(!::symlink("out", "sym"));

View File

@ -41,8 +41,7 @@ using std::endl;
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
#include <windows.h> #include <windows.h>
#endif #endif
namespace namespace {
{
typedef int errno_t; typedef int errno_t;
std::string platform(BOOST_PLATFORM); std::string platform(BOOST_PLATFORM);
bool report_throws = false; bool report_throws = false;

View File

@ -27,12 +27,15 @@
// https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN // https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN
#if !defined(__MINGW32__) || defined(__MINGW64__) #if !defined(__MINGW32__) || defined(__MINGW64__)
typedef struct _REPARSE_DATA_BUFFER { typedef struct _REPARSE_DATA_BUFFER
{
ULONG ReparseTag; ULONG ReparseTag;
USHORT ReparseDataLength; USHORT ReparseDataLength;
USHORT Reserved; USHORT Reserved;
union { union
struct { {
struct
{
USHORT SubstituteNameOffset; USHORT SubstituteNameOffset;
USHORT SubstituteNameLength; USHORT SubstituteNameLength;
USHORT PrintNameOffset; USHORT PrintNameOffset;
@ -40,14 +43,16 @@ typedef struct _REPARSE_DATA_BUFFER {
ULONG Flags; ULONG Flags;
WCHAR PathBuffer[1]; WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer; } SymbolicLinkReparseBuffer;
struct { struct
{
USHORT SubstituteNameOffset; USHORT SubstituteNameOffset;
USHORT SubstituteNameLength; USHORT SubstituteNameLength;
USHORT PrintNameOffset; USHORT PrintNameOffset;
USHORT PrintNameLength; USHORT PrintNameLength;
WCHAR PathBuffer[1]; WCHAR PathBuffer[1];
} MountPointReparseBuffer; } MountPointReparseBuffer;
struct { struct
{
UCHAR DataBuffer[1]; UCHAR DataBuffer[1];
} GenericReparseBuffer; } GenericReparseBuffer;
}; };
@ -104,9 +109,7 @@ bool create_io_reparse_file_placeholder(const wchar_t* name)
return false; return false;
} }
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0);
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
FILE_FLAG_OPEN_REPARSE_POINT, 0);
if (hHandle == INVALID_HANDLE_VALUE) if (hHandle == INVALID_HANDLE_VALUE)
{ {
@ -119,9 +122,7 @@ bool create_io_reparse_file_placeholder(const wchar_t* name)
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER; pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
DWORD dwLen; DWORD dwLen;
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, NULL, 0, &dwLen, NULL) != 0;
pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE,
NULL, 0, &dwLen, NULL) != 0;
if (!ret) if (!ret)
{ {

View File

@ -16,15 +16,12 @@ using namespace std;
#pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe #pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe
#endif #endif
namespace namespace {
{
void facet_info(const locale& loc, const char* msg) void facet_info(const locale& loc, const char* msg)
{ {
cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(" cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
<< msg << ") is " << msg << ") is "
<< (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc) << (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "true\n" : "false\n");
? "true\n"
: "false\n");
} }
void default_info() void default_info()
@ -68,7 +65,7 @@ namespace
cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl; cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
} }
} }
} } // namespace
int main() int main()
{ {

View File

@ -20,8 +20,7 @@ using namespace boost::filesystem;
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp> #include <boost/detail/lightweight_main.hpp>
namespace namespace {
{
} // unnamed namespace } // unnamed namespace
int cpp_main(int, char*[]) int cpp_main(int, char*[])
@ -30,8 +29,7 @@ int cpp_main(int, char*[])
std::string prefix("d:\\temp\\"); std::string prefix("d:\\temp\\");
std::cout << "prefix is " << prefix << '\n'; std::cout << "prefix is " << prefix << '\n';
const std::size_t safe_size const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260
= 260 - prefix.size() - 100; // Windows MAX_PATH is 260
std::string safe_x_string(safe_size, 'x'); std::string safe_x_string(safe_size, 'x');
std::string safe_y_string(safe_size, 'y'); std::string safe_y_string(safe_size, 'y');

View File

@ -25,7 +25,6 @@
#error BOOST_FILESYSTEM_STATIC_LINK not set by default #error BOOST_FILESYSTEM_STATIC_LINK not set by default
#endif #endif
#ifndef BOOST_SYSTEM_STATIC_LINK #ifndef BOOST_SYSTEM_STATIC_LINK
#error BOOST_SYSTEM_STATIC_LINK not set by default #error BOOST_SYSTEM_STATIC_LINK not set by default
#endif #endif

View File

@ -9,13 +9,11 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem
{
void tu2(); void tu2();
} }
} } // namespace boost
int main() int main()
{ {

View File

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

View File

@ -100,8 +100,7 @@ inline void unsetenv_(const char* name)
// on Windows, except for standard libaries known to have wchar_t overloads for // on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str() // file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \ #if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads
#define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available #define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#else // use the native c_str, which will be narrow on POSIX, wide on Windows #else // use the native c_str, which will be narrow on POSIX, wide on Windows
#define BOOST_FILESYSTEM_C_STR c_str() #define BOOST_FILESYSTEM_C_STR c_str()
@ -109,8 +108,7 @@ inline void unsetenv_(const char* name)
#define CHECK_EXCEPTION(Functor, Expect) throws_fs_error(Functor, Expect, __LINE__) #define CHECK_EXCEPTION(Functor, Expect) throws_fs_error(Functor, Expect, __LINE__)
namespace namespace {
{
typedef int errno_t; typedef int errno_t;
std::string platform(BOOST_PLATFORM); std::string platform(BOOST_PLATFORM);
bool report_throws = false; bool report_throws = false;
@ -137,38 +135,40 @@ namespace
{ {
std::ofstream f(ph.BOOST_FILESYSTEM_C_STR); std::ofstream f(ph.BOOST_FILESYSTEM_C_STR);
if (!f) if (!f)
throw fs::filesystem_error("operations_test create_file", throw fs::filesystem_error("operations_test create_file", ph, error_code(errno, system_category()));
ph, error_code(errno, system_category())); if (!contents.empty())
if (!contents.empty()) f << contents; f << contents;
} }
void verify_file(const fs::path& ph, const std::string& expected) void verify_file(const fs::path& ph, const std::string& expected)
{ {
std::ifstream f(ph.BOOST_FILESYSTEM_C_STR); std::ifstream f(ph.BOOST_FILESYSTEM_C_STR);
if (!f) if (!f)
throw fs::filesystem_error("operations_test verify_file", throw fs::filesystem_error("operations_test verify_file", ph, error_code(errno, system_category()));
ph, error_code(errno, system_category()));
std::string contents; std::string contents;
f >> contents; f >> contents;
if (contents != expected) if (contents != expected)
throw fs::filesystem_error("operations_test verify_file contents \"" throw fs::filesystem_error("operations_test verify_file contents \"" + contents + "\" != \"" + expected + "\"", ph, error_code());
+ contents + "\" != \"" + expected + "\"", ph, error_code());
} }
template< typename F > template< typename F >
bool throws_fs_error(F func, errno_t en, int line) bool throws_fs_error(F func, errno_t en, int line)
{ {
try { func(); } try
{
func();
}
catch (const fs::filesystem_error& ex) catch (const fs::filesystem_error& ex)
{ {
if (report_throws) if (report_throws)
{ {
// use the what() convenience function to display exceptions // use the what() convenience function to display exceptions
cout << "\n" << ex.what() << "\n"; cout << "\n"
<< ex.what() << "\n";
} }
if (en == 0 if (en == 0 || en == ex.code().default_error_condition().value())
|| en == ex.code().default_error_condition().value()) return true; return true;
cout cout
<< "\nWarning: line " << line << "\nWarning: line " << line
<< " exception reports default_error_condition().value() " << " exception reports default_error_condition().value() "
@ -249,12 +249,13 @@ namespace
class renamer class renamer
{ {
public: public:
renamer(const fs::path & p1, const fs::path & p2) renamer(const fs::path& p1, const fs::path& p2) :
: from(p1), to(p2) {} from(p1), to(p2) {}
void operator()() void operator()()
{ {
fs::rename(from, to); fs::rename(from, to);
} }
private: private:
fs::path from; fs::path from;
fs::path to; fs::path to;
@ -323,13 +324,12 @@ namespace
catch (std::runtime_error x) catch (std::runtime_error x)
{ {
exception_thrown = true; exception_thrown = true;
if (report_throws) cout << x.what() << endl; if (report_throws)
cout << x.what() << endl;
if (platform == "Windows" && language_id == 0x0409) // English (United States) if (platform == "Windows" && language_id == 0x0409) // English (United States)
// the stdcxx standard library apparently appends additional info // the stdcxx standard library apparently appends additional info
// to what(), so check only the initial portion: // to what(), so check only the initial portion:
BOOST_TEST(std::strncmp(x.what(), BOOST_TEST(std::strncmp(x.what(), "boost::filesystem::create_directory", sizeof("boost::filesystem::create_directory") - 1) == 0);
"boost::filesystem::create_directory",
sizeof("boost::filesystem::create_directory")-1) == 0);
} }
BOOST_TEST(exception_thrown); BOOST_TEST(exception_thrown);
@ -344,10 +344,10 @@ namespace
catch (system_error x) catch (system_error x)
{ {
exception_thrown = true; exception_thrown = true;
if (report_throws) cout << x.what() << endl; if (report_throws)
cout << x.what() << endl;
if (platform == "Windows" && language_id == 0x0409) // English (United States) if (platform == "Windows" && language_id == 0x0409) // English (United States)
BOOST_TEST(std::strcmp(x.what(), BOOST_TEST(std::strcmp(x.what(), "boost::filesystem::create_directory: The system cannot find the path specified") == 0);
"boost::filesystem::create_directory: The system cannot find the path specified") == 0);
} }
BOOST_TEST(exception_thrown); BOOST_TEST(exception_thrown);
@ -362,11 +362,11 @@ namespace
catch (fs::filesystem_error x) catch (fs::filesystem_error x)
{ {
exception_thrown = true; exception_thrown = true;
if (report_throws) cout << x.what() << endl; if (report_throws)
cout << x.what() << endl;
if (platform == "Windows" && language_id == 0x0409) // English (United States) if (platform == "Windows" && language_id == 0x0409) // English (United States)
{ {
bool ok (std::strcmp(x.what(), bool ok(std::strcmp(x.what(), "boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir/foo/bar\"") == 0);
"boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir/foo/bar\"") == 0);
BOOST_TEST(ok); BOOST_TEST(ok);
if (!ok) if (!ok)
{ {
@ -387,11 +387,11 @@ namespace
catch (const fs::filesystem_error& x) catch (const fs::filesystem_error& x)
{ {
exception_thrown = true; exception_thrown = true;
if (report_throws) cout << x.what() << endl; if (report_throws)
cout << x.what() << endl;
if (platform == "Windows" && language_id == 0x0409) // English (United States) if (platform == "Windows" && language_id == 0x0409) // English (United States)
{ {
bool ok (std::strcmp(x.what(), bool ok(std::strcmp(x.what(), "boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir/foo/bar\"") == 0);
"boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir/foo/bar\"") == 0);
BOOST_TEST(ok); BOOST_TEST(ok);
if (!ok) if (!ok)
{ {
@ -486,8 +486,14 @@ namespace
cout << "directory_iterator_tests..." << endl; cout << "directory_iterator_tests..." << endl;
bool dir_itr_exception(false); bool dir_itr_exception(false);
try { fs::directory_iterator it(""); } try
catch (const fs::filesystem_error &) { dir_itr_exception = true; } {
fs::directory_iterator it("");
}
catch (const fs::filesystem_error&)
{
dir_itr_exception = true;
}
BOOST_TEST(dir_itr_exception); BOOST_TEST(dir_itr_exception);
error_code ec; error_code ec;
@ -497,8 +503,14 @@ namespace
BOOST_TEST(ec); BOOST_TEST(ec);
dir_itr_exception = false; dir_itr_exception = false;
try { fs::directory_iterator itx("nosuchdirectory"); } try
catch (const fs::filesystem_error &) { dir_itr_exception = true; } {
fs::directory_iterator itx("nosuchdirectory");
}
catch (const fs::filesystem_error&)
{
dir_itr_exception = true;
}
BOOST_TEST(dir_itr_exception); BOOST_TEST(dir_itr_exception);
ec.clear(); ec.clear();
@ -513,7 +525,10 @@ namespace
BOOST_TEST(ecx); BOOST_TEST(ecx);
BOOST_TEST(ecx == boost::system::errc::no_such_file_or_directory); BOOST_TEST(ecx == boost::system::errc::no_such_file_or_directory);
} }
catch (const fs::filesystem_error &) { dir_itr_exception = true; } catch (const fs::filesystem_error&)
{
dir_itr_exception = true;
}
BOOST_TEST(!dir_itr_exception); BOOST_TEST(!dir_itr_exception);
// create a second directory named d2 // create a second directory named d2
@ -655,8 +670,7 @@ namespace
//cout << " walk_tree" << endl; //cout << " walk_tree" << endl;
error_code ec; error_code ec;
int d1f1_count = 0; int d1f1_count = 0;
for (fs::recursive_directory_iterator it (dir, for (fs::recursive_directory_iterator it(dir, recursive ? (fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks) : fs::directory_options::none);
recursive ? (fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks) : fs::directory_options::none);
it != fs::recursive_directory_iterator(); it != fs::recursive_directory_iterator();
it.increment(ec)) it.increment(ec))
{ {
@ -707,8 +721,7 @@ namespace
fs::create_symlink(dir / "f0", dir / "f0_symlink", ec); fs::create_symlink(dir / "f0", dir / "f0_symlink", ec);
fs::create_symlink(dir / "no such file", dir / "dangling_symlink", ec); fs::create_symlink(dir / "no such file", dir / "dangling_symlink", ec);
fs::create_directory_symlink(dir / "d1", dir / "d1_symlink", ec); fs::create_directory_symlink(dir / "d1", dir / "d1_symlink", ec);
fs::create_directory_symlink(dir/"no such directory", fs::create_directory_symlink(dir / "no such directory", dir / "dangling_directory_symlink", ec);
dir/"dangling_directory_symlink", ec);
for (fs::directory_iterator it(dir); for (fs::directory_iterator it(dir);
it != fs::directory_iterator(); ++it) it != fs::directory_iterator(); ++it)
@ -787,14 +800,18 @@ namespace
BOOST_TEST(!fs::exists(from_ph)); BOOST_TEST(!fs::exists(from_ph));
BOOST_TEST(fs::exists(f1x)); BOOST_TEST(fs::exists(f1x));
bool create_hard_link_ok(true); bool create_hard_link_ok(true);
try { fs::create_hard_link(f1x, from_ph); } try
{
fs::create_hard_link(f1x, from_ph);
}
catch (const fs::filesystem_error& ex) catch (const fs::filesystem_error& ex)
{ {
create_hard_link_ok = false; create_hard_link_ok = false;
cout cout
<< " *** For information only ***\n" << " *** For information only ***\n"
" create_hard_link() attempt failed\n" " create_hard_link() attempt failed\n"
" filesystem_error.what() reports: " << ex.what() << "\n" " filesystem_error.what() reports: "
<< ex.what() << "\n"
" create_hard_link() may not be supported on this file system\n"; " create_hard_link() may not be supported on this file system\n";
} }
@ -816,8 +833,7 @@ namespace
BOOST_TEST(create_hard_link_ok); BOOST_TEST(create_hard_link_ok);
error_code ec; error_code ec;
fs::create_hard_link(fs::path("doesnotexist"), fs::create_hard_link(fs::path("doesnotexist"), fs::path("shouldnotwork"), ec);
fs::path("shouldnotwork"), ec);
BOOST_TEST(ec); BOOST_TEST(ec);
} }
@ -831,14 +847,18 @@ namespace
fs::path f1x(dir / "f1"); fs::path f1x(dir / "f1");
BOOST_TEST(!fs::exists(from_ph)); BOOST_TEST(!fs::exists(from_ph));
BOOST_TEST(fs::exists(f1x)); BOOST_TEST(fs::exists(f1x));
try { fs::create_symlink(f1x, from_ph); } try
{
fs::create_symlink(f1x, from_ph);
}
catch (const fs::filesystem_error& ex) catch (const fs::filesystem_error& ex)
{ {
create_symlink_ok = false; create_symlink_ok = false;
cout cout
<< " *** For information only ***\n" << " *** For information only ***\n"
" create_symlink() attempt failed\n" " create_symlink() attempt failed\n"
" filesystem_error.what() reports: " << ex.what() << "\n" " filesystem_error.what() reports: "
<< ex.what() << "\n"
" create_symlink() may not be supported on this operating system or file system\n"; " create_symlink() may not be supported on this operating system or file system\n";
} }
@ -926,7 +946,6 @@ namespace
cout << " status(p2).permissions(): " << fs::status(p2).permissions() << endl; cout << " status(p2).permissions(): " << fs::status(p2).permissions() << endl;
cout << std::dec; cout << std::dec;
} }
} }
else // Windows else // Windows
{ {
@ -1113,7 +1132,8 @@ namespace
catch (const fs::filesystem_error& x) catch (const fs::filesystem_error& x)
{ {
cout << x.what() << "\n\n" cout << x.what() << "\n\n"
"***** Creating directory " << dir << " failed. *****\n" "***** Creating directory "
<< dir << " failed. *****\n"
"***** This is a serious error that will prevent further tests *****\n" "***** This is a serious error that will prevent further tests *****\n"
"***** from returning useful results. Further testing is aborted. *****\n\n"; "***** from returning useful results. Further testing is aborted. *****\n\n";
std::exit(1); std::exit(1);
@ -1122,7 +1142,8 @@ namespace
catch (...) catch (...)
{ {
cout << "\n\n" cout << "\n\n"
"***** Creating directory " << dir << " failed. *****\n" "***** Creating directory "
<< dir << " failed. *****\n"
"***** This is a serious error that will prevent further tests *****\n" "***** This is a serious error that will prevent further tests *****\n"
"***** from returning useful results. Further testing is aborted. *****\n\n"; "***** from returning useful results. Further testing is aborted. *****\n\n";
std::exit(1); std::exit(1);
@ -1508,7 +1529,6 @@ namespace
BOOST_TEST_EQ(fs::absolute(fs::path("./foo"), "/abc"), "/abc/./foo"); BOOST_TEST_EQ(fs::absolute(fs::path("./foo"), "/abc"), "/abc/./foo");
BOOST_TEST_EQ(fs::absolute(fs::path("../foo"), "/abc"), "/abc/../foo"); BOOST_TEST_EQ(fs::absolute(fs::path("../foo"), "/abc"), "/abc/../foo");
} }
} }
// canonical_basic_tests -----------------------------------------------------------// // canonical_basic_tests -----------------------------------------------------------//
@ -1526,8 +1546,14 @@ namespace
fs::canonical("no-such-file", "x", ec); fs::canonical("no-such-file", "x", ec);
BOOST_TEST(ec); BOOST_TEST(ec);
bool ok(false); bool ok(false);
try { fs::canonical("no-such-file"); } try
catch (const fs::filesystem_error&) { ok = true; } {
fs::canonical("no-such-file");
}
catch (const fs::filesystem_error&)
{
ok = true;
}
BOOST_TEST(ok); BOOST_TEST(ok);
// non-symlink tests; also see canonical_symlink_tests() // non-symlink tests; also see canonical_symlink_tests()
@ -1609,15 +1635,27 @@ namespace
bool copy_ex_ok = false; bool copy_ex_ok = false;
file_copied = false; file_copied = false;
try { file_copied = fs::copy_file(f1x, d1x / "f2"); } try
catch (const fs::filesystem_error &) { copy_ex_ok = true; } {
file_copied = fs::copy_file(f1x, d1x / "f2");
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = true;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(!file_copied); BOOST_TEST(!file_copied);
file_copied = false; file_copied = false;
copy_ex_ok = false; copy_ex_ok = false;
try { file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::none); } try
catch (const fs::filesystem_error &) { copy_ex_ok = true; } {
file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::none);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = true;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(!file_copied); BOOST_TEST(!file_copied);
@ -1626,8 +1664,14 @@ namespace
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U);
file_copied = false; file_copied = false;
copy_ex_ok = true; copy_ex_ok = true;
try { file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::skip_existing); } try
catch (const fs::filesystem_error &) { copy_ex_ok = false; } {
file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::skip_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(!file_copied); BOOST_TEST(!file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U);
@ -1635,8 +1679,14 @@ namespace
file_copied = false; file_copied = false;
copy_ex_ok = true; copy_ex_ok = true;
try { file_copied = fs::copy_file(f1x, d1x / "f2-non-existing", fs::copy_options::skip_existing); } try
catch (const fs::filesystem_error &) { copy_ex_ok = false; } {
file_copied = fs::copy_file(f1x, d1x / "f2-non-existing", fs::copy_options::skip_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(file_copied); BOOST_TEST(file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2-non-existing"), 7U); BOOST_TEST_EQ(fs::file_size(d1x / "f2-non-existing"), 7U);
@ -1645,8 +1695,14 @@ namespace
file_copied = false; file_copied = false;
copy_ex_ok = true; copy_ex_ok = true;
try { file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::update_existing); } try
catch (const fs::filesystem_error &) { copy_ex_ok = false; } {
file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::update_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(!file_copied); BOOST_TEST(!file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U);
@ -1663,8 +1719,14 @@ namespace
BOOST_TEST_EQ(fs::file_size(d1x / "f2-more-recent"), 1U); BOOST_TEST_EQ(fs::file_size(d1x / "f2-more-recent"), 1U);
file_copied = false; file_copied = false;
copy_ex_ok = true; copy_ex_ok = true;
try { file_copied = fs::copy_file(d1x / "f2-more-recent", d1x / "f2", fs::copy_options::update_existing); } try
catch (const fs::filesystem_error &) { copy_ex_ok = false; } {
file_copied = fs::copy_file(d1x / "f2-more-recent", d1x / "f2", fs::copy_options::update_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(file_copied); BOOST_TEST(file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 1U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 1U);
@ -1676,8 +1738,14 @@ namespace
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 10U);
file_copied = false; file_copied = false;
copy_ex_ok = true; copy_ex_ok = true;
try { file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::overwrite_existing); } try
catch (const fs::filesystem_error &) { copy_ex_ok = false; } {
file_copied = fs::copy_file(f1x, d1x / "f2", fs::copy_options::overwrite_existing);
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = false;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
BOOST_TEST(file_copied); BOOST_TEST(file_copied);
BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 7U); BOOST_TEST_EQ(fs::file_size(d1x / "f2"), 7U);
@ -1769,13 +1837,25 @@ namespace
//BOOST_TEST(fs::is_symlink(sym3)); //BOOST_TEST(fs::is_symlink(sym3));
bool copy_ex_ok = false; bool copy_ex_ok = false;
try { fs::copy_symlink("no-such-file", "new-symlink1"); } try
catch (const fs::filesystem_error &) { copy_ex_ok = true; } {
fs::copy_symlink("no-such-file", "new-symlink1");
}
catch (const fs::filesystem_error&)
{
copy_ex_ok = true;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
copy_ex_ok = false; copy_ex_ok = false;
try { fs::copy_symlink(f1x, "new-symlink2"); } // should fail; f1x not symlink try
catch (const fs::filesystem_error &) { copy_ex_ok = true; } {
fs::copy_symlink(f1x, "new-symlink2");
} // should fail; f1x not symlink
catch (const fs::filesystem_error&)
{
copy_ex_ok = true;
}
BOOST_TEST(copy_ex_ok); BOOST_TEST(copy_ex_ok);
} }
@ -1889,13 +1969,11 @@ namespace
BOOST_TEST(!fs::exists("tools/jam/src/:sys:stat.h")); // !exists() if ERROR_INVALID_NAME BOOST_TEST(!fs::exists("tools/jam/src/:sys:stat.h")); // !exists() if ERROR_INVALID_NAME
BOOST_TEST(!fs::exists(":sys:stat.h")); // !exists() if ERROR_INVALID_PARAMETER BOOST_TEST(!fs::exists(":sys:stat.h")); // !exists() if ERROR_INVALID_PARAMETER
BOOST_TEST(dir.string().size() > 1 BOOST_TEST(dir.string().size() > 1 && dir.string()[1] == ':'); // verify path includes drive
&& dir.string()[1] == ':'); // verify path includes drive
BOOST_TEST(fs::system_complete("").empty()); BOOST_TEST(fs::system_complete("").empty());
BOOST_TEST(fs::system_complete("/") == fs::initial_path().root_path()); BOOST_TEST(fs::system_complete("/") == fs::initial_path().root_path());
BOOST_TEST(fs::system_complete("foo") BOOST_TEST(fs::system_complete("foo") == fs::initial_path() / "foo");
== fs::initial_path() / "foo");
fs::path p1(fs::system_complete("/foo")); fs::path p1(fs::system_complete("/foo"));
BOOST_TEST_EQ(p1.string().size(), 6U); // this failed during v3 development due to bug BOOST_TEST_EQ(p1.string().size(), 6U); // this failed during v3 development due to bug
@ -1903,16 +1981,11 @@ namespace
std::string s2(fs::initial_path().root_path().string() + "foo"); std::string s2(fs::initial_path().root_path().string() + "foo");
BOOST_TEST_EQ(s1, s2); BOOST_TEST_EQ(s1, s2);
BOOST_TEST(fs::system_complete(fs::path(fs::initial_path().root_name())) BOOST_TEST(fs::system_complete(fs::path(fs::initial_path().root_name())) == fs::initial_path());
== fs::initial_path()); BOOST_TEST(fs::system_complete(fs::path(fs::initial_path().root_name().string() + "foo")).string() == fs::initial_path() / "foo");
BOOST_TEST(fs::system_complete(fs::path(fs::initial_path().root_name().string() BOOST_TEST(fs::system_complete(fs::path("c:/")).generic_string() == "c:/");
+ "foo")).string() == fs::initial_path() / "foo"); BOOST_TEST(fs::system_complete(fs::path("c:/foo")).generic_string() == "c:/foo");
BOOST_TEST(fs::system_complete(fs::path("c:/")).generic_string() BOOST_TEST(fs::system_complete(fs::path("//share")).generic_string() == "//share");
== "c:/");
BOOST_TEST(fs::system_complete(fs::path("c:/foo")).generic_string()
== "c:/foo");
BOOST_TEST(fs::system_complete(fs::path("//share")).generic_string()
== "//share");
#if defined(BOOST_FILESYSTEM_HAS_MKLINK) #if defined(BOOST_FILESYSTEM_HAS_MKLINK)
// Issue 9016 asked that NTFS directory junctions be recognized as directories. // Issue 9016 asked that NTFS directory junctions be recognized as directories.
@ -1987,10 +2060,8 @@ namespace
BOOST_TEST(fs::system_complete("").empty()); BOOST_TEST(fs::system_complete("").empty());
BOOST_TEST(fs::initial_path().root_path().string() == "/"); BOOST_TEST(fs::initial_path().root_path().string() == "/");
BOOST_TEST(fs::system_complete("/").string() == "/"); BOOST_TEST(fs::system_complete("/").string() == "/");
BOOST_TEST(fs::system_complete("foo").string() BOOST_TEST(fs::system_complete("foo").string() == fs::initial_path().string() + "/foo");
== fs::initial_path().string()+"/foo"); BOOST_TEST(fs::system_complete("/foo").string() == fs::initial_path().root_path().string() + "foo");
BOOST_TEST(fs::system_complete("/foo").string()
== fs::initial_path().root_path().string()+"foo");
} // POSIX } // POSIX
} }
@ -2006,8 +2077,7 @@ namespace
BOOST_TEST(fs::initial_path() == fs::current_path()); BOOST_TEST(fs::initial_path() == fs::current_path());
BOOST_TEST(fs::initial_path().is_absolute()); BOOST_TEST(fs::initial_path().is_absolute());
BOOST_TEST(fs::current_path().is_absolute()); BOOST_TEST(fs::current_path().is_absolute());
BOOST_TEST(fs::initial_path().string() BOOST_TEST(fs::initial_path().string() == fs::current_path().string());
== fs::current_path().string());
} }
// space_tests ---------------------------------------------------------------------// // space_tests ---------------------------------------------------------------------//
@ -2072,9 +2142,8 @@ namespace
std::string m_string; std::string m_string;
bool m_empty; bool m_empty;
previous_value(const char* name) previous_value(const char* name) :
: m_name(name) m_name(name), m_empty(true)
, m_empty (true)
{ {
if (const char* value = getenv(name)) if (const char* value = getenv(name))
{ {
@ -2088,15 +2157,14 @@ namespace
} }
~previous_value() ~previous_value()
{ {
m_empty? unsetenv_(m_name.c_str()) m_empty ? unsetenv_(m_name.c_str()) : setenv_(m_name.c_str(), m_string.c_str(), 1);
: setenv_(m_name.c_str(), m_string.c_str(), 1);
} }
}; };
previous_value m_previous_value; previous_value m_previous_value;
guarded_env_var(const char* name, const char* value) guarded_env_var(const char* name, const char* value) :
: m_previous_value(name) m_previous_value(name)
{ {
// std::cout << name << " old value is \"" << getenv(name) << "\"" << std::endl; // std::cout << name << " old value is \"" << getenv(name) << "\"" << std::endl;
value ? setenv_(name, value, 1) : unsetenv_(name); value ? setenv_(name, value, 1) : unsetenv_(name);
@ -2119,7 +2187,8 @@ namespace
#if defined(__CYGWIN__) && !defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ == 4 #if defined(__CYGWIN__) && !defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ == 4
cout << "Bug in GCC 4.9 getenv() when !defined(__GXX_EXPERIMENTAL_CXX0X__) makes these" cout << "Bug in GCC 4.9 getenv() when !defined(__GXX_EXPERIMENTAL_CXX0X__) makes these"
"tests meaningless, so skip them" << endl; "tests meaningless, so skip them"
<< endl;
return; return;
#endif #endif
// Test ticket #5300, temp_directory_path failure on Windows with path length > 130. // Test ticket #5300, temp_directory_path failure on Windows with path length > 130.
@ -2156,7 +2225,8 @@ namespace
BOOST_TEST(exists(fs::temp_directory_path())); BOOST_TEST(exists(fs::temp_directory_path()));
fs::path ph = fs::temp_directory_path() / fs::unique_path("temp_directory_path_test_%%%%_%%%%.txt"); fs::path ph = fs::temp_directory_path() / fs::unique_path("temp_directory_path_test_%%%%_%%%%.txt");
{ {
if(exists(ph)) remove(ph); if (exists(ph))
remove(ph);
std::ofstream f(ph.BOOST_FILESYSTEM_C_STR); std::ofstream f(ph.BOOST_FILESYSTEM_C_STR);
f << "passed"; f << "passed";
} }
@ -2182,17 +2252,10 @@ namespace
guarded_env_var m_temp; guarded_env_var m_temp;
guarded_env_var m_tempdir; guarded_env_var m_tempdir;
guarded_tmp_vars guarded_tmp_vars(const fs::path::value_type* tmpdir, const fs::path::value_type* tmp, const fs::path::value_type* temp, const fs::path::value_type* tempdir) :
( const fs::path::value_type* tmpdir m_tmpdir("TMPDIR", tmpdir), m_tmp("TMP", tmp), m_temp("TEMP", temp), m_tempdir("TEMPDIR", tempdir)
, const fs::path::value_type* tmp {
, const fs::path::value_type* temp }
, const fs::path::value_type* tempdir
)
: m_tmpdir ("TMPDIR" , tmpdir )
, m_tmp ("TMP" , tmp )
, m_temp ("TEMP" , temp )
, m_tempdir("TEMPDIR", tempdir)
{}
}; };
{ {
@ -2227,17 +2290,10 @@ namespace
guarded_env_var m_localappdata; guarded_env_var m_localappdata;
guarded_env_var m_userprofile; guarded_env_var m_userprofile;
guarded_tmp_vars guarded_tmp_vars(const char* tmp, const char* temp, const char* localappdata, const char* userprofile) :
( const char* tmp m_tmp("TMP", tmp), m_temp("TEMP", temp), m_localappdata("LOCALAPPDATA", localappdata), m_userprofile("USERPROFILE", userprofile)
, const char* temp {
, const char* localappdata }
, const char* userprofile
)
: m_tmp ("TMP" , tmp )
, m_temp ("TEMP" , temp )
, m_localappdata ("LOCALAPPDATA" , localappdata)
, m_userprofile ("USERPROFILE" , userprofile )
{}
}; };
// test the GetWindowsDirectoryW()/Temp fallback // test the GetWindowsDirectoryW()/Temp fallback
@ -2288,8 +2344,7 @@ namespace
BOOST_TEST_EQ(fs::weakly_canonical(dir), dir); BOOST_TEST_EQ(fs::weakly_canonical(dir), dir);
BOOST_TEST_EQ(fs::weakly_canonical(dir / "no-such/foo/bar"), dir / "no-such/foo/bar"); BOOST_TEST_EQ(fs::weakly_canonical(dir / "no-such/foo/bar"), dir / "no-such/foo/bar");
BOOST_TEST_EQ(fs::weakly_canonical(dir / "no-such/foo/../bar"), dir / "no-such/bar"); BOOST_TEST_EQ(fs::weakly_canonical(dir / "no-such/foo/../bar"), dir / "no-such/bar");
BOOST_TEST_EQ(fs::weakly_canonical(dir/"../no-such/foo/../bar"), BOOST_TEST_EQ(fs::weakly_canonical(dir / "../no-such/foo/../bar"), dir.parent_path() / "no-such/bar");
dir.parent_path()/"no-such/bar");
BOOST_TEST_EQ(fs::weakly_canonical("c:/no-such/foo/bar"), "c:/no-such/foo/bar"); BOOST_TEST_EQ(fs::weakly_canonical("c:/no-such/foo/bar"), "c:/no-such/foo/bar");
fs::create_directory_symlink(dir / "d1", dir / "sld1"); fs::create_directory_symlink(dir / "d1", dir / "sld1");

View File

@ -13,7 +13,6 @@
// ------------------------------------------------------------------------------------// // ------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features // See deprecated_test for tests of deprecated features
@ -44,13 +43,13 @@ using std::string;
#define CHECK(x) check(x, __FILE__, __LINE__) #define CHECK(x) check(x, __FILE__, __LINE__)
namespace namespace {
{
bool cleanup = true; bool cleanup = true;
void check(bool ok, const char* file, int line) void check(bool ok, const char* file, int line)
{ {
if (ok) return; if (ok)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
@ -262,8 +261,7 @@ namespace
{ {
cout << "directory_entry test..." << endl; cout << "directory_entry test..." << endl;
directory_entry de("foo.bar", directory_entry de("foo.bar", file_status(regular_file, owner_all), file_status(directory_file, group_all));
file_status(regular_file, owner_all), file_status(directory_file, group_all));
CHECK(de.path() == "foo.bar"); CHECK(de.path() == "foo.bar");
CHECK(de.status() == file_status(regular_file, owner_all)); CHECK(de.status() == file_status(regular_file, owner_all));
@ -300,7 +298,8 @@ namespace
{ {
threw = true; threw = true;
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n" cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
"what() returns " << ex.what() << "\n"; "what() returns "
<< ex.what() << "\n";
} }
catch (...) catch (...)
{ {

View File

@ -81,12 +81,10 @@ using boost::prior;
#define PATH_TEST_EQ(a, b) check(a, b, __FILE__, __LINE__) #define PATH_TEST_EQ(a, b) check(a, b, __FILE__, __LINE__)
namespace namespace {
{
std::string platform(BOOST_PLATFORM); std::string platform(BOOST_PLATFORM);
void check(const fs::path & source, void check(const fs::path& source, const std::string& expected, const char* file, int line)
const std::string & expected, const char* file, int line)
{ {
if (source.string() == expected) if (source.string() == expected)
return; return;
@ -112,7 +110,10 @@ namespace
std::cout << "exception_tests..." << std::endl; std::cout << "exception_tests..." << std::endl;
const std::string str_1("string-1"); const std::string str_1("string-1");
boost::system::error_code ec(12345, boost::system::system_category()); boost::system::error_code ec(12345, boost::system::system_category());
try { throw fs::filesystem_error(str_1, ec); } try
{
throw fs::filesystem_error(str_1, ec);
}
catch (const fs::filesystem_error& ex) catch (const fs::filesystem_error& ex)
{ {
//std::cout << ex.what() << "*" << std::endl; //std::cout << ex.what() << "*" << std::endl;
@ -121,7 +122,10 @@ namespace
BOOST_TEST(ex.code() == ec); BOOST_TEST(ex.code() == ec);
} }
try { throw fs::filesystem_error(str_1, "p1", "p2", ec); } try
{
throw fs::filesystem_error(str_1, "p1", "p2", ec);
}
catch (const fs::filesystem_error& ex) catch (const fs::filesystem_error& ex)
{ {
//std::cout << ex.what() << "*" << std::endl; //std::cout << ex.what() << "*" << std::endl;
@ -1389,7 +1393,6 @@ namespace
void composition_tests() void composition_tests()
{ {
std::cout << "composition_tests..." << std::endl; std::cout << "composition_tests..." << std::endl;
} }
// construction_tests ---------------------------------------------------------------// // construction_tests ---------------------------------------------------------------//
@ -1605,7 +1608,6 @@ namespace
PATH_TEST_EQ(path("foo/") / "bar", "foo/bar"); PATH_TEST_EQ(path("foo/") / "bar", "foo/bar");
append_test_aux("foo/", "bar", "foo/bar"); append_test_aux("foo/", "bar", "foo/bar");
if (platform == "Windows") if (platform == "Windows")
{ {
PATH_TEST_EQ(path("foo") / "bar", "foo\\bar"); PATH_TEST_EQ(path("foo") / "bar", "foo\\bar");
@ -1681,7 +1683,6 @@ namespace
PATH_TEST_EQ(p.append(p.c_str() + 5, p.c_str() + 7), "snafubar" BOOST_DIR_SEP "ba"); PATH_TEST_EQ(p.append(p.c_str() + 5, p.c_str() + 7), "snafubar" BOOST_DIR_SEP "ba");
} }
// name_function_tests -------------------------------------------------------------// // name_function_tests -------------------------------------------------------------//
void name_function_tests() void name_function_tests()
@ -1793,8 +1794,7 @@ namespace
BOOST_TEST(path("a/b").replace_extension(".c") == "a/b.c"); BOOST_TEST(path("a/b").replace_extension(".c") == "a/b.c");
PATH_TEST_EQ(path("a.txt/b").replace_extension(".c"), "a.txt/b.c"); // ticket 4702 PATH_TEST_EQ(path("a.txt/b").replace_extension(".c"), "a.txt/b.c"); // ticket 4702
BOOST_TEST(path("foo.txt").replace_extension("exe") == "foo.exe"); // ticket 5118 BOOST_TEST(path("foo.txt").replace_extension("exe") == "foo.exe"); // ticket 5118
BOOST_TEST(path("foo.txt").replace_extension(".tar.bz2") BOOST_TEST(path("foo.txt").replace_extension(".tar.bz2") == "foo.tar.bz2"); // ticket 5118
== "foo.tar.bz2"); // ticket 5118
} }
// make_preferred_tests ------------------------------------------------------------// // make_preferred_tests ------------------------------------------------------------//
@ -1805,13 +1805,11 @@ namespace
if (platform == "Windows") if (platform == "Windows")
{ {
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() == path("\\\\abc\\def\\ghi").native());
== path("\\\\abc\\def\\ghi").native());
} }
else else
{ {
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() == path("//abc\\def/ghi").native());
== path("//abc\\def/ghi").native());
} }
} }
@ -1958,9 +1956,7 @@ int cpp_main(int, char*[])
// The choice of platform is make at runtime rather than compile-time // The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though // so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested. // only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
? "Windows"
: "POSIX";
std::cout << "Platform is " << platform << '\n'; std::cout << "Platform is " << platform << '\n';
BOOST_TEST(p1.string() != p3.string()); BOOST_TEST(p1.string() != p3.string());

View File

@ -36,8 +36,7 @@ using namespace boost::timer;
using std::cout; using std::cout;
using std::endl; using std::endl;
namespace namespace {
{
boost::int64_t max_cycles; boost::int64_t max_cycles;
template< class STD_STRING > template< class STD_STRING >

View File

@ -64,8 +64,7 @@ using std::wstring;
#pragma warning(disable : 4428) // Disable universal-character-name encountered in source warning. #pragma warning(disable : 4428) // Disable universal-character-name encountered in source warning.
#endif #endif
namespace namespace {
{
boost::system::error_code ec; boost::system::error_code ec;
const boost::system::error_code ok; const boost::system::error_code ok;
@ -73,10 +72,10 @@ namespace
std::string platform(BOOST_PLATFORM); std::string platform(BOOST_PLATFORM);
void check_path(const path& source, void check_path(const path& source, const wstring& expected, const char* file, int line)
const wstring& expected, const char* file, int line)
{ {
if (source == expected) return; if (source == expected)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
@ -88,19 +87,19 @@ namespace
} }
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
void check_native(const path& p, void check_native(const path& p, const string&, const wstring& expected, const char* file, int line)
const string&, const wstring& expected, const char* file, int line)
#else #else
void check_native(const path& p, void check_native(const path& p, const string& expected, const wstring&, const char* file, int line)
const string& expected, const wstring&, const char* file, int line)
#endif #endif
{ {
if (p.native() == expected) return; if (p.native() == expected)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
std::cout << file << '(' << line << "): native() is not equal expected\n" std::cout << file << '(' << line << "): native() is not equal expected\n"
" native---: " << std::hex; " native---: "
<< std::hex;
path::string_type nat(p.native()); path::string_type nat(p.native());
for (path::string_type::const_iterator it = nat.begin(); it != nat.end(); ++it) for (path::string_type::const_iterator it = nat.begin(); it != nat.end(); ++it)
std::cout << long(*it) << ' '; std::cout << long(*it) << ' ';
@ -111,10 +110,10 @@ namespace
} }
template< class T1, class T2 > template< class T1, class T2 >
void check_equal(const T1& value, void check_equal(const T1& value, const T2& expected, const char* file, int line)
const T2& expected, const char* file, int line)
{ {
if (value == expected) return; if (value == expected)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
@ -127,7 +126,8 @@ namespace
void check(bool ok_, const char* file, int line) void check(bool ok_, const char* file, int line)
{ {
if (ok_) return; if (ok_)
return;
++::boost::detail::test_errors(); ++::boost::detail::test_errors();
@ -141,9 +141,15 @@ namespace
std::vector< char > v; // see main() for initialization to f, u, z std::vector< char > v; // see main() for initialization to f, u, z
std::vector< wchar_t > wv; // see main() for initialization to w, f, u, z std::vector< wchar_t > wv; // see main() for initialization to w, f, u, z
class Base {}; class Base
class Derived : public Base {}; {
void fun(const boost::shared_ptr< Base >&) {} };
class Derived : public Base
{
};
void fun(const boost::shared_ptr< Base >&)
{
}
// test_constructors ---------------------------------------------------------------// // test_constructors ---------------------------------------------------------------//
@ -299,10 +305,8 @@ namespace
if (!from2.empty()) if (!from2.empty())
cout << "Note: move assignment did not result in empty rhs path" << endl; cout << "Note: move assignment did not result in empty rhs path" << endl;
#else #else
std::cout << std::cout << "Test skipped because compiler does not support move semantics" << std::endl;
"Test skipped because compiler does not support move semantics" << std::endl;
#endif #endif
} }
// test_appends --------------------------------------------------------------------// // test_appends --------------------------------------------------------------------//
@ -819,7 +823,6 @@ namespace
CHECK(p2.has_extension()); CHECK(p2.has_extension());
CHECK(p2.is_absolute()); CHECK(p2.is_absolute());
CHECK(!p2.is_relative()); CHECK(!p2.is_relative());
} }
// test_imbue_locale ---------------------------------------------------------------// // test_imbue_locale ---------------------------------------------------------------//
@ -958,43 +961,45 @@ namespace
// test_error_handling -------------------------------------------------------------// // test_error_handling -------------------------------------------------------------//
class error_codecvt class error_codecvt :
: public std::codecvt< wchar_t, char, std::mbstate_t > public std::codecvt< wchar_t, char, std::mbstate_t >
{ {
public: public:
explicit error_codecvt() explicit error_codecvt() :
: std::codecvt<wchar_t, char, std::mbstate_t>() {} std::codecvt< wchar_t, char, std::mbstate_t >()
protected: {
}
protected:
virtual bool do_always_noconv() const throw() { return false; } virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; } virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&, virtual std::codecvt_base::result do_in(std::mbstate_t&, const char*, const char*, const char*&, wchar_t*, wchar_t*, wchar_t*&) const
const char*, const char*, const char*&,
wchar_t*, wchar_t*, wchar_t*&) const
{ {
static std::codecvt_base::result r = std::codecvt_base::noconv; static std::codecvt_base::result r = std::codecvt_base::noconv;
if (r == std::codecvt_base::partial) r = std::codecvt_base::error; if (r == std::codecvt_base::partial)
else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; r = std::codecvt_base::error;
else r = std::codecvt_base::partial; else if (r == std::codecvt_base::error)
r = std::codecvt_base::noconv;
else
r = std::codecvt_base::partial;
return r; return r;
} }
virtual std::codecvt_base::result do_out(std::mbstate_t &, virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t*, const wchar_t*, const wchar_t*&, char*, char*, char*&) const
const wchar_t*, const wchar_t*, const wchar_t*&,
char*, char*, char*&) const
{ {
static std::codecvt_base::result r = std::codecvt_base::noconv; static std::codecvt_base::result r = std::codecvt_base::noconv;
if (r == std::codecvt_base::partial) r = std::codecvt_base::error; if (r == std::codecvt_base::partial)
else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; r = std::codecvt_base::error;
else r = std::codecvt_base::partial; else if (r == std::codecvt_base::error)
r = std::codecvt_base::noconv;
else
r = std::codecvt_base::partial;
return r; return r;
} }
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char*, char*, char*&) const { return ok; }
char*, char*, char* &) const { return ok; } virtual int do_length(std::mbstate_t&, const char*, const char*, std::size_t) const { return 0; }
virtual int do_length(std::mbstate_t &,
const char*, const char*, std::size_t) const { return 0; }
virtual int do_max_length() const throw() { return 0; } virtual int do_max_length() const throw() { return 0; }
}; };
@ -1019,42 +1024,57 @@ namespace
{ {
std::cout << " testing std::codecvt_base::partial error..." << std::endl; std::cout << " testing std::codecvt_base::partial error..." << std::endl;
bool exception_thrown(false); bool exception_thrown(false);
try { path(STRING_FOO_); } try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex) catch (const bs::system_error& ex)
{ {
exception_thrown = true; exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, fs::codecvt_error_category()));
fs::codecvt_error_category())); }
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
} }
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown); BOOST_TEST(exception_thrown);
} }
{ {
std::cout << " testing std::codecvt_base::error error..." << std::endl; std::cout << " testing std::codecvt_base::error error..." << std::endl;
bool exception_thrown(false); bool exception_thrown(false);
try { path(STRING_FOO_); } try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex) catch (const bs::system_error& ex)
{ {
exception_thrown = true; exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, fs::codecvt_error_category()));
fs::codecvt_error_category())); }
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
} }
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown); BOOST_TEST(exception_thrown);
} }
{ {
std::cout << " testing std::codecvt_base::noconv error..." << std::endl; std::cout << " testing std::codecvt_base::noconv error..." << std::endl;
bool exception_thrown(false); bool exception_thrown(false);
try { path(STRING_FOO_); } try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex) catch (const bs::system_error& ex)
{ {
exception_thrown = true; exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, fs::codecvt_error_category()));
fs::codecvt_error_category())); }
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
} }
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown); BOOST_TEST(exception_thrown);
} }
@ -1079,12 +1099,10 @@ namespace
} // unnamed namespace } // unnamed namespace
namespace boost namespace boost {
{ namespace filesystem {
namespace filesystem namespace path_traits {
{
namespace path_traits
{
template<> struct is_iterator< const user_string::value_type* > { static const bool value = true; }; template<> struct is_iterator< const user_string::value_type* > { static const bool value = true; };
template<> struct is_iterator< user_string::value_type* > { static const bool value = true; }; template<> struct is_iterator< user_string::value_type* > { static const bool value = true; };
template<> struct is_iterator< user_string::iterator > { static const bool value = true; }; template<> struct is_iterator< user_string::iterator > { static const bool value = true; };
@ -1112,21 +1130,19 @@ namespace filesystem
#endif #endif
template<> template<>
user_string convert<user_string>(const string_type & source, user_string convert< user_string >(string_type const& source, system::error_code& ec)
system::error_code & ec)
{ {
user_string temp; user_string temp;
for (string_type::const_iterator it = source.begin(); for (string_type::const_iterator it = source.begin(); it != source.end(); ++it)
it != source.end(); ++it)
temp += *it - 1; temp += *it - 1;
return temp; return temp;
} }
} // namespace path_traits } // namespace path_traits
} // namespace filesystem } // namespace filesystem
} // namespace boost } // namespace boost
namespace namespace {
{
void test_user_supplied_type() void test_user_supplied_type()
{ {
@ -1158,9 +1174,7 @@ namespace
//} //}
//return not_defined; //return not_defined;
return 0 == strcmp(name, value + 1) return 0 == strcmp(name, value + 1) ? not_defined : (value[1] ? value : no_value);
? not_defined
: (value[1] ? value : no_value);
} }
#define BOOST_MACRO_VALUE(X) macro_value(#X, BOOST_STRINGIZE(=X)) #define BOOST_MACRO_VALUE(X) macro_value(#X, BOOST_STRINGIZE(=X))
@ -1239,9 +1253,7 @@ int test_main(int, char*[])
test_error_handling(); test_error_handling();
#if 0 #if 0
test_user_supplied_type(); test_user_supplied_type();
#endif #endif
std::string foo("\\abc"); std::string foo("\\abc");

View File

@ -22,8 +22,8 @@ using boost::filesystem::path;
using std::cout; using std::cout;
using std::endl; using std::endl;
namespace namespace {
{
void lexically_relative_test() void lexically_relative_test()
{ {
cout << "lexically_relative_test..." << endl; cout << "lexically_relative_test..." << endl;
@ -93,6 +93,7 @@ namespace
// paths unrelated // paths unrelated
BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c"); BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c");
} }
} // unnamed namespace } // unnamed namespace
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//

View File

@ -30,8 +30,7 @@ using std::endl;
using std::string; using std::string;
using std::wstring; using std::wstring;
namespace namespace {
{
bool cleanup = true; bool cleanup = true;
} }

View File

@ -27,21 +27,20 @@
// // // //
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
class test_codecvt class test_codecvt :
: public std::codecvt< wchar_t, char, std::mbstate_t > public std::codecvt< wchar_t, char, std::mbstate_t >
{ {
public: public:
explicit test_codecvt() explicit test_codecvt() :
: std::codecvt<wchar_t, char, std::mbstate_t>() {} std::codecvt< wchar_t, char, std::mbstate_t >()
{
}
protected: protected:
virtual bool do_always_noconv() const throw() { return false; } virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; } virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&, virtual std::codecvt_base::result do_in(std::mbstate_t&, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
const char* from, const char* from_end, 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) for (; from != from_end && to != to_end; ++from, ++to)
*to = wchar_t(*from + 1); *to = wchar_t(*from + 1);
@ -53,9 +52,7 @@
return ok; return ok;
} }
virtual std::codecvt_base::result do_out(std::mbstate_t&, 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
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) for (; from != from_end && to != to_end; ++from, ++to)
*to = static_cast< char >(*from - 1); *to = static_cast< char >(*from - 1);
@ -67,12 +64,8 @@
return ok; return ok;
} }
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
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_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; } virtual int do_max_length() const throw() { return 0; }
}; };