aboutsummaryrefslogtreecommitdiffstats
path: root/lang/cpp/src
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2024-07-04 12:36:04 +0000
committerIngo Klöcker <[email protected]>2024-07-05 08:05:51 +0000
commit2656d3ee5b1a905d9fe4dd5c8b2d9737e775df31 (patch)
tree9f200f6192910356fbfb77bdea25d324df9c93a5 /lang/cpp/src
parentqt: Always include C++ binding headers with gpgme++/ prefix (diff)
downloadgpgme-2656d3ee5b1a905d9fe4dd5c8b2d9737e775df31.tar.gz
gpgme-2656d3ee5b1a905d9fe4dd5c8b2d9737e775df31.zip
cpp: Add safer member function returning text describing an error
* lang/cpp/src/error.h, lang/cpp/src/context.cpp (class Error): New member function asStdString. -- Unlike asString the new function doesn't cache the value returned by gpgme_strerror_r. This ensures that on Windows the UTF-8 encoded text is returned for the main thread even if the function was called before for another thread. For other threads asStdString will still return the natively encoded error description until UTF-8 encoded error descriptions can be enabled for all threads (T7185). GnuPG-bug-id: 7188
Diffstat (limited to 'lang/cpp/src')
-rw-r--r--lang/cpp/src/context.cpp7
-rw-r--r--lang/cpp/src/error.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp
index 99e354df..4882c80c 100644
--- a/lang/cpp/src/context.cpp
+++ b/lang/cpp/src/context.cpp
@@ -130,6 +130,13 @@ const char *Error::asString() const
return mMessage.c_str();
}
+std::string Error::asStdString() const
+{
+ std::string message;
+ format_error(static_cast<gpgme_error_t>(mErr), message);
+ return message;
+}
+
int Error::code() const
{
return gpgme_err_code(mErr);
diff --git a/lang/cpp/src/error.h b/lang/cpp/src/error.h
index d1367046..bc970e36 100644
--- a/lang/cpp/src/error.h
+++ b/lang/cpp/src/error.h
@@ -48,6 +48,7 @@ public:
const char *source() const;
const char *asString() const;
+ std::string asStdString() const;
int code() const;
int sourceID() const;