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