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