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/. */
11 PR_IMPLEMENT(PRErrorCode
) PR_GetError(void) {
12 PRThread
* thread
= PR_GetCurrentThread();
13 return thread
->errorCode
;
16 PR_IMPLEMENT(PRInt32
) PR_GetOSError(void) {
17 PRThread
* thread
= PR_GetCurrentThread();
18 return thread
->osErrorCode
;
21 PR_IMPLEMENT(void) PR_SetError(PRErrorCode code
, PRInt32 osErr
) {
22 PRThread
* thread
= PR_GetCurrentThread();
23 thread
->errorCode
= code
;
24 thread
->osErrorCode
= osErr
;
25 thread
->errorStringLength
= 0;
28 PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength
, const char* text
) {
29 PRThread
* thread
= PR_GetCurrentThread();
31 if (0 == textLength
) {
32 if (NULL
!= thread
->errorString
) {
33 PR_DELETE(thread
->errorString
);
35 thread
->errorStringSize
= 0;
38 textLength
+ 31; /* actual length to allocate. Plus a little extra */
39 if (thread
->errorStringSize
< textLength
+ 1) /* do we have room? */
41 if (NULL
!= thread
->errorString
) {
42 PR_DELETE(thread
->errorString
);
44 thread
->errorString
= (char*)PR_MALLOC(size
);
45 if (NULL
== thread
->errorString
) {
46 thread
->errorStringSize
= 0;
47 thread
->errorStringLength
= 0;
50 thread
->errorStringSize
= size
;
52 memcpy(thread
->errorString
, text
, textLength
+ 1);
54 thread
->errorStringLength
= textLength
;
57 PR_IMPLEMENT(PRInt32
) PR_GetErrorTextLength(void) {
58 PRThread
* thread
= PR_GetCurrentThread();
59 return thread
->errorStringLength
;
60 } /* PR_GetErrorTextLength */
62 PR_IMPLEMENT(PRInt32
) PR_GetErrorText(char* text
) {
63 PRThread
* thread
= PR_GetCurrentThread();
64 if (0 != thread
->errorStringLength
) {
65 memcpy(text
, thread
->errorString
, thread
->errorStringLength
+ 1);
67 return thread
->errorStringLength
;
68 } /* PR_GetErrorText */