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 }
void CPIDGuard::Release(void) { if ( !m_Path.empty() ) { // MT-Safe protect CFastMutexGuard LOCK(s_PidGuardMutex); // Read info TPid pid = 0; unsigned int ref = 0; CNcbiIfstream in(m_Path.c_str()); if ( in.good() ) { in >> pid >> ref; in.close(); if ( m_NewPID != pid ) { // We do not own this file more return; } if ( ref ) { ref--; } // Check reference counter if ( ref ) { // Write updated reference counter into the file CNcbiOfstream out(m_Path.c_str(), IOS_BASE::out | IOS_BASE::trunc); if ( out.good() ) { out << pid << endl << ref << endl; } if ( !out.good() ) { NCBI_THROW(CPIDGuardException, eWrite, "Unable to write into PID file " + m_Path +": " + _T_CSTRING(NcbiSys_strerror(errno))); } } else { // Remove the file CDirEntry(m_Path).Remove(); } }