|
1 | 1 | // filesystem path.cpp ------------------------------------------------------------- // |
2 | 2 |
|
3 | 3 | // Copyright Beman Dawes 2008 |
4 | | -// Copyright Andrey Semashev 2021-2024 |
| 4 | +// Copyright Andrey Semashev 2021-2025 |
5 | 5 |
|
6 | 6 | // Distributed under the Boost Software License, Version 1.0. |
7 | 7 | // See http://www.boost.org/LICENSE_1_0.txt |
|
28 | 28 | #include "windows_file_codecvt.hpp" |
29 | 29 | #include "windows_tools.hpp" |
30 | 30 | #include <windows.h> |
31 | | -#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) |
| 31 | +#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || \ |
| 32 | + defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__NETBSD__) || defined(__NetBSD__) || \ |
| 33 | + defined(sun) || defined(__sun) || \ |
| 34 | + defined(__HAIKU__) |
| 35 | +// "All BSD system functions expect their string parameters to be in UTF-8 encoding |
| 36 | +// and nothing else." See |
| 37 | +// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html |
| 38 | +// |
| 39 | +// "The kernel will reject any filename that is not a valid UTF-8 string, and it will |
| 40 | +// even be normalized (to Unicode NFD) before stored on disk, at least when using HFS. |
| 41 | +// The right way to deal with it would be to always convert the filename to UTF-8 |
| 42 | +// before trying to open/create a file." See |
| 43 | +// http://lists.apple.com/archives/unix-porting/2007/Sep/msg00023.html |
| 44 | +// |
| 45 | +// "How a file name looks at the API level depends on the API. Current Carbon APIs |
| 46 | +// handle file names as an array of UTF-16 characters; POSIX ones handle them as an |
| 47 | +// array of UTF-8, which is why UTF-8 works well in Terminal. How it's stored on disk |
| 48 | +// depends on the disk format; HFS+ uses UTF-16, but that's not important in most |
| 49 | +// cases." See |
| 50 | +// http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html |
| 51 | +// |
| 52 | +// Many thanks to Peter Dimov for digging out the above references! |
| 53 | +// |
| 54 | +// BSD systems have historically been largely encoding-agnostic wrt. filesystem paths, |
| 55 | +// but more recent versions have come to universally use UTF-8. |
| 56 | +// |
| 57 | +// On DragonFly BSD 6.4.0, std::locale("") fails unless LANG is set to some locale that |
| 58 | +// is supported in libc. |
| 59 | +// |
| 60 | +// On Solaris 11.4, std::locale("") fails even if LANG is set correctly in the environment. |
| 61 | +// Recent versions of Solaris seem to have transitioned to UTF-8 for filename encoding. |
32 | 62 | #include <boost/filesystem/detail/utf8_codecvt_facet.hpp> |
| 63 | +#define BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET |
33 | 64 | #endif |
34 | 65 |
|
35 | 66 | #ifdef BOOST_FILESYSTEM_DEBUG |
@@ -1427,26 +1458,7 @@ std::locale default_locale() |
1427 | 1458 | #if defined(BOOST_FILESYSTEM_WINDOWS_API) |
1428 | 1459 | std::locale global_loc = std::locale(); |
1429 | 1460 | return std::locale(global_loc, new boost::filesystem::detail::windows_file_codecvt()); |
1430 | | -#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) |
1431 | | - // "All BSD system functions expect their string parameters to be in UTF-8 encoding |
1432 | | - // and nothing else." See |
1433 | | - // http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html |
1434 | | - // |
1435 | | - // "The kernel will reject any filename that is not a valid UTF-8 string, and it will |
1436 | | - // even be normalized (to Unicode NFD) before stored on disk, at least when using HFS. |
1437 | | - // The right way to deal with it would be to always convert the filename to UTF-8 |
1438 | | - // before trying to open/create a file." See |
1439 | | - // http://lists.apple.com/archives/unix-porting/2007/Sep/msg00023.html |
1440 | | - // |
1441 | | - // "How a file name looks at the API level depends on the API. Current Carbon APIs |
1442 | | - // handle file names as an array of UTF-16 characters; POSIX ones handle them as an |
1443 | | - // array of UTF-8, which is why UTF-8 works well in Terminal. How it's stored on disk |
1444 | | - // depends on the disk format; HFS+ uses UTF-16, but that's not important in most |
1445 | | - // cases." See |
1446 | | - // http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html |
1447 | | - // |
1448 | | - // Many thanks to Peter Dimov for digging out the above references! |
1449 | | - |
| 1461 | +#elif defined(BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET) |
1450 | 1462 | std::locale global_loc = std::locale(); |
1451 | 1463 | return std::locale(global_loc, new boost::filesystem::detail::utf8_codecvt_facet()); |
1452 | 1464 | #else // Other POSIX |
|
0 commit comments