Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / filesystem / src / error_handling.hpp
1 //  error_handling.hpp  --------------------------------------------------------------------//
2
3 //  Copyright 2002-2009, 2014 Beman Dawes
4 //  Copyright 2019 Andrey Semashev
5
6 //  Distributed under the Boost Software License, Version 1.0.
7 //  See http://www.boost.org/LICENSE_1_0.txt
8
9 //  See library home page at http://www.boost.org/libs/filesystem
10
11 //--------------------------------------------------------------------------------------//
12
13 #ifndef BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_
14 #define BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_
15
16 #include <cerrno>
17 #include <boost/system/error_code.hpp>
18 #include <boost/filesystem/config.hpp>
19 #include <boost/filesystem/exception.hpp>
20
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>
25 #endif
26
27 namespace boost {
28 namespace filesystem {
29
30 #if defined(BOOST_POSIX_API)
31
32 typedef int err_t;
33
34 //  POSIX uses a 0 return to indicate success
35 #define BOOST_ERRNO    errno
36
37 #define BOOST_ERROR_NOT_SUPPORTED ENOSYS
38 #define BOOST_ERROR_ALREADY_EXISTS EEXIST
39
40 #else
41
42 typedef boost::winapi::DWORD_ err_t;
43
44 //  Windows uses a non-0 return to indicate success
45 #define BOOST_ERRNO    boost::winapi::GetLastError()
46
47 #define BOOST_ERROR_ALREADY_EXISTS boost::winapi::ERROR_ALREADY_EXISTS_
48 #define BOOST_ERROR_NOT_SUPPORTED boost::winapi::ERROR_NOT_SUPPORTED_
49
50 #endif
51
52 //  error handling helpers  ----------------------------------------------------------//
53
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);
58
59 inline bool error(err_t error_num, system::error_code* ec, const char* message)
60 {
61   if (BOOST_LIKELY(!error_num))
62   {
63     if (ec)
64       ec->clear();
65     return false;
66   }
67   else
68   { //  error
69     filesystem::emit_error(error_num, ec, message);
70     return true;
71   }
72 }
73
74 inline bool error(err_t error_num, const path& p, system::error_code* ec, const char* message)
75 {
76   if (BOOST_LIKELY(!error_num))
77   {
78     if (ec)
79       ec->clear();
80     return false;
81   }
82   else
83   { //  error
84     filesystem::emit_error(error_num, p, ec, message);
85     return true;
86   }
87 }
88
89 inline bool error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
90 {
91   if (BOOST_LIKELY(!error_num))
92   {
93     if (ec)
94       ec->clear();
95     return false;
96   }
97   else
98   { //  error
99     filesystem::emit_error(error_num, p1, p2, ec, message);
100     return true;
101   }
102 }
103
104 } // namespace filesystem
105 } // namespace boost
106
107 #endif // BOOST_FILESYSTEM3_SRC_ERROR_HANDLING_HPP_