Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / security / nss / lib / base / item.c
blob9713f36ae1460ece4f29d7a0e0528bfc72f11ec7
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifdef DEBUG
38 static const char CVS_ID[] = "@(#) $RCSfile: item.c,v $ $Revision: 1.4 $ $Date: 2005/01/20 02:25:45 $";
39 #endif /* DEBUG */
42 * item.c
44 * This contains some item-manipulation code.
47 #ifndef BASE_H
48 #include "base.h"
49 #endif /* BASE_H */
52 * nssItem_Create
54 * -- fgmr comments --
56 * The error may be one of the following values:
57 * NSS_ERROR_INVALID_ARENA
58 * NSS_ERROR_NO_MEMORY
59 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
60 * NSS_ERROR_INVALID_POINTER
62 * Return value:
63 * A pointer to an NSSItem upon success
64 * NULL upon failure
67 NSS_IMPLEMENT NSSItem *
68 nssItem_Create
70 NSSArena *arenaOpt,
71 NSSItem *rvOpt,
72 PRUint32 length,
73 const void *data
76 NSSItem *rv = (NSSItem *)NULL;
78 #ifdef DEBUG
79 if( (NSSArena *)NULL != arenaOpt ) {
80 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
81 return (NSSItem *)NULL;
85 if( (const void *)NULL == data ) {
86 if( length > 0 ) {
87 nss_SetError(NSS_ERROR_INVALID_POINTER);
88 return (NSSItem *)NULL;
91 #endif /* DEBUG */
93 if( (NSSItem *)NULL == rvOpt ) {
94 rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
95 if( (NSSItem *)NULL == rv ) {
96 goto loser;
98 } else {
99 rv = rvOpt;
102 rv->size = length;
103 rv->data = nss_ZAlloc(arenaOpt, length);
104 if( (void *)NULL == rv->data ) {
105 goto loser;
108 if( length > 0 ) {
109 (void)nsslibc_memcpy(rv->data, data, length);
112 return rv;
114 loser:
115 if( rv != rvOpt ) {
116 nss_ZFreeIf(rv);
119 return (NSSItem *)NULL;
122 NSS_IMPLEMENT void
123 nssItem_Destroy
125 NSSItem *item
128 nss_ClearErrorStack();
130 nss_ZFreeIf(item->data);
131 nss_ZFreeIf(item);
136 * nssItem_Duplicate
138 * -- fgmr comments --
140 * The error may be one of the following values:
141 * NSS_ERROR_INVALID_ARENA
142 * NSS_ERROR_NO_MEMORY
143 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
144 * NSS_ERROR_INVALID_ITEM
146 * Return value:
147 * A pointer to an NSSItem upon success
148 * NULL upon failure
151 NSS_IMPLEMENT NSSItem *
152 nssItem_Duplicate
154 NSSItem *obj,
155 NSSArena *arenaOpt,
156 NSSItem *rvOpt
159 #ifdef DEBUG
160 if( (NSSArena *)NULL != arenaOpt ) {
161 if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
162 return (NSSItem *)NULL;
166 if( (NSSItem *)NULL == obj ) {
167 nss_SetError(NSS_ERROR_INVALID_ITEM);
168 return (NSSItem *)NULL;
170 #endif /* DEBUG */
172 return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
175 #ifdef DEBUG
177 * nssItem_verifyPointer
179 * -- fgmr comments --
181 * The error may be one of the following values:
182 * NSS_ERROR_INVALID_ITEM
184 * Return value:
185 * PR_SUCCESS upon success
186 * PR_FAILURE upon failure
189 NSS_IMPLEMENT PRStatus
190 nssItem_verifyPointer
192 const NSSItem *item
195 if( ((const NSSItem *)NULL == item) ||
196 (((void *)NULL == item->data) && (item->size > 0)) ) {
197 nss_SetError(NSS_ERROR_INVALID_ITEM);
198 return PR_FAILURE;
201 return PR_SUCCESS;
203 #endif /* DEBUG */
206 * nssItem_Equal
208 * -- fgmr comments --
210 * The error may be one of the following values:
211 * NSS_ERROR_INVALID_ITEM
213 * Return value:
214 * PR_TRUE if the items are identical
215 * PR_FALSE if they aren't
216 * PR_FALSE upon error
219 NSS_IMPLEMENT PRBool
220 nssItem_Equal
222 const NSSItem *one,
223 const NSSItem *two,
224 PRStatus *statusOpt
227 if( (PRStatus *)NULL != statusOpt ) {
228 *statusOpt = PR_SUCCESS;
231 if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
232 return PR_TRUE;
235 if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
236 return PR_FALSE;
239 if( one->size != two->size ) {
240 return PR_FALSE;
243 return nsslibc_memequal(one->data, two->data, one->size, statusOpt);