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

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

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 years, 6 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
« no previous file with comments | « nss/lib/base/hashops.c ('k') | 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 /*
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(NSSArena *arenaOpt, NSSItem *rvOpt, PRUint32 length,
33 const void *data)
34 {
35 NSSItem *rv = (NSSItem *)NULL;
36
37 #ifdef DEBUG
38 if ((NSSArena *)NULL != arenaOpt) {
39 if (PR_SUCCESS != nssArena_verifyPointer(arenaOpt)) {
40 return (NSSItem *)NULL;
41 }
42 }
43
44 if ((const void *)NULL == data) {
45 if (length > 0) {
46 nss_SetError(NSS_ERROR_INVALID_POINTER);
47 return (NSSItem *)NULL;
48 }
49 }
50 #endif /* DEBUG */
51
52 if ((NSSItem *)NULL == rvOpt) {
53 rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
54 if ((NSSItem *)NULL == rv) {
55 goto loser;
56 }
57 } else {
58 rv = rvOpt;
59 }
60
61 rv->size = length;
62 rv->data = nss_ZAlloc(arenaOpt, length);
63 if ((void *)NULL == rv->data) {
64 goto loser;
65 }
66
67 if (length > 0) {
68 (void)nsslibc_memcpy(rv->data, data, length);
69 }
70
71 return rv;
72
73 loser:
74 if (rv != rvOpt) {
75 nss_ZFreeIf(rv);
76 }
77
78 return (NSSItem *)NULL;
79 }
80
81 NSS_IMPLEMENT void
82 nssItem_Destroy(NSSItem *item)
83 {
84 nss_ClearErrorStack();
85
86 nss_ZFreeIf(item->data);
87 nss_ZFreeIf(item);
88 }
89
90 /*
91 * nssItem_Duplicate
92 *
93 * -- fgmr comments --
94 *
95 * The error may be one of the following values:
96 * NSS_ERROR_INVALID_ARENA
97 * NSS_ERROR_NO_MEMORY
98 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
99 * NSS_ERROR_INVALID_ITEM
100 *
101 * Return value:
102 * A pointer to an NSSItem upon success
103 * NULL upon failure
104 */
105
106 NSS_IMPLEMENT NSSItem *
107 nssItem_Duplicate(NSSItem *obj, NSSArena *arenaOpt, NSSItem *rvOpt)
108 {
109 #ifdef DEBUG
110 if ((NSSArena *)NULL != arenaOpt) {
111 if (PR_SUCCESS != nssArena_verifyPointer(arenaOpt)) {
112 return (NSSItem *)NULL;
113 }
114 }
115
116 if ((NSSItem *)NULL == obj) {
117 nss_SetError(NSS_ERROR_INVALID_ITEM);
118 return (NSSItem *)NULL;
119 }
120 #endif /* DEBUG */
121
122 return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
123 }
124
125 #ifdef DEBUG
126 /*
127 * nssItem_verifyPointer
128 *
129 * -- fgmr comments --
130 *
131 * The error may be one of the following values:
132 * NSS_ERROR_INVALID_ITEM
133 *
134 * Return value:
135 * PR_SUCCESS upon success
136 * PR_FAILURE upon failure
137 */
138
139 NSS_IMPLEMENT PRStatus
140 nssItem_verifyPointer(const NSSItem *item)
141 {
142 if (((const NSSItem *)NULL == item) ||
143 (((void *)NULL == item->data) && (item->size > 0))) {
144 nss_SetError(NSS_ERROR_INVALID_ITEM);
145 return PR_FAILURE;
146 }
147
148 return PR_SUCCESS;
149 }
150 #endif /* DEBUG */
151
152 /*
153 * nssItem_Equal
154 *
155 * -- fgmr comments --
156 *
157 * The error may be one of the following values:
158 * NSS_ERROR_INVALID_ITEM
159 *
160 * Return value:
161 * PR_TRUE if the items are identical
162 * PR_FALSE if they aren't
163 * PR_FALSE upon error
164 */
165
166 NSS_IMPLEMENT PRBool
167 nssItem_Equal(const NSSItem *one, const NSSItem *two, PRStatus *statusOpt)
168 {
169 if ((PRStatus *)NULL != statusOpt) {
170 *statusOpt = PR_SUCCESS;
171 }
172
173 if (((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two)) {
174 return PR_TRUE;
175 }
176
177 if (((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two)) {
178 return PR_FALSE;
179 }
180
181 if (one->size != two->size) {
182 return PR_FALSE;
183 }
184
185 return nsslibc_memequal(one->data, two->data, one->size, statusOpt);
186 }
OLDNEW
« no previous file with comments | « nss/lib/base/hashops.c ('k') | nss/lib/base/libc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698