diff options
Diffstat (limited to 'src/os_win/os_errno.c')
-rw-r--r-- | src/os_win/os_errno.c | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/src/os_win/os_errno.c b/src/os_win/os_errno.c index 00ee638fbe3..81bcdf9089e 100644 --- a/src/os_win/os_errno.c +++ b/src/os_win/os_errno.c @@ -58,47 +58,27 @@ __wt_errno(void) /* * __wt_strerror -- - * Windows implementation of wiredtiger_strerror. + * Windows implementation of WT_SESSION.strerror and wiredtiger_strerror. */ const char * -__wt_strerror(int error) +__wt_strerror(WT_SESSION_IMPL *session, int error, char *errbuf, size_t errlen) { + DWORD lasterror; const char *p; + char buf[512]; /* - * POSIX errors are non-negative integers; check for 0 explicitly - * in-case the underlying strerror doesn't handle 0, some don't. + * Check for a WiredTiger or POSIX constant string, no buffer needed. */ - if (error == 0) - return ("Successful return: 0"); - if (error > 0 && (p = strerror(error)) != NULL) + if ((p = __wt_wiredtiger_error(error)) != NULL) return (p); - return (NULL); -} - -/* - * __wt_strerror_r -- - * Windows implementation of wiredtiger_strerror_r. - */ -int -__wt_strerror_r(int error, char *buf, size_t buflen) -{ - DWORD lasterror; - const char *p; - - /* Require at least 2 bytes, printable character and trailing nul. */ - if (buflen < 2) - return (ENOMEM); /* - * Check for POSIX errors, Windows errors, then fallback to something - * generic. Copy the string into the user's buffer, return success if - * anything printed. + * When called from wiredtiger_strerror, write a passed-in buffer. + * When called from WT_SESSION.strerror, write the session's buffer. + * + * Check for Windows errors. */ - p = __wt_strerror(error); - if (p != NULL && snprintf(buf, buflen, "%s", p) > 0) - return (0); - if (error < 0) { error = __wt_map_error_to_windows_error(error); @@ -109,16 +89,25 @@ __wt_strerror_r(int error, char *buf, size_t buflen) error, 0, /* let system choose the correct LANGID */ buf, - buflen, + sizeof(buf), NULL); - if (lasterror != 0) - return (0); - - /* Fall through to the fallback error code */ + if (lasterror != 0 && session == NULL && + snprintf(errbuf, errlen, "%s", buf) > 0) + return (errbuf); + if (lasterror != 0 && session != NULL && + __wt_buf_set(session, &session->err, buf, strlen(buf)) == 0) + return (session->err.data); } - /* Fallback to a generic message, then guess it's a memory problem. */ - return ( - snprintf(buf, buflen, "error return: %d", error) > 0 ? 0 : ENOMEM); + /* Fallback to a generic message. */ + if (session == NULL && + snprintf(errbuf, errlen, "error return: %d", error) > 0) + return (errbuf); + if (session != NULL && __wt_buf_fmt( + session, &session->err, "error return: %d", error) == 0) + return (session->err.data); + + /* Defeated. */ + return ("Unable to return error string"); } |