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.

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

mercurial