andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #include "primpl.h" andre@0: andre@0: #include andre@0: #include andre@0: andre@0: PR_IMPLEMENT(PRErrorCode) PR_GetError(void) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: return thread->errorCode; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_GetOSError(void) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: return thread->osErrorCode; andre@0: } andre@0: andre@0: PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: thread->errorCode = code; andre@0: thread->osErrorCode = osErr; andre@0: thread->errorStringLength = 0; andre@0: } andre@0: andre@0: PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: andre@0: if (0 == textLength) andre@0: { andre@0: if (NULL != thread->errorString) andre@0: PR_DELETE(thread->errorString); andre@0: thread->errorStringSize = 0; andre@0: } andre@0: else andre@0: { andre@0: PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */ andre@0: if (thread->errorStringSize < textLength+1) /* do we have room? */ andre@0: { andre@0: if (NULL != thread->errorString) andre@0: PR_DELETE(thread->errorString); andre@0: thread->errorString = (char*)PR_MALLOC(size); andre@0: if ( NULL == thread->errorString ) { andre@0: thread->errorStringSize = 0; andre@0: thread->errorStringLength = 0; andre@0: return; andre@0: } andre@0: thread->errorStringSize = size; andre@0: } andre@0: memcpy(thread->errorString, text, textLength+1 ); andre@0: } andre@0: thread->errorStringLength = textLength; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: return thread->errorStringLength; andre@0: } /* PR_GetErrorTextLength */ andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text) andre@0: { andre@0: PRThread *thread = PR_GetCurrentThread(); andre@0: if (0 != thread->errorStringLength) andre@0: memcpy(text, thread->errorString, thread->errorStringLength+1); andre@0: return thread->errorStringLength; andre@0: } /* PR_GetErrorText */ andre@0: andre@0: