Beispiel #1
0
static int& GetFailCounter(CId2Reader::TConn /*conn*/)
{
#ifdef NCBI_THREADS
    static CStaticTls<int> fail_counter;
    int* ptr = fail_counter.GetValue();
    if ( !ptr ) {
        ptr = new int(0);
        fail_counter.SetValue(ptr);
    }
    return *ptr;
#else
    static int fail_counter = 0;
    return fail_counter;
#endif
}
Beispiel #2
0
const char* CLastErrorAdapt::GetErrCodeString(int errnum)
{
    TXChar* xptr = NULL;
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                  FORMAT_MESSAGE_FROM_SYSTEM     |
                  FORMAT_MESSAGE_MAX_WIDTH_MASK  |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
                  "%0", errnum,
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                  (TXChar*)&xptr, 0, NULL);
#if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
    CStringUTF8 tmp( CUtf8::AsUTF8(xptr));
    char* ptr = (char*)LocalAlloc( LPTR, tmp.size() + 1);
    strcpy(ptr, tmp.c_str());
    LocalFree(xptr);
#else
    char* ptr = xptr;
#endif
    // Remove trailing dots and spaces
    size_t pos = strlen(ptr);
    if ( pos ) {
        while (--pos  &&  (ptr[pos] == '.' || ptr[pos] == ' ')) {
            ptr[pos] = '\0';
        }
    }
    // Save pointer
    s_TlsErrorMessage.SetValue(ptr, s_TlsErrorMessageCleanup);
    return ptr;
}
Beispiel #3
0
BEGIN_NCBI_SCOPE


/////////////////////////////////////////////////////////////////////////////
impl::CDBExceptionStorage& GetCTLExceptionStorage(void)
{
    static CStaticTls<impl::CDBExceptionStorage> instance;

    impl::CDBExceptionStorage* result = instance.GetValue();
    if (!result) {
		auto_ptr<impl::CDBExceptionStorage> tmp_value(new impl::CDBExceptionStorage);
        instance.SetValue(tmp_value.get(), s_DelExceptionStorage);
		result = tmp_value.release();
    }

    return *result;
}
Beispiel #4
0
extern const char*  Ncbi_strerror(int errnum)
{
#if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
        (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
    string tmp;
#  if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__
    TXChar xbuf[256];
    NcbiSys_strerror_s(xbuf,sizeof(xbuf)/sizeof(TXChar),errnum);
    tmp = _T_STDSTRING(xbuf);
#  else
    tmp = _T_STDSTRING( NcbiSys_strerror(errnum) );
#  endif
    char* ptr = new char[ tmp.size() + 1];
    strcpy(ptr, tmp.c_str());
    s_TlsStrerrorMessage.SetValue(ptr, s_TlsStrerrorMessageCleanup);
    return ptr;
#else
    return NcbiSys_strerror(errnum);
#endif
}