/src/nspr/pr/src/misc/prerror.c
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "primpl.h" |
7 | | |
8 | | #include <string.h> |
9 | | #include <stdlib.h> |
10 | | |
11 | 0 | PR_IMPLEMENT(PRErrorCode) PR_GetError(void) { |
12 | 0 | PRThread* thread = PR_GetCurrentThread(); |
13 | 0 | return thread->errorCode; |
14 | 0 | } |
15 | | |
16 | 0 | PR_IMPLEMENT(PRInt32) PR_GetOSError(void) { |
17 | 0 | PRThread* thread = PR_GetCurrentThread(); |
18 | 0 | return thread->osErrorCode; |
19 | 0 | } |
20 | | |
21 | 0 | PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr) { |
22 | 0 | PRThread* thread = PR_GetCurrentThread(); |
23 | 0 | thread->errorCode = code; |
24 | 0 | thread->osErrorCode = osErr; |
25 | 0 | thread->errorStringLength = 0; |
26 | 0 | } |
27 | | |
28 | 0 | PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char* text) { |
29 | 0 | PRThread* thread = PR_GetCurrentThread(); |
30 | |
|
31 | 0 | if (0 == textLength) { |
32 | 0 | if (NULL != thread->errorString) { |
33 | 0 | PR_DELETE(thread->errorString); |
34 | 0 | } |
35 | 0 | thread->errorStringSize = 0; |
36 | 0 | } else { |
37 | 0 | PRIntn size = |
38 | 0 | textLength + 31; /* actual length to allocate. Plus a little extra */ |
39 | 0 | if (thread->errorStringSize < textLength + 1) /* do we have room? */ |
40 | 0 | { |
41 | 0 | if (NULL != thread->errorString) { |
42 | 0 | PR_DELETE(thread->errorString); |
43 | 0 | } |
44 | 0 | thread->errorString = (char*)PR_MALLOC(size); |
45 | 0 | if (NULL == thread->errorString) { |
46 | 0 | thread->errorStringSize = 0; |
47 | 0 | thread->errorStringLength = 0; |
48 | 0 | return; |
49 | 0 | } |
50 | 0 | thread->errorStringSize = size; |
51 | 0 | } |
52 | 0 | memcpy(thread->errorString, text, textLength + 1); |
53 | 0 | } |
54 | 0 | thread->errorStringLength = textLength; |
55 | 0 | } |
56 | | |
57 | 0 | PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void) { |
58 | 0 | PRThread* thread = PR_GetCurrentThread(); |
59 | 0 | return thread->errorStringLength; |
60 | 0 | } /* PR_GetErrorTextLength */ |
61 | | |
62 | 0 | PR_IMPLEMENT(PRInt32) PR_GetErrorText(char* text) { |
63 | 0 | PRThread* thread = PR_GetCurrentThread(); |
64 | 0 | if (0 != thread->errorStringLength) { |
65 | 0 | memcpy(text, thread->errorString, thread->errorStringLength + 1); |
66 | 0 | } |
67 | 0 | return thread->errorStringLength; |
68 | 0 | } /* PR_GetErrorText */ |