1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/misc/prerror.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "primpl.h" 1.10 + 1.11 +#include <string.h> 1.12 +#include <stdlib.h> 1.13 + 1.14 +PR_IMPLEMENT(PRErrorCode) PR_GetError(void) 1.15 +{ 1.16 + PRThread *thread = PR_GetCurrentThread(); 1.17 + return thread->errorCode; 1.18 +} 1.19 + 1.20 +PR_IMPLEMENT(PRInt32) PR_GetOSError(void) 1.21 +{ 1.22 + PRThread *thread = PR_GetCurrentThread(); 1.23 + return thread->osErrorCode; 1.24 +} 1.25 + 1.26 +PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr) 1.27 +{ 1.28 + PRThread *thread = PR_GetCurrentThread(); 1.29 + thread->errorCode = code; 1.30 + thread->osErrorCode = osErr; 1.31 + thread->errorStringLength = 0; 1.32 +} 1.33 + 1.34 +PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text) 1.35 +{ 1.36 + PRThread *thread = PR_GetCurrentThread(); 1.37 + 1.38 + if (0 == textLength) 1.39 + { 1.40 + if (NULL != thread->errorString) 1.41 + PR_DELETE(thread->errorString); 1.42 + thread->errorStringSize = 0; 1.43 + } 1.44 + else 1.45 + { 1.46 + PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */ 1.47 + if (thread->errorStringSize < textLength+1) /* do we have room? */ 1.48 + { 1.49 + if (NULL != thread->errorString) 1.50 + PR_DELETE(thread->errorString); 1.51 + thread->errorString = (char*)PR_MALLOC(size); 1.52 + if ( NULL == thread->errorString ) { 1.53 + thread->errorStringSize = 0; 1.54 + thread->errorStringLength = 0; 1.55 + return; 1.56 + } 1.57 + thread->errorStringSize = size; 1.58 + } 1.59 + memcpy(thread->errorString, text, textLength+1 ); 1.60 + } 1.61 + thread->errorStringLength = textLength; 1.62 +} 1.63 + 1.64 +PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void) 1.65 +{ 1.66 + PRThread *thread = PR_GetCurrentThread(); 1.67 + return thread->errorStringLength; 1.68 +} /* PR_GetErrorTextLength */ 1.69 + 1.70 +PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text) 1.71 +{ 1.72 + PRThread *thread = PR_GetCurrentThread(); 1.73 + if (0 != thread->errorStringLength) 1.74 + memcpy(text, thread->errorString, thread->errorStringLength+1); 1.75 + return thread->errorStringLength; 1.76 +} /* PR_GetErrorText */ 1.77 + 1.78 +