MCPcopy Create free account
hub / github.com/boostorg/filesystem / current_path

Function current_path

src/operations.cpp:3599–3667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3597}
3598
3599BOOST_FILESYSTEM_DECL
3600path current_path(error_code* ec)
3601{
3602#if defined(BOOST_FILESYSTEM_USE_WASI)
3603 // Windows CE has no current directory, so everything's relative to the root of the directory tree.
3604 // WASI also does not support current path.
3605 emit_error(BOOST_ERROR_NOT_SUPPORTED, ec, "boost::filesystem::current_path");
3606 return path();
3607#elif defined(BOOST_FILESYSTEM_POSIX_API)
3608 struct local
3609 {
3610 static bool getcwd_error(error_code* ec)
3611 {
3612 const int err = errno;
3613 return error((err != ERANGE
3614#if defined(__MSL__) && (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
3615 // bug in some versions of the Metrowerks C lib on the Mac: wrong errno set
3616 && err != 0
3617#endif
3618 ) ? err : 0,
3619 ec, "boost::filesystem::current_path");
3620 }
3621 };
3622
3623 path cur;
3624 char small_buf[small_path_size];
3625 const char* p = ::getcwd(small_buf, sizeof(small_buf));
3626 if (BOOST_LIKELY(!!p))
3627 {
3628 cur = p;
3629 if (ec)
3630 ec->clear();
3631 }
3632 else if (BOOST_LIKELY(!local::getcwd_error(ec)))
3633 {
3634 for (std::size_t path_max = sizeof(small_buf) * 2u;; path_max *= 2u) // loop 'til buffer large enough
3635 {
3636 if (BOOST_UNLIKELY(path_max > absolute_path_max))
3637 {
3638 emit_error(ENAMETOOLONG, ec, "boost::filesystem::current_path");
3639 break;
3640 }
3641
3642 std::unique_ptr< char[] > buf(new char[path_max]);
3643 p = ::getcwd(buf.get(), path_max);
3644 if (BOOST_LIKELY(!!p))
3645 {
3646 cur = buf.get();
3647 if (ec)
3648 ec->clear();
3649 break;
3650 }
3651 else if (BOOST_UNLIKELY(local::getcwd_error(ec)))
3652 {
3653 break;
3654 }
3655 }
3656 }

Callers 15

absolute_v3Function · 0.70
absolute_v4Function · 0.70
copyFunction · 0.70
initial_pathFunction · 0.70
relativeFunction · 0.70
space_info spaceFunction · 0.70
system_completeFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50
bad_directory_sizeFunction · 0.50
directory_iterator_testsFunction · 0.50
current_directory_testsFunction · 0.50

Calls 6

emit_errorFunction · 0.85
errorFunction · 0.85
clearMethod · 0.80
getMethod · 0.80
pathFunction · 0.50
c_strMethod · 0.45

Tested by 12

bad_directory_sizeFunction · 0.40
directory_iterator_testsFunction · 0.40
current_directory_testsFunction · 0.40
remove_all_symlink_testsFunction · 0.40
absolute_testsFunction · 0.40
canonical_basic_testsFunction · 0.40
platform_specific_testsFunction · 0.40
initial_testsFunction · 0.40
cpp_mainFunction · 0.40
test_copy_file_symlinksFunction · 0.40
cpp_mainFunction · 0.40