xref: /freebsd/contrib/llvm-project/libcxx/src/filesystem/filesystem_error.cpp (revision 770cf0a5f02dc8983a89c6568d741fbc25baa999)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <__config>
10 #include <__memory/shared_ptr.h>
11 #include <__utility/unreachable.h>
12 #include <filesystem>
13 #include <system_error>
14 
15 #include "format_string.h"
16 
17 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
18 
19 filesystem_error::~filesystem_error() {}
20 
21 void filesystem_error::__create_what(int __num_paths) {
22   const char* derived_what = system_error::what();
23   __storage_->__what_      = [&]() -> string {
24     switch (__num_paths) {
25     case 0:
26       return detail::format_string("filesystem error: %s", derived_what);
27     case 1:
28       return detail::format_string("filesystem error: %s [" PATH_CSTR_FMT "]", derived_what, path1().c_str());
29     case 2:
30       return detail::format_string(
31           "filesystem error: %s [" PATH_CSTR_FMT "] [" PATH_CSTR_FMT "]",
32           derived_what,
33           path1().c_str(),
34           path2().c_str());
35     }
36     __libcpp_unreachable();
37   }();
38 }
39 
40 _LIBCPP_END_NAMESPACE_FILESYSTEM
41