Asylo
posix_errors.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Asylo authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ASYLO_UTIL_POSIX_ERRORS_H_
18 #define ASYLO_UTIL_POSIX_ERRORS_H_
19 
20 #include "absl/strings/string_view.h"
21 #include "asylo/util/status.h"
22 
23 namespace asylo {
24 
25 /// Returns a Status representing a POSIX error. If `errnum` is zero,
26 /// `PosixError()` returns an OK status. Otherwise, the returned error message
27 /// includes the POSIX error explanation string.
28 ///
29 /// Callers should not rely on how `PosixError()` embeds error information in
30 /// the returned `Status`. Instead, callers can use `GetErrno()` to inspect a
31 /// `Status` for POSIX error information.
32 ///
33 /// However, callers may rely on stability in the mapping between POSIX error
34 /// numbers and `absl::StatusCode`s. Callers can also use this function to
35 /// create `Status`es that are understandable by other code that uses the POSIX
36 /// error space.
37 ///
38 /// \param errnum A POSIX error number. See errno(3).
39 /// \param message An optional message to prepend to the POSIX error explanation
40 /// string.
41 /// \return An error representing `errnum`, or an OK status if `errnum` is zero.
43 
44 /// Returns a Status representing the last POSIX error in this thread.
45 ///
46 /// Equivalent to calling `PosixError(errno, message)`.
47 ///
48 /// \param message An optional message to prepend to the POSIX error explanation
49 /// string.
50 /// \return An error the last POSIX error in this thread.
52 
53 /// Returns the POSIX error number that a `Status` represents, or zero if the
54 /// `Status` does not represent a POSIX error.
55 ///
56 /// This function understands `Status`es that were created in the POSIX error
57 /// space.
58 ///
59 /// \param status A status object.
60 /// \return The POSIX error number represented by `status`, or zero if `status`
61 /// does not represent a POSIX error.
62 int GetErrno(const Status &status);
63 
64 } // namespace asylo
65 
66 #endif // ASYLO_UTIL_POSIX_ERRORS_H_
int GetErrno(const Status &status)
Returns the POSIX error number that a Status represents, or zero if the Status does not represent a P...
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
Status LastPosixError(absl::string_view message="")
Returns a Status representing the last POSIX error in this thread.
Status PosixError(int errnum, absl::string_view message="")
Returns a Status representing a POSIX error.