Skip to content

Commit ae458c7

Browse files
committed
Switch to POSIX API on Cygwin.
This follows other Boost libraries (in particular, Boost.System) in treating Cygwin as a POSIX platform rather than Windows. This is a breaking change, but apparently downstream Boost.Filesystem packages on Cygwin are patched to the same effect. As part of this change, AT_NO_AUTOMOUNT is made an optional requirement to enable POSIX *at APIs. This flag is not POSIX-standard and is not supported on Cygwin, while *at APIs are.
1 parent 43ccf9f commit ae458c7

File tree

12 files changed

+36
-17
lines changed

12 files changed

+36
-17
lines changed

build/Jamfile.v2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ rule select-windows-crypto-api ( properties * )
3939
{
4040
local result ;
4141

42-
if <target-os>windows in $(properties) || <target-os>cygwin in $(properties)
42+
if <target-os>windows in $(properties)
4343
{
4444
if ! [ has-config-flag BOOST_FILESYSTEM_DISABLE_BCRYPT : $(properties) ] &&
4545
[ configure.builds ../config//has_bcrypt : $(properties) : "has BCrypt API" ]
@@ -175,10 +175,6 @@ project
175175
<target-os>windows:<define>_WIN32_WINNT=0x0A00
176176
<target-os>windows:<define>WIN32_LEAN_AND_MEAN
177177
<target-os>windows:<define>NOMINMAX
178-
<target-os>cygwin:<define>BOOST_USE_WINDOWS_H
179-
<target-os>cygwin:<define>_WIN32_WINNT=0x0A00
180-
<target-os>cygwin:<define>WIN32_LEAN_AND_MEAN
181-
<target-os>cygwin:<define>NOMINMAX
182178

183179
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
184180
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105651
@@ -207,7 +203,7 @@ rule select-platform-specific-sources ( properties * )
207203
{
208204
local result ;
209205

210-
if <target-os>windows in $(properties) || <target-os>cygwin in $(properties)
206+
if <target-os>windows in $(properties)
211207
{
212208
result += <source>windows_file_codecvt.cpp ;
213209
}

config/has_posix_at_apis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main()
2222
res |= renameat(AT_FDCWD, "x", fd1, "y");
2323

2424
struct stat st;
25-
res |= fstatat(fd1, "y", &st, AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW);
25+
res |= fstatat(fd1, "y", &st, AT_SYMLINK_NOFOLLOW);
2626

2727
res |= linkat(fd1, "y", fd1, "z", 0);
2828
res |= symlinkat("foo/z", fd1, "sz");

doc/index.htm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ <h3>Note for <a name="Cygwin">Cygwin</a> users</h3>
338338
<p> <a href="http://www.cygwin.com/">Cygwin</a> version 1.7 or later is
339339
required because only versions of GCC with wide character strings are supported.</p>
340340

341-
<p> The library's implementation code treats Cygwin as a Windows platform, and
342-
thus uses the Windows API and uses Windows path syntax as the native path
341+
<p> The library's implementation code treats Cygwin as a POSIX platform, and
342+
thus uses the POSIX API and POSIX path syntax as the native path
343343
syntax.</p>
344344

345345
<h2><a name="Change-history">Version history</a></h2>

doc/release_history.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@
4242

4343
<h2>1.91.0</h2>
4444
<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>
45+
<li>Boost.Filesystem now defines and uses its own platform macros <code>BOOST_FILESYSTEM_POSIX_API</code> and <code>BOOST_FILESYSTEM_WINDOWS_API</code>. The old <code>BOOST_POSIX_API</code> and <code>BOOST_WINDOWS_API</code> macros are still defined by Boost.System.</li>
4646
<li>On POSIX platforms not supporting <code>openat</code> and related APIs, fixed an error reported by <code>recursive_directory_iterator</code> increment when the iterator encounters a dangling symlink and following symlinks is disabled.</li>
47+
<li><b>Breaking change for Cygwin users.</b> The library now treats Cygwin as a POSIX platform. This has several user-facing consequences, in particular:
48+
<ul>
49+
<li>The <code>path::value_type</code> type has changed from <code>wchar_t</code> to <code>char</code>. As on other POSIX platforms, wide character paths will be converted to the narrow character encoding using the locale set by <code>path::imbue</code>. Note that since Cygwin is running on top of Windows, it will also perform character code conversion internally. It is important that locale in the Cygwin environment is configured correctly.</li>
50+
<li>Path syntax now follows POSIX conventions, Windows-specific paths (e.g. UNC paths, drive names and path prefixes) are not supported.</li>
51+
<li>Certain Windows-specific parts of the API will become inaccessible. Since reparse points are a Windows-only feature, <code>file_type::reparse_file</code> will not be reported for files. Reparse point handling is dependent on Cygwin runtime behavior.</li>
52+
<li>Cygwin has its own implementation of symlinks that is incompatible with native Windows symlinks. Boost.Filesystem will now create and operate on Cygwin symlinks.</li>
53+
<li>Error codes reported by Boost.Filesystem will now use POSIX <code>errno</code> values.</li>
54+
</ul>
55+
</li>
4756
</ul>
4857

4958
<h2>1.90.0</h2>

doc/v3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ <h3>Compiler support</h3>
134134
supported.<br/>
135135
&nbsp;</li>
136136
<li>Cygwin versions prior to 1.7 are no longer supported because they lack
137-
wide string support. Cygwin now compiles only for the Windows API and path
137+
wide string support. Cygwin now compiles only for the POSIX API and path
138138
syntax.<br/>
139139
&nbsp;</li>
140140
<li>MinGW versions not supporting wide strings are no longer supported.<br/>

include/boost/filesystem/config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
#error BOOST_FILESYSTEM_WINDOWS_API and BOOST_FILESYSTEM_POSIX_API must not be defined by users
6060
#endif
6161

62-
// Cygwin is treated as Windows to minimize path character code conversions
63-
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
62+
// Note: Cygwin is treated as a POSIX platform
63+
#if defined(BOOST_WINDOWS)
6464
#define BOOST_FILESYSTEM_WINDOWS_API
6565
#else
6666
#define BOOST_FILESYSTEM_POSIX_API

src/operations.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ using boost::system::system_category;
186186
#define BOOST_FILESYSTEM_NO_O_CLOEXEC
187187
#endif
188188

189+
// At least Cygwin (cygwin1.dll 3.6.5, as of 2025-12-25) doesn't support AT_NO_AUTOMOUNT
190+
#ifndef AT_NO_AUTOMOUNT
191+
#define AT_NO_AUTOMOUNT 0
192+
#endif
193+
189194
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
190195
#define BOOST_FILESYSTEM_HAS_FDATASYNC
191196
#endif

src/platform_config.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@
6868
#define _INCLUDE_STDCSOURCE_199901
6969
#endif
7070

71-
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || \
72-
defined(__CYGWIN__)
71+
#if defined(__CYGWIN__)
72+
#ifndef _GNU_SOURCE
73+
#define _GNU_SOURCE
74+
#endif
75+
#elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
7376
// Define target Windows version macros before including any other headers
7477
#include <boost/winapi/config.hpp>
7578
#endif

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ rule check-mklink ( properties * )
4949
project
5050
: requirements
5151
<include>.
52+
<include>../src
5253
<target-os>windows:<define>_SCL_SECURE_NO_WARNINGS
5354
<target-os>windows:<define>_SCL_SECURE_NO_DEPRECATE
5455
<target-os>windows:<define>_CRT_SECURE_NO_WARNINGS

test/deprecated_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
7878
// The choice of platform is make at runtime rather than compile-time
7979
// so that compile errors for all platforms will be detected even though
8080
// only the current platform is runtime tested.
81-
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
81+
platform = (platform == "Win32" || platform == "Win64") ? "Windows" : "POSIX";
8282
std::cout << "Platform is " << platform << '\n';
8383

8484
l.push_back('s');

0 commit comments

Comments
 (0)