nsprpub/pr/src/misc/prerror.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "primpl.h"
michael@0 7
michael@0 8 #include <string.h>
michael@0 9 #include <stdlib.h>
michael@0 10
michael@0 11 PR_IMPLEMENT(PRErrorCode) PR_GetError(void)
michael@0 12 {
michael@0 13 PRThread *thread = PR_GetCurrentThread();
michael@0 14 return thread->errorCode;
michael@0 15 }
michael@0 16
michael@0 17 PR_IMPLEMENT(PRInt32) PR_GetOSError(void)
michael@0 18 {
michael@0 19 PRThread *thread = PR_GetCurrentThread();
michael@0 20 return thread->osErrorCode;
michael@0 21 }
michael@0 22
michael@0 23 PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr)
michael@0 24 {
michael@0 25 PRThread *thread = PR_GetCurrentThread();
michael@0 26 thread->errorCode = code;
michael@0 27 thread->osErrorCode = osErr;
michael@0 28 thread->errorStringLength = 0;
michael@0 29 }
michael@0 30
michael@0 31 PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text)
michael@0 32 {
michael@0 33 PRThread *thread = PR_GetCurrentThread();
michael@0 34
michael@0 35 if (0 == textLength)
michael@0 36 {
michael@0 37 if (NULL != thread->errorString)
michael@0 38 PR_DELETE(thread->errorString);
michael@0 39 thread->errorStringSize = 0;
michael@0 40 }
michael@0 41 else
michael@0 42 {
michael@0 43 PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */
michael@0 44 if (thread->errorStringSize < textLength+1) /* do we have room? */
michael@0 45 {
michael@0 46 if (NULL != thread->errorString)
michael@0 47 PR_DELETE(thread->errorString);
michael@0 48 thread->errorString = (char*)PR_MALLOC(size);
michael@0 49 if ( NULL == thread->errorString ) {
michael@0 50 thread->errorStringSize = 0;
michael@0 51 thread->errorStringLength = 0;
michael@0 52 return;
michael@0 53 }
michael@0 54 thread->errorStringSize = size;
michael@0 55 }
michael@0 56 memcpy(thread->errorString, text, textLength+1 );
michael@0 57 }
michael@0 58 thread->errorStringLength = textLength;
michael@0 59 }
michael@0 60
michael@0 61 PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void)
michael@0 62 {
michael@0 63 PRThread *thread = PR_GetCurrentThread();
michael@0 64 return thread->errorStringLength;
michael@0 65 } /* PR_GetErrorTextLength */
michael@0 66
michael@0 67 PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text)
michael@0 68 {
michael@0 69 PRThread *thread = PR_GetCurrentThread();
michael@0 70 if (0 != thread->errorStringLength)
michael@0 71 memcpy(text, thread->errorString, thread->errorStringLength+1);
michael@0 72 return thread->errorStringLength;
michael@0 73 } /* PR_GetErrorText */
michael@0 74
michael@0 75

mercurial