| 3440 | } |
| 3441 | |
| 3442 | BOOST_FILESYSTEM_DECL |
| 3443 | bool 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) |