summaryrefslogtreecommitdiff
path: root/src/os_win/os_errno.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_win/os_errno.c')
-rw-r--r--src/os_win/os_errno.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/os_win/os_errno.c b/src/os_win/os_errno.c
index 590fcdc9d44..f3fffd5ef42 100644
--- a/src/os_win/os_errno.c
+++ b/src/os_win/os_errno.c
@@ -46,13 +46,13 @@ __wt_map_windows_error_to_error(DWORD winerr)
* of failures.
*/
int
-__wt_map_error_rdonly(int winerr)
+__wt_map_error_rdonly(int error)
{
- if (winerr == ERROR_FILE_NOT_FOUND)
+ if (error == ERROR_FILE_NOT_FOUND)
return (WT_NOTFOUND);
- else if (winerr == ERROR_ACCESS_DENIED)
+ else if (error == ERROR_ACCESS_DENIED)
return (WT_PERM_DENIED);
- return (winerr);
+ return (error);
}
/*
@@ -63,14 +63,33 @@ int
__wt_errno(void)
{
/*
+ * Check for 0:
+ * It's easy to introduce a problem by calling the wrong error function,
+ * for example, this function when the MSVC function set the C runtime
+ * error value. Handle gracefully and always return an error.
+ */
+ return (errno == 0 ? WT_ERROR : errno);
+}
+
+/*
+ * __wt_getlasterror --
+ * Return GetLastError, or WT_ERROR if error not set.
+ */
+int
+__wt_getlasterror(void)
+{
+ /*
* Called when we know an error occurred, and we want the system
- * error code, but there's some chance it's not set.
+ * error code.
*/
DWORD err = GetLastError();
- /* GetLastError should only be called if we hit an actual error */
- WT_ASSERT(NULL, err != ERROR_SUCCESS);
-
+ /*
+ * Check for ERROR_SUCCESS:
+ * It's easy to introduce a problem by calling the wrong error function,
+ * for example, this function when the MSVC function set the C runtime
+ * error value. Handle gracefully and always return an error.
+ */
return (err == ERROR_SUCCESS ?
WT_ERROR : __wt_map_windows_error_to_error(err));
}