1 // error_handling.hpp --------------------------------------------------------------------//
3 // Copyright 2002-2009, 2014 Beman Dawes
4 // Copyright 2019 Andrey Semashev
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
9 // See library home page at http://www.boost.org/libs/filesystem
11 //--------------------------------------------------------------------------------------//
13 #ifndef BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_
14 #define BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_
17 #include <boost/system/error_code.hpp>
18 #include <boost/filesystem/config.hpp>
19 #include <boost/filesystem/exception.hpp>
21 #if defined(BOOST_WINDOWS_API)
22 #include <boost/winapi/basic_types.hpp>
23 #include <boost/winapi/get_last_error.hpp>
24 #include <boost/winapi/error_codes.hpp>
28 namespace filesystem {
30 #if defined(BOOST_POSIX_API)
34 // POSIX uses a 0 return to indicate success
35 #define BOOST_ERRNO errno
37 #define BOOST_ERROR_NOT_SUPPORTED ENOSYS
38 #define BOOST_ERROR_ALREADY_EXISTS EEXIST
42 typedef boost::winapi::DWORD_ err_t;
44 // Windows uses a non-0 return to indicate success
45 #define BOOST_ERRNO boost::winapi::GetLastError()
47 #define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
48 #define BOOST_ERROR_NOT_SUPPORTED boost::winapi::ERROR_NOT_SUPPORTED_
52 // error handling helpers ----------------------------------------------------------//
54 // Implemented in exception.cpp
55 void emit_error(err_t error_num, system::error_code* ec, const char* message);
56 void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message);
57 void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message);
59 inline bool error(err_t error_num, system::error_code* ec, const char* message)
61 if (BOOST_LIKELY(!error_num))
69 filesystem::emit_error(error_num, ec, message);
74 inline bool error(err_t error_num, const path& p, system::error_code* ec, const char* message)
76 if (BOOST_LIKELY(!error_num))
84 filesystem::emit_error(error_num, p, ec, message);
89 inline bool error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
91 if (BOOST_LIKELY(!error_num))
99 filesystem::emit_error(error_num, p1, p2, ec, message);
104 } // namespace filesystem
107 #endif // BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_