From 57b7db2259edf3522ae73f3198eab36c888d5c6f Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 22 Sep 2003 12:30:01 +0000 Subject: [PATCH] Thread-safety and removal of extraneous logging, thanks to Phil Dennis --- zoom/zexcept.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index 3a11382..6a684f0 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.9 2003-07-07 09:23:16 adam Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.10 2003-09-22 12:30:01 mike Exp $ // Z39.50 Exception classes @@ -23,7 +23,7 @@ namespace ZOOM { } std::string exception::errmsg() const { - static char buf[40]; + char buf[40]; sprintf(buf, "error #%d", code); return buf; } @@ -35,15 +35,32 @@ namespace ZOOM { } std::string systemException::errmsg() const { - return strerror(code); + // For thread safety on linux (and most unix systems), we need + // to use the reentrant version of the error translation + // function. Microsoft's strerror() is thread safe, since it + // returns a pointer to thread local storage. Unfortunately + // there several different reentrant versions. Here, we check + // for glibc, since we are using gcc. It appears at least the + // current version of gcc has strerror_r() available by + // default. + #ifdef __GLIBC__ + char buf[1024]; + // PJD: result not necessarily equal to buf + const char* result = strerror_r(code, buf, sizeof(buf)); + if (result != 0) + return result; + return exception::errmsg(); + #else + return strerror(code); + #endif } bib1Exception::bib1Exception(int errcode, const std::string &addinfo) : exception(errcode), info(addinfo) { - std::cerr << "WARNING: made bib1Exception(" << errcode << "=" << - ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; + // std::cerr << "WARNING: made bib1Exception(" << errcode << "=" << + // ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; } bib1Exception::~bib1Exception() { -- 1.7.10.4