summaryrefslogtreecommitdiff
path: root/src/mongo/util/errno_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/errno_util.h')
-rw-r--r--src/mongo/util/errno_util.h56
1 files changed, 4 insertions, 52 deletions
diff --git a/src/mongo/util/errno_util.h b/src/mongo/util/errno_util.h
index bbc12c3b40f..0464c38a409 100644
--- a/src/mongo/util/errno_util.h
+++ b/src/mongo/util/errno_util.h
@@ -29,7 +29,6 @@
#pragma once
-#include <cstdlib>
#include <system_error>
#include <utility>
@@ -37,36 +36,6 @@
namespace mongo {
-#ifdef _WIN32
-namespace errno_util_win32_detail {
-int gle();
-int wsaGle();
-} // namespace errno_util_win32_detail
-#endif
-
-/**
- * Returns category to use for POSIX errno error codes.
- * On POSIX, `errno` codes are the `std::system_category`.
- * On Windows, the `errno` codes are the `std::generic_category`.
- */
-inline const std::error_category& posixCategory() {
-#ifdef _WIN32
- return std::generic_category();
-#else
- return std::system_category();
-#endif
-}
-
-/** Wraps POSIX `errno` value in an appropriate `std::error_code`. */
-inline std::error_code posixError(int e) {
- return std::error_code(e, posixCategory());
-}
-
-/** Wraps `e` in a `std::error_code` with `std::system_category`. */
-inline std::error_code systemError(int e) {
- return std::error_code(e, std::system_category());
-}
-
/**
* Returns `{errno, std::generic_category()}`.
* Windows has both Windows errors and POSIX errors. That is, there's a
@@ -79,39 +48,22 @@ inline std::error_code systemError(int e) {
* On POSIX systems, `std::system_category` is potentially a superset of
* `std::generic_category`, so `lastSystemError` should be preferred for
* handling system errors.
- *
- * Guaranteed to not modify `errno`.
*/
inline std::error_code lastPosixError() {
- return posixError(errno);
+ return std::error_code(errno, std::generic_category());
}
/**
* On POSIX, returns `{errno, std::system_category()}`.
* On Windows, returns `{GetLastError(), std::system_category()}`, but see `lastPosixError`.
- *
- * Guaranteed to not modify the system error code variable.
*/
inline std::error_code lastSystemError() {
#ifdef _WIN32
- return systemError(errno_util_win32_detail::gle());
-#else
- return systemError(errno);
-#endif
-}
-
-/**
- * Portable wrapper for socket API calls. On POSIX platforms this is just
- * `lastSystemError`. On Windows, Winsock API callers must query last error with
- * `WSAGetLastError` instead of `GetLastError`. The Winsock errors can use the
- * same error code category as other Windows API calls.
- */
-inline std::error_code lastSocketError() {
-#ifdef _WIN32
- return systemError(errno_util_win32_detail::wsaGle());
+ int e = GetLastError();
#else
- return lastSystemError();
+ int e = errno;
#endif
+ return std::error_code(e, std::system_category());
}
/**