|
38 | 38 | #endif |
39 | 39 | #include <cerrno> |
40 | 40 |
|
| 41 | +// Default to POSIX under Emscripten. If BOOST_FILESYSTEM_EMSCRIPTEN_USE_WASI is set, use WASI instead. |
| 42 | +#if defined(__wasm) && (!defined(__EMSCRIPTEN__) || defined(BOOST_FILESYSTEM_EMSCRIPTEN_USE_WASI)) |
| 43 | +#define BOOST_FILESYSTEM_USE_WASI |
| 44 | +#endif |
| 45 | + |
41 | 46 | #ifdef BOOST_POSIX_API |
42 | 47 |
|
43 | 48 | #include <sys/types.h> |
44 | 49 | #include <sys/stat.h> |
45 | 50 |
|
46 | | -#if defined(__wasm) |
| 51 | +#if defined(BOOST_FILESYSTEM_USE_WASI) |
47 | 52 | // WASI does not have statfs or statvfs. |
48 | 53 | #elif !defined(__APPLE__) && \ |
49 | 54 | (!defined(__OpenBSD__) || BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(4, 4, 0)) && \ |
@@ -2220,7 +2225,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod |
2220 | 2225 | } |
2221 | 2226 |
|
2222 | 2227 | mode_t to_mode = from_mode; |
2223 | | -#if !defined(__wasm) |
| 2228 | +#if !defined(BOOST_FILESYSTEM_USE_WASI) |
2224 | 2229 | // Enable writing for the newly created files. Having write permission set is important e.g. for NFS, |
2225 | 2230 | // which checks the file permission on the server, even if the client's file descriptor supports writing. |
2226 | 2231 | to_mode |= S_IWUSR; |
@@ -2339,7 +2344,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod |
2339 | 2344 | if (BOOST_UNLIKELY(err != 0)) |
2340 | 2345 | goto fail; // err already contains the error code |
2341 | 2346 |
|
2342 | | -#if !defined(__wasm) |
| 2347 | +#if !defined(BOOST_FILESYSTEM_USE_WASI) |
2343 | 2348 | // If we created a new file with an explicitly added S_IWUSR permission, |
2344 | 2349 | // we may need to update its mode bits to match the source file. |
2345 | 2350 | if (to_mode != from_mode) |
@@ -2775,7 +2780,7 @@ void create_symlink(path const& to, path const& from, error_code* ec) |
2775 | 2780 | BOOST_FILESYSTEM_DECL |
2776 | 2781 | path current_path(error_code* ec) |
2777 | 2782 | { |
2778 | | -#if defined(UNDER_CE) || defined(__wasm) |
| 2783 | +#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_USE_WASI) |
2779 | 2784 | // Windows CE has no current directory, so everything's relative to the root of the directory tree. |
2780 | 2785 | // WASI also does not support current path. |
2781 | 2786 | emit_error(BOOST_ERROR_NOT_SUPPORTED, ec, "boost::filesystem::current_path"); |
@@ -2845,7 +2850,7 @@ path current_path(error_code* ec) |
2845 | 2850 | BOOST_FILESYSTEM_DECL |
2846 | 2851 | void current_path(path const& p, system::error_code* ec) |
2847 | 2852 | { |
2848 | | -#if defined(UNDER_CE) || defined(__wasm) |
| 2853 | +#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_USE_WASI) |
2849 | 2854 | emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::current_path"); |
2850 | 2855 | #else |
2851 | 2856 | error(!BOOST_SET_CURRENT_DIRECTORY(p.c_str()) ? BOOST_ERRNO : 0, p, ec, "boost::filesystem::current_path"); |
@@ -3349,7 +3354,7 @@ void permissions(path const& p, perms prms, system::error_code* ec) |
3349 | 3354 | if ((prms & add_perms) && (prms & remove_perms)) // precondition failed |
3350 | 3355 | return; |
3351 | 3356 |
|
3352 | | -#if defined(__wasm) |
| 3357 | +#if defined(BOOST_FILESYSTEM_USE_WASI) |
3353 | 3358 | emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::permissions"); |
3354 | 3359 | #elif defined(BOOST_POSIX_API) |
3355 | 3360 | error_code local_ec; |
@@ -3613,7 +3618,7 @@ space_info space(path const& p, error_code* ec) |
3613 | 3618 | if (ec) |
3614 | 3619 | ec->clear(); |
3615 | 3620 |
|
3616 | | -#if defined(__wasm) |
| 3621 | +#if defined(BOOST_FILESYSTEM_USE_WASI) |
3617 | 3622 |
|
3618 | 3623 | emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::space"); |
3619 | 3624 |
|
|
0 commit comments