comparison nss/lib/base/item.c @ 0:1e5118fa0cb1

This is NSS with a Cmake Buildsyste To compile a static NSS library for Windows we've used the Chromium-NSS fork and added a Cmake buildsystem to compile it statically for Windows. See README.chromium for chromium changes and README.trustbridge for our modifications.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 10:47:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e5118fa0cb1
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 /*
6 * item.c
7 *
8 * This contains some item-manipulation code.
9 */
10
11 #ifndef BASE_H
12 #include "base.h"
13 #endif /* BASE_H */
14
15 /*
16 * nssItem_Create
17 *
18 * -- fgmr comments --
19 *
20 * The error may be one of the following values:
21 * NSS_ERROR_INVALID_ARENA
22 * NSS_ERROR_NO_MEMORY
23 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
24 * NSS_ERROR_INVALID_POINTER
25 *
26 * Return value:
27 * A pointer to an NSSItem upon success
28 * NULL upon failure
29 */
30
31 NSS_IMPLEMENT NSSItem *
32 nssItem_Create
33 (
34 NSSArena *arenaOpt,
35 NSSItem *rvOpt,
36 PRUint32 length,
37 const void *data
38 )
39 {
40 NSSItem *rv = (NSSItem *)NULL;
41
42 #ifdef DEBUG
43 if( (NSSArena *)NULL != arenaOpt ) {
44 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
45 return (NSSItem *)NULL;
46 }
47 }
48
49 if( (const void *)NULL == data ) {
50 if( length > 0 ) {
51 nss_SetError(NSS_ERROR_INVALID_POINTER);
52 return (NSSItem *)NULL;
53 }
54 }
55 #endif /* DEBUG */
56
57 if( (NSSItem *)NULL == rvOpt ) {
58 rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
59 if( (NSSItem *)NULL == rv ) {
60 goto loser;
61 }
62 } else {
63 rv = rvOpt;
64 }
65
66 rv->size = length;
67 rv->data = nss_ZAlloc(arenaOpt, length);
68 if( (void *)NULL == rv->data ) {
69 goto loser;
70 }
71
72 if( length > 0 ) {
73 (void)nsslibc_memcpy(rv->data, data, length);
74 }
75
76 return rv;
77
78 loser:
79 if( rv != rvOpt ) {
80 nss_ZFreeIf(rv);
81 }
82
83 return (NSSItem *)NULL;
84 }
85
86 NSS_IMPLEMENT void
87 nssItem_Destroy
88 (
89 NSSItem *item
90 )
91 {
92 nss_ClearErrorStack();
93
94 nss_ZFreeIf(item->data);
95 nss_ZFreeIf(item);
96
97 }
98
99 /*
100 * nssItem_Duplicate
101 *
102 * -- fgmr comments --
103 *
104 * The error may be one of the following values:
105 * NSS_ERROR_INVALID_ARENA
106 * NSS_ERROR_NO_MEMORY
107 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
108 * NSS_ERROR_INVALID_ITEM
109 *
110 * Return value:
111 * A pointer to an NSSItem upon success
112 * NULL upon failure
113 */
114
115 NSS_IMPLEMENT NSSItem *
116 nssItem_Duplicate
117 (
118 NSSItem *obj,
119 NSSArena *arenaOpt,
120 NSSItem *rvOpt
121 )
122 {
123 #ifdef DEBUG
124 if( (NSSArena *)NULL != arenaOpt ) {
125 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
126 return (NSSItem *)NULL;
127 }
128 }
129
130 if( (NSSItem *)NULL == obj ) {
131 nss_SetError(NSS_ERROR_INVALID_ITEM);
132 return (NSSItem *)NULL;
133 }
134 #endif /* DEBUG */
135
136 return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
137 }
138
139 #ifdef DEBUG
140 /*
141 * nssItem_verifyPointer
142 *
143 * -- fgmr comments --
144 *
145 * The error may be one of the following values:
146 * NSS_ERROR_INVALID_ITEM
147 *
148 * Return value:
149 * PR_SUCCESS upon success
150 * PR_FAILURE upon failure
151 */
152
153 NSS_IMPLEMENT PRStatus
154 nssItem_verifyPointer
155 (
156 const NSSItem *item
157 )
158 {
159 if( ((const NSSItem *)NULL == item) ||
160 (((void *)NULL == item->data) && (item->size > 0)) ) {
161 nss_SetError(NSS_ERROR_INVALID_ITEM);
162 return PR_FAILURE;
163 }
164
165 return PR_SUCCESS;
166 }
167 #endif /* DEBUG */
168
169 /*
170 * nssItem_Equal
171 *
172 * -- fgmr comments --
173 *
174 * The error may be one of the following values:
175 * NSS_ERROR_INVALID_ITEM
176 *
177 * Return value:
178 * PR_TRUE if the items are identical
179 * PR_FALSE if they aren't
180 * PR_FALSE upon error
181 */
182
183 NSS_IMPLEMENT PRBool
184 nssItem_Equal
185 (
186 const NSSItem *one,
187 const NSSItem *two,
188 PRStatus *statusOpt
189 )
190 {
191 if( (PRStatus *)NULL != statusOpt ) {
192 *statusOpt = PR_SUCCESS;
193 }
194
195 if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
196 return PR_TRUE;
197 }
198
199 if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
200 return PR_FALSE;
201 }
202
203 if( one->size != two->size ) {
204 return PR_FALSE;
205 }
206
207 return nsslibc_memequal(one->data, two->data, one->size, statusOpt);
208 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)