Skip to content

Commit 36cff31

Browse files
committed
Define Boost-Filesystem-specific macros for platform API selection.
Because Boost.System has switched to define BOOST_POSIX_API on Cygwin[1], Boost.Filesystem now defines its own set of macros for platform API selection. At this time, we preserve the previous behavior, where Cygwin is treated as Windows. [1]: boostorg/system#137
1 parent c172ae5 commit 36cff31

26 files changed

+232
-215
lines changed

doc/release_history.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
</tr>
4141
</table>
4242

43+
<h2>1.91.0</h2>
44+
<ul>
45+
<li>Due to a change in Boost.System, Boost.Filesystem now defines and uses its own platform macros <code>BOOST_FILESYSTEM_POSIX_API</code> and <code>BOOST_FILESYSTEM_WINDOWS_API</code>. These macros may not necessarily match the old <code>BOOST_POSIX_API</code> and <code>BOOST_WINDOWS_API</code> macros defined by Boost.System.</li>
46+
</ul>
47+
4348
<h2>1.90.0</h2>
4449
<ul>
4550
<li>Clear passed <code>error_code</code> argument on successful completion of the <code>permissions</code> operation. (<a href="https://github.com/boostorg/filesystem/pull/338">PR#338</a>)</li>

doc/tutorial.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,9 +1000,9 @@ <h2><a name="Class path-iterators-etc">Class path: Iterators, observers, composi
10001000
cout &lt;&lt; &quot;Usage: path_info path-element [path-element...]\n&quot;
10011001
&quot;Composes a path via operator/= from one or more path-element arguments\n&quot;
10021002
&quot;Example: path_info foo/bar baz\n&quot;
1003-
# ifdef BOOST_POSIX_API
1003+
# ifdef BOOST_FILESYSTEM_POSIX_API
10041004
&quot; would report info about the composed path foo/bar/baz\n&quot;;
1005-
# else // BOOST_WINDOWS_API
1005+
# else // BOOST_FILESYSTEM_WINDOWS_API
10061006
&quot; would report info about the composed path foo/bar\\baz\n&quot;;
10071007
# endif
10081008
return 1;
@@ -1021,10 +1021,10 @@ <h2><a name="Class path-iterators-etc">Class path: Iterators, observers, composi
10211021
cout &lt;&lt; &quot; &quot; &lt;&lt; element &lt;&lt; '\n';
10221022

10231023
cout &lt;&lt; &quot;\nobservers, native format:&quot; &lt;&lt; endl;
1024-
# ifdef BOOST_POSIX_API
1024+
# ifdef BOOST_FILESYSTEM_POSIX_API
10251025
cout &lt;&lt; &quot; native()-------------: &quot; &lt;&lt; p.native() &lt;&lt; endl;
10261026
cout &lt;&lt; &quot; c_str()--------------: &quot; &lt;&lt; p.c_str() &lt;&lt; endl;
1027-
# else // BOOST_WINDOWS_API
1027+
# else // BOOST_FILESYSTEM_WINDOWS_API
10281028
wcout &lt;&lt; L&quot; native()-------------: &quot; &lt;&lt; p.native() &lt;&lt; endl;
10291029
wcout &lt;&lt; L&quot; c_str()--------------: &quot; &lt;&lt; p.c_str() &lt;&lt; endl;
10301030
# endif
@@ -1229,10 +1229,10 @@ <h2><a name="Class path-iterators-etc">Class path: Iterators, observers, composi
12291229
<tr>
12301230
<td>
12311231
<pre><!-- include file "../example/path_info.cpp" --> cout &lt;&lt; &quot;\nobservers, native format:&quot; &lt;&lt; endl;
1232-
# ifdef BOOST_POSIX_API
1232+
# ifdef BOOST_FILESYSTEM_POSIX_API
12331233
cout &lt;&lt; &quot; native()-------------: &quot; &lt;&lt; p.native() &lt;&lt; endl;
12341234
cout &lt;&lt; &quot; c_str()--------------: &quot; &lt;&lt; p.c_str() &lt;&lt; endl;
1235-
# else // BOOST_WINDOWS_API
1235+
# else // BOOST_FILESYSTEM_WINDOWS_API
12361236
wcout &lt;&lt; L&quot; native()-------------: &quot; &lt;&lt; p.native() &lt;&lt; endl;
12371237
wcout &lt;&lt; L&quot; c_str()--------------: &quot; &lt;&lt; p.c_str() &lt;&lt; endl;
12381238
# endif

example/path_info.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ int main(int argc, char* argv[])
2525
cout << "Usage: path_info path-element [path-element...]\n"
2626
"Composes a path via operator/= from one or more path-element arguments\n"
2727
"Example: path_info foo/bar baz\n"
28-
#ifdef BOOST_POSIX_API
28+
#ifdef BOOST_FILESYSTEM_POSIX_API
2929
" would report info about the composed path foo/bar/baz\n";
30-
#else // BOOST_WINDOWS_API
30+
#else // BOOST_FILESYSTEM_WINDOWS_API
3131
" would report info about the composed path foo/bar\\baz\n";
3232
#endif
3333
return 1;
@@ -46,10 +46,10 @@ int main(int argc, char* argv[])
4646
cout << " " << element << '\n';
4747

4848
cout << "\nobservers, native format:" << endl;
49-
#ifdef BOOST_POSIX_API
49+
#ifdef BOOST_FILESYSTEM_POSIX_API
5050
cout << " native()-------------: " << p.native() << endl;
5151
cout << " c_str()--------------: " << p.c_str() << endl;
52-
#else // BOOST_WINDOWS_API
52+
#else // BOOST_FILESYSTEM_WINDOWS_API
5353
wcout << L" native()-------------: " << p.native() << endl;
5454
wcout << L" c_str()--------------: " << p.c_str() << endl;
5555
#endif

include/boost/filesystem/config.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// http://www.boost.org/more/separate_compilation.html
1818

1919
#include <boost/config.hpp>
20-
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
2120
#include <boost/detail/workaround.hpp>
2221

2322
#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3 && BOOST_FILESYSTEM_VERSION != 4
@@ -54,6 +53,19 @@
5453
#error Both BOOST_FILESYSTEM_DEPRECATED and BOOST_FILESYSTEM_NO_DEPRECATED are defined
5554
#endif
5655

56+
// BOOST_FILESYSTEM_WINDOWS_API or BOOST_FILESYSTEM_POSIX_API -------------------------//
57+
58+
#if defined(BOOST_FILESYSTEM_WINDOWS_API) || defined(BOOST_FILESYSTEM_POSIX_API)
59+
#error BOOST_FILESYSTEM_WINDOWS_API and BOOST_FILESYSTEM_POSIX_API must not be defined by users
60+
#endif
61+
62+
// Cygwin is treated as Windows to minimize path character code conversions
63+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
64+
#define BOOST_FILESYSTEM_WINDOWS_API
65+
#else
66+
#define BOOST_FILESYSTEM_POSIX_API
67+
#endif
68+
5769
// throw an exception ----------------------------------------------------------------//
5870
//
5971
// Exceptions were originally thrown via boost::throw_exception().

include/boost/filesystem/cstdio.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <boost/filesystem/config.hpp>
1616
#include <boost/filesystem/path.hpp>
1717
#include <cstdio>
18-
#if defined(BOOST_WINDOWS_API)
18+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
1919
#include <wchar.h>
2020
#include <cstddef>
2121
#include <cstring>
@@ -27,7 +27,7 @@
2727
namespace boost {
2828
namespace filesystem {
2929

30-
#if defined(BOOST_WINDOWS_API)
30+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
3131

3232
inline std::FILE* fopen(filesystem::path const& p, const char* mode)
3333
{
@@ -70,14 +70,14 @@ inline std::FILE* fopen(filesystem::path const& p, const char* mode)
7070
#endif
7171
}
7272

73-
#else // defined(BOOST_WINDOWS_API)
73+
#else // defined(BOOST_FILESYSTEM_WINDOWS_API)
7474

7575
inline std::FILE* fopen(filesystem::path const& p, const char* mode)
7676
{
7777
return std::fopen(p.c_str(), mode);
7878
}
7979

80-
#endif // defined(BOOST_WINDOWS_API)
80+
#endif // defined(BOOST_FILESYSTEM_WINDOWS_API)
8181

8282
} // namespace filesystem
8383
} // namespace boost

include/boost/filesystem/detail/path_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class directory_entry;
5555
namespace detail {
5656
namespace path_traits {
5757

58-
#if defined(BOOST_WINDOWS_API)
58+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
5959
typedef wchar_t path_native_char_type;
6060
#define BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE false
6161
#define BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE true

include/boost/filesystem/directory.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ namespace detail {
632632
struct dir_itr_imp :
633633
public boost::intrusive_ref_counter< dir_itr_imp >
634634
{
635-
#ifdef BOOST_WINDOWS_API
635+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
636636
bool close_handle;
637637
unsigned char extra_data_format;
638638
std::size_t current_offset;
@@ -641,7 +641,7 @@ struct dir_itr_imp :
641641
void* handle;
642642

643643
dir_itr_imp() noexcept :
644-
#ifdef BOOST_WINDOWS_API
644+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
645645
close_handle(false),
646646
extra_data_format(0u),
647647
current_offset(0u),

include/boost/filesystem/fstream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <boost/filesystem/detail/header.hpp> // must be the last #include
2222

23-
#if defined(BOOST_WINDOWS_API)
23+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
2424
// On Windows, except for standard libaries known to have wchar_t overloads for
2525
// file stream I/O, use path::string() to get a narrow character c_str()
2626
#if (defined(_CPPLIB_VER) && _CPPLIB_VER >= 405 && !defined(_STLPORT_VERSION)) || \
@@ -40,7 +40,7 @@
4040
// Use narrow characters, since wide not available
4141
#define BOOST_FILESYSTEM_C_STR(p) p.string().c_str()
4242
#endif
43-
#endif // defined(BOOST_WINDOWS_API)
43+
#endif // defined(BOOST_FILESYSTEM_WINDOWS_API)
4444

4545
#if !defined(BOOST_FILESYSTEM_C_STR)
4646
#define BOOST_FILESYSTEM_C_STR(p) p.c_str()

include/boost/filesystem/operations.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ inline path temp_directory_path(system::error_code& ec)
603603
}
604604

605605
inline path unique_path(path const& p =
606-
#if defined(BOOST_WINDOWS_API)
606+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
607607
L"%%%%-%%%%-%%%%-%%%%"
608608
#else
609609
"%%%%-%%%%-%%%%-%%%%"
@@ -617,7 +617,7 @@ inline path unique_path(system::error_code& ec)
617617
{
618618
return detail::unique_path
619619
(
620-
#if defined(BOOST_WINDOWS_API)
620+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
621621
L"%%%%-%%%%-%%%%-%%%%",
622622
#else
623623
"%%%%-%%%%-%%%%-%%%%",

include/boost/filesystem/path.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct path_algorithms
108108
BOOST_FILESYSTEM_DECL static path generic_path_v3(path const& p);
109109
BOOST_FILESYSTEM_DECL static path generic_path_v4(path const& p);
110110

111-
#if defined(BOOST_WINDOWS_API)
111+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
112112
BOOST_FILESYSTEM_DECL static void make_preferred_v3(path& p);
113113
BOOST_FILESYSTEM_DECL static void make_preferred_v4(path& p);
114114
#endif
@@ -160,7 +160,7 @@ struct path_algorithms
160160

161161
class path :
162162
public filesystem::path_detail::path_constants<
163-
#ifdef BOOST_WINDOWS_API
163+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
164164
detail::path_traits::path_native_char_type, L'/', L'\\', L'.'
165165
#else
166166
detail::path_traits::path_native_char_type, '/', '/', '.'
@@ -865,7 +865,7 @@ class path :
865865
template< typename String >
866866
String string(codecvt_type const& cvt) const;
867867

868-
#ifdef BOOST_WINDOWS_API
868+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
869869
std::string string() const
870870
{
871871
std::string tmp;
@@ -884,7 +884,7 @@ class path :
884884
// string_type is std::wstring, so there is no conversion
885885
std::wstring const& wstring() const { return m_pathname; }
886886
std::wstring const& wstring(codecvt_type const&) const { return m_pathname; }
887-
#else // BOOST_POSIX_API
887+
#else // BOOST_FILESYSTEM_POSIX_API
888888
// string_type is std::string, so there is no conversion
889889
std::string const& string() const { return m_pathname; }
890890
std::string const& string(codecvt_type const&) const { return m_pathname; }
@@ -1012,7 +1012,7 @@ class path :
10121012
bool is_relative() const { return !is_absolute(); }
10131013
bool is_absolute() const
10141014
{
1015-
#if defined(BOOST_WINDOWS_API)
1015+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
10161016
return has_root_name() && has_root_directory();
10171017
#else
10181018
return has_root_directory();
@@ -1343,12 +1343,12 @@ inline typename std::enable_if<
13431343
std::size_t
13441344
>::type hash_value(Path const& p) noexcept
13451345
{
1346-
#ifdef BOOST_WINDOWS_API
1346+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
13471347
std::size_t seed = 0u;
13481348
for (typename Path::value_type const* it = p.c_str(); *it; ++it)
13491349
hash_combine(seed, *it == L'/' ? L'\\' : *it);
13501350
return seed;
1351-
#else // BOOST_POSIX_API
1351+
#else // BOOST_FILESYSTEM_POSIX_API
13521352
return hash_range(p.native().begin(), p.native().end());
13531353
#endif
13541354
}
@@ -1416,7 +1416,7 @@ namespace detail {
14161416
inline bool is_directory_separator(path::value_type c) noexcept
14171417
{
14181418
return c == path::separator
1419-
#ifdef BOOST_WINDOWS_API
1419+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
14201420
|| c == path::preferred_separator
14211421
#endif
14221422
;
@@ -1425,7 +1425,7 @@ inline bool is_directory_separator(path::value_type c) noexcept
14251425
inline bool is_element_separator(path::value_type c) noexcept
14261426
{
14271427
return c == path::separator
1428-
#ifdef BOOST_WINDOWS_API
1428+
#ifdef BOOST_FILESYSTEM_WINDOWS_API
14291429
|| c == path::preferred_separator || c == L':'
14301430
#endif
14311431
;
@@ -1621,7 +1621,7 @@ BOOST_FORCEINLINE path path::generic_path() const
16211621
BOOST_FORCEINLINE path& path::make_preferred()
16221622
{
16231623
// No effect on POSIX
1624-
#if defined(BOOST_WINDOWS_API)
1624+
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
16251625
BOOST_FILESYSTEM_VERSIONED_SYM(detail::path_algorithms::make_preferred)(*this);
16261626
#endif
16271627
return *this;

0 commit comments

Comments
 (0)