diff options
author | Keith Bostic <keith@wiredtiger.com> | 2014-12-24 11:15:21 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2014-12-24 11:15:21 -0500 |
commit | baa157b40673c027acf1ddcb99fedb848a660885 (patch) | |
tree | a69a301ed798ffd3bfd7b533cb8a8cfbdfcb2674 /src/os_posix | |
parent | bc7ed41d8e3d9c268c0d57600a36d32c98bdf8b0 (diff) | |
download | mongo-baa157b40673c027acf1ddcb99fedb848a660885.tar.gz |
Add wiredtiger_strerror_r, a thread-safe version of wiredtiger_strerror,
which allows us to support Windows' errors where we have to allocate a
buffer to get the error string.
Diffstat (limited to 'src/os_posix')
-rw-r--r-- | src/os_posix/os_errno.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/os_posix/os_errno.c b/src/os_posix/os_errno.c index 9290f7d651f..b0cb288ea74 100644 --- a/src/os_posix/os_errno.c +++ b/src/os_posix/os_errno.c @@ -20,3 +20,30 @@ __wt_errno(void) */ return (errno == 0 ? WT_ERROR : errno); } + +/* + * __wt_strerror_r -- + * POSIX implementation of strerror_r. + */ +int +__wt_strerror_r(int error, char *buf, size_t buflen) +{ + char *p; + + /* Require at least 2 bytes, printable character and trailing nul. */ + if (buflen < 2) + return (ENOMEM); + + /* + * POSIX errors are non-negative integers, copy the string into the + * user's buffer. Return success if anything printed (we checked if + * the buffer had space for at least one character). + */ + if (error > 0 && + (p = strerror(error)) != NULL && snprintf(buf, buflen, "%s", p) > 0) + return (0); + + /* Fallback to a generic message, then guess it's a memory problem. */ + return ( + snprintf(buf, buflen, "error return: %d", error) > 0 ? 0 : ENOMEM); +} |