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
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.
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 ***** */
38
static const char CVS_ID[] = "@(#) $RCSfile: item.c,v $ $Revision: 1.4 $ $Date: 2005/01/20 02:25:45 $";
44
* This contains some item-manipulation code.
56
* The error may be one of the following values:
57
* NSS_ERROR_INVALID_ARENA
59
* NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
60
* NSS_ERROR_INVALID_POINTER
63
* A pointer to an NSSItem upon success
67
NSS_IMPLEMENT NSSItem *
76
NSSItem *rv = (NSSItem *)NULL;
79
if( (NSSArena *)NULL != arenaOpt ) {
80
if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
81
return (NSSItem *)NULL;
85
if( (const void *)NULL == data ) {
87
nss_SetError(NSS_ERROR_INVALID_POINTER);
88
return (NSSItem *)NULL;
93
if( (NSSItem *)NULL == rvOpt ) {
94
rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
95
if( (NSSItem *)NULL == rv ) {
103
rv->data = nss_ZAlloc(arenaOpt, length);
104
if( (void *)NULL == rv->data ) {
109
(void)nsslibc_memcpy(rv->data, data, length);
119
return (NSSItem *)NULL;
128
nss_ClearErrorStack();
130
nss_ZFreeIf(item->data);
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
147
* A pointer to an NSSItem upon success
151
NSS_IMPLEMENT NSSItem *
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;
172
return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
177
* nssItem_verifyPointer
179
* -- fgmr comments --
181
* The error may be one of the following values:
182
* NSS_ERROR_INVALID_ITEM
185
* PR_SUCCESS upon success
186
* PR_FAILURE upon failure
189
NSS_IMPLEMENT PRStatus
190
nssItem_verifyPointer
195
if( ((const NSSItem *)NULL == item) ||
196
(((void *)NULL == item->data) && (item->size > 0)) ) {
197
nss_SetError(NSS_ERROR_INVALID_ITEM);
208
* -- fgmr comments --
210
* The error may be one of the following values:
211
* NSS_ERROR_INVALID_ITEM
214
* PR_TRUE if the items are identical
215
* PR_FALSE if they aren't
216
* PR_FALSE upon error
227
if( (PRStatus *)NULL != statusOpt ) {
228
*statusOpt = PR_SUCCESS;
231
if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
235
if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
239
if( one->size != two->size ) {
243
return nsslibc_memequal(one->data, two->data, one->size, statusOpt);