Improve the process for GNU tools
[minix3.git] / external / bsd / kyua-cli / dist / utils / fs / exceptions.cpp
blobaabd809ebee11532b033ab57d7394838df108f16
1 // Copyright 2010 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "utils/fs/exceptions.hpp"
31 #include <cstring>
33 #include "utils/format/macros.hpp"
35 namespace fs = utils::fs;
38 /// Constructs a new error with a plain-text message.
39 ///
40 /// \param message The plain-text error message.
41 fs::error::error(const std::string& message) :
42 std::runtime_error(message)
47 /// Destructor for the error.
48 fs::error::~error(void) throw()
53 /// Constructs a new invalid_path_error.
54 ///
55 /// \param textual_path Textual representation of the invalid path.
56 /// \param reason Description of the error in the path.
57 fs::invalid_path_error::invalid_path_error(const std::string& textual_path,
58 const std::string& reason) :
59 error(F("Invalid path '%s': %s") % textual_path % reason),
60 _textual_path(textual_path)
65 /// Destructor for the error.
66 fs::invalid_path_error::~invalid_path_error(void) throw()
71 /// Returns the invalid path related to the exception.
72 ///
73 /// \return The textual representation of the invalid path.
74 const std::string&
75 fs::invalid_path_error::invalid_path(void) const
77 return _textual_path;
81 /// Constructs a new join_error.
82 ///
83 /// \param textual_path1_ Textual representation of the first path.
84 /// \param textual_path2_ Textual representation of the second path.
85 /// \param reason Description of the error in the join operation.
86 fs::join_error::join_error(const std::string& textual_path1_,
87 const std::string& textual_path2_,
88 const std::string& reason) :
89 error(F("Cannot join paths '%s' and '%s': %s") % textual_path1_ %
90 textual_path2_ % reason),
91 _textual_path1(textual_path1_),
92 _textual_path2(textual_path2_)
97 /// Destructor for the error.
98 fs::join_error::~join_error(void) throw()
103 /// Gets the first path that caused the error in a join operation.
105 /// \return The textual representation of the path.
106 const std::string&
107 fs::join_error::textual_path1(void) const
109 return _textual_path1;
113 /// Gets the second path that caused the error in a join operation.
115 /// \return The textual representation of the path.
116 const std::string&
117 fs::join_error::textual_path2(void) const
119 return _textual_path2;
123 /// Constructs a new error based on an errno code.
125 /// \param message_ The message describing what caused the error.
126 /// \param errno_ The error code.
127 fs::system_error::system_error(const std::string& message_, const int errno_) :
128 error(F("%s: %s") % message_ % std::strerror(errno_)),
129 _original_errno(errno_)
134 /// Destructor for the error.
135 fs::system_error::~system_error(void) throw()
141 /// Gets the original errno code.
143 fs::system_error::original_errno(void) const throw()
145 return _original_errno;