]>
git.saurik.com Git - apple/security.git/blob - libsecurity_ssl/lib/sslMemory.c
2 * Copyright (c) 1999-2001,2005-2007,2010-2012 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * sslMemory.c - Memory allocator implementation
28 #include "sslMemory.h"
29 #include "sslContext.h"
33 #pragma mark Basic low-level malloc/free
36 * For now, all allocs/frees go thru here.
38 #include <string.h> /* memset */
42 sslMalloc(size_t length
)
44 return malloc(length
);
56 sslRealloc(void *oldPtr
, size_t oldLen
, size_t newLen
)
58 return realloc(oldPtr
, newLen
);
62 #pragma mark SSLBuffer-level alloc/free
64 OSStatus
SSLAllocBuffer(
67 const SSLContext
*ctx
) // currently unused
69 buf
->data
= (UInt8
*)sslMalloc(length
);
70 if(buf
->data
== NULL
) {
79 SSLFreeBuffer(SSLBuffer
*buf
, const SSLContext
*ctx
)
82 sslErrorLog("SSLFreeBuffer: NULL buf!\n");
83 return errSSLInternal
;
92 SSLReallocBuffer(SSLBuffer
*buf
, size_t newSize
, const SSLContext
*ctx
)
94 buf
->data
= (UInt8
*)sslRealloc(buf
->data
, buf
->length
, newSize
);
95 if(buf
->data
== NULL
) {
99 buf
->length
= newSize
;
104 #pragma mark Convenience routines
112 dst
= (UInt8
*)sslMalloc(len
);
116 memmove(dst
, src
, len
);
120 OSStatus
SSLAllocCopyBuffer(
121 const SSLBuffer
*src
,
122 SSLBuffer
**dst
) // buffer and data mallocd and returned
126 SSLBuffer
*rtn
= (SSLBuffer
*)sslMalloc(sizeof(SSLBuffer
));
130 serr
= SSLCopyBuffer(src
, rtn
);
140 OSStatus
SSLCopyBufferFromData(
143 SSLBuffer
*dst
) // data mallocd and returned
145 dst
->data
= sslAllocCopy((const UInt8
*)src
, len
);
146 if(dst
->data
== NULL
) {
153 OSStatus
SSLCopyBuffer(
154 const SSLBuffer
*src
,
155 SSLBuffer
*dst
) // data mallocd and returned
157 return SSLCopyBufferFromData(src
->data
, src
->length
, dst
);