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

Function create_directory

src/operations.cpp:3442–3511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3440}
3441
3442BOOST_FILESYSTEM_DECL
3443bool create_directory(path const& p, const path* existing, error_code* ec)
3444{
3445 if (ec)
3446 ec->clear();
3447
3448#if defined(BOOST_FILESYSTEM_POSIX_API)
3449
3450 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
3451 if (existing)
3452 {
3453#if defined(BOOST_FILESYSTEM_USE_STATX)
3454 struct ::statx existing_stat;
3455 if (BOOST_UNLIKELY(invoke_statx(AT_FDCWD, existing->c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_MODE, &existing_stat) < 0))
3456 {
3457 emit_error(errno, p, *existing, ec, "boost::filesystem::create_directory");
3458 return false;
3459 }
3460
3461 if (BOOST_UNLIKELY((existing_stat.stx_mask & (STATX_TYPE | STATX_MODE)) != (STATX_TYPE | STATX_MODE)))
3462 {
3463 emit_error(BOOST_ERROR_NOT_SUPPORTED, p, *existing, ec, "boost::filesystem::create_directory");
3464 return false;
3465 }
3466#else
3467 struct ::stat existing_stat;
3468 if (::stat(existing->c_str(), &existing_stat) < 0)
3469 {
3470 emit_error(errno, p, *existing, ec, "boost::filesystem::create_directory");
3471 return false;
3472 }
3473#endif
3474
3475 const mode_t existing_mode = get_mode(existing_stat);
3476 if (!S_ISDIR(existing_mode))
3477 {
3478 emit_error(ENOTDIR, p, *existing, ec, "boost::filesystem::create_directory");
3479 return false;
3480 }
3481
3482 mode = existing_mode;
3483 }
3484
3485 if (::mkdir(p.c_str(), mode) == 0)
3486 return true;
3487
3488#else // defined(BOOST_FILESYSTEM_POSIX_API)
3489
3490 BOOL res;
3491 if (existing)
3492 res = ::CreateDirectoryExW(existing->c_str(), p.c_str(), nullptr);
3493 else
3494 res = ::CreateDirectoryW(p.c_str(), nullptr);
3495
3496 if (res)
3497 return true;
3498
3499#endif // defined(BOOST_FILESYSTEM_POSIX_API)

Callers 15

copyFunction · 0.70
create_directoriesFunction · 0.70
bad_create_directoryFunction · 0.50
exception_testsFunction · 0.50
create_treeFunction · 0.50
directory_iterator_testsFunction · 0.50
create_directory_testsFunction · 0.50
remove_testsFunction · 0.50
remove_all_testsFunction · 0.50
remove_all_symlink_testsFunction · 0.50
cpp_mainFunction · 0.50

Calls 7

invoke_statxFunction · 0.85
emit_errorFunction · 0.85
get_modeFunction · 0.85
clearMethod · 0.80
statClass · 0.70
is_directoryFunction · 0.50
c_strMethod · 0.45

Tested by 15

bad_create_directoryFunction · 0.40
exception_testsFunction · 0.40
create_treeFunction · 0.40
directory_iterator_testsFunction · 0.40
create_directory_testsFunction · 0.40
remove_testsFunction · 0.40
remove_all_testsFunction · 0.40
remove_all_symlink_testsFunction · 0.40
cpp_mainFunction · 0.40
operations_testFunction · 0.40
directory_entry_testFunction · 0.40