X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzexcept.cpp;h=6a684f08009fabd70bbd6d1bfd7bea06d786e055;hb=ab42ade0e6fe70998e8fe70338b2d78008d388f7;hp=462767bd4a7c248217a09c117620917dad566a76;hpb=01126607d1b475f43b29548dbd98f199f8e9f57f;p=yazpp-moved-to-github.git diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index 462767b..6a684f0 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -1,10 +1,11 @@ -// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.8 2003-07-02 10:25:13 adam Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.10 2003-09-22 12:30:01 mike Exp $ // Z39.50 Exception classes #include #include #include // for strerror(), strlen(), strcpy() +#include #include "zoom.h" @@ -22,7 +23,7 @@ namespace ZOOM { } std::string exception::errmsg() const { - static char buf[40]; + char buf[40]; sprintf(buf, "error #%d", code); return buf; } @@ -34,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() {