Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: mozilla/security/nss/lib/base/item.c

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mozilla/security/nss/lib/base/hashops.c ('k') | mozilla/security/nss/lib/base/libc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #ifdef DEBUG
6 static const char CVS_ID[] = "@(#) $RCSfile: item.c,v $ $Revision: 1.5 $ $Date: 2012/04/25 14:49:26 $";
7 #endif /* DEBUG */
8
9 /*
10 * item.c
11 *
12 * This contains some item-manipulation code.
13 */
14
15 #ifndef BASE_H
16 #include "base.h"
17 #endif /* BASE_H */
18
19 /*
20 * nssItem_Create
21 *
22 * -- fgmr comments --
23 *
24 * The error may be one of the following values:
25 * NSS_ERROR_INVALID_ARENA
26 * NSS_ERROR_NO_MEMORY
27 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
28 * NSS_ERROR_INVALID_POINTER
29 *
30 * Return value:
31 * A pointer to an NSSItem upon success
32 * NULL upon failure
33 */
34
35 NSS_IMPLEMENT NSSItem *
36 nssItem_Create
37 (
38 NSSArena *arenaOpt,
39 NSSItem *rvOpt,
40 PRUint32 length,
41 const void *data
42 )
43 {
44 NSSItem *rv = (NSSItem *)NULL;
45
46 #ifdef DEBUG
47 if( (NSSArena *)NULL != arenaOpt ) {
48 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
49 return (NSSItem *)NULL;
50 }
51 }
52
53 if( (const void *)NULL == data ) {
54 if( length > 0 ) {
55 nss_SetError(NSS_ERROR_INVALID_POINTER);
56 return (NSSItem *)NULL;
57 }
58 }
59 #endif /* DEBUG */
60
61 if( (NSSItem *)NULL == rvOpt ) {
62 rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
63 if( (NSSItem *)NULL == rv ) {
64 goto loser;
65 }
66 } else {
67 rv = rvOpt;
68 }
69
70 rv->size = length;
71 rv->data = nss_ZAlloc(arenaOpt, length);
72 if( (void *)NULL == rv->data ) {
73 goto loser;
74 }
75
76 if( length > 0 ) {
77 (void)nsslibc_memcpy(rv->data, data, length);
78 }
79
80 return rv;
81
82 loser:
83 if( rv != rvOpt ) {
84 nss_ZFreeIf(rv);
85 }
86
87 return (NSSItem *)NULL;
88 }
89
90 NSS_IMPLEMENT void
91 nssItem_Destroy
92 (
93 NSSItem *item
94 )
95 {
96 nss_ClearErrorStack();
97
98 nss_ZFreeIf(item->data);
99 nss_ZFreeIf(item);
100
101 }
102
103 /*
104 * nssItem_Duplicate
105 *
106 * -- fgmr comments --
107 *
108 * The error may be one of the following values:
109 * NSS_ERROR_INVALID_ARENA
110 * NSS_ERROR_NO_MEMORY
111 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
112 * NSS_ERROR_INVALID_ITEM
113 *
114 * Return value:
115 * A pointer to an NSSItem upon success
116 * NULL upon failure
117 */
118
119 NSS_IMPLEMENT NSSItem *
120 nssItem_Duplicate
121 (
122 NSSItem *obj,
123 NSSArena *arenaOpt,
124 NSSItem *rvOpt
125 )
126 {
127 #ifdef DEBUG
128 if( (NSSArena *)NULL != arenaOpt ) {
129 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
130 return (NSSItem *)NULL;
131 }
132 }
133
134 if( (NSSItem *)NULL == obj ) {
135 nss_SetError(NSS_ERROR_INVALID_ITEM);
136 return (NSSItem *)NULL;
137 }
138 #endif /* DEBUG */
139
140 return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
141 }
142
143 #ifdef DEBUG
144 /*
145 * nssItem_verifyPointer
146 *
147 * -- fgmr comments --
148 *
149 * The error may be one of the following values:
150 * NSS_ERROR_INVALID_ITEM
151 *
152 * Return value:
153 * PR_SUCCESS upon success
154 * PR_FAILURE upon failure
155 */
156
157 NSS_IMPLEMENT PRStatus
158 nssItem_verifyPointer
159 (
160 const NSSItem *item
161 )
162 {
163 if( ((const NSSItem *)NULL == item) ||
164 (((void *)NULL == item->data) && (item->size > 0)) ) {
165 nss_SetError(NSS_ERROR_INVALID_ITEM);
166 return PR_FAILURE;
167 }
168
169 return PR_SUCCESS;
170 }
171 #endif /* DEBUG */
172
173 /*
174 * nssItem_Equal
175 *
176 * -- fgmr comments --
177 *
178 * The error may be one of the following values:
179 * NSS_ERROR_INVALID_ITEM
180 *
181 * Return value:
182 * PR_TRUE if the items are identical
183 * PR_FALSE if they aren't
184 * PR_FALSE upon error
185 */
186
187 NSS_IMPLEMENT PRBool
188 nssItem_Equal
189 (
190 const NSSItem *one,
191 const NSSItem *two,
192 PRStatus *statusOpt
193 )
194 {
195 if( (PRStatus *)NULL != statusOpt ) {
196 *statusOpt = PR_SUCCESS;
197 }
198
199 if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
200 return PR_TRUE;
201 }
202
203 if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
204 return PR_FALSE;
205 }
206
207 if( one->size != two->size ) {
208 return PR_FALSE;
209 }
210
211 return nsslibc_memequal(one->data, two->data, one->size, statusOpt);
212 }
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/base/hashops.c ('k') | mozilla/security/nss/lib/base/libc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698