From e7855e43bbc4dd0a5e8fcbfd4888181001dcd1ec Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 17 Jun 2011 14:18:54 -0700 Subject: [PATCH] Make sure we use the correct strerror() in case someone is using threads. --- libmemcached/error.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 49375097..5cfb4be2 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -99,18 +99,35 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t error->rc= rc; error->local_errno= local_errno; + const char *errmsg_ptr; + char errmsg[MAX_ERROR_LENGTH]; + errmsg[0]= 0; + errmsg_ptr= errmsg; + + if (local_errno) + { +#ifdef STRERROR_R_CHAR_P + errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg)); +#else + strerror_r(local_errno, errmsg, sizeof(errmsg)); + errmsg_ptr= errmsg; +#endif + } + + if (str and str->size and local_errno) { error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s(%s), %.*s -> %s", memcached_strerror(&memc, rc), - strerror(local_errno), + errmsg_ptr, memcached_string_printf(*str), at); } else if (local_errno) { error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s(%s) -> %s", memcached_strerror(&memc, rc), - strerror(local_errno), at); + errmsg_ptr, + at); } else if (str and str->size) { -- 2.30.2