]>
git.saurik.com Git - apple/security.git/blob - SecureTransport/sslalloc.c
   2  * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. 
   4  * The contents of this file constitute Original Code as defined in and are 
   5  * subject to the Apple Public Source License Version 1.2 (the 'License'). 
   6  * You may not use this file except in compliance with the License. Please obtain 
   7  * a copy of the License at http://www.apple.com/publicsource and read it before 
  10  * This Original Code and all software distributed under the License are 
  11  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 
  12  * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 
  13  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
  14  * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 
  15  * specific language governing rights and limitations under the License. 
  22         Contains:       memory allocator implementation 
  24         Written by:     Doug Mitchell, based on Netscape SSLRef 3.0 
  26         Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved. 
  29 /*  ********************************************************************* 
  32     SSLRef 3.0 Final -- 11/19/96 
  34     Copyright (c)1996 by Netscape Communications Corp. 
  36     By retrieving this software you are bound by the licensing terms 
  37     disclosed in the file "LICENSE.txt". Please read it, and if you don't 
  38     accept the terms, delete this software. 
  40     SSLRef 3.0 was developed by Netscape Communications Corp. of Mountain 
  41     View, California <http://home.netscape.com/> and Consensus Development 
  42     Corporation of Berkeley, California <http://www.consensus.com/>. 
  44     ********************************************************************* 
  46     File: sslalloc.c   Utility functions for doing allocation 
  48     These functions call the user-supplied callbacks to 
  49     allocate/free/reallocate memory 
  51     ****************************************************************** */ 
  57 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h> 
  59 #pragma mark *** Basic low-level malloc/free *** 
  62  * For now, all allocs/frees go thru here.  
  64 #include <string.h>                     /* memset */ 
  68 sslMalloc(UInt32 length
) 
  70         return malloc(length
); 
  82 sslRealloc(void *oldPtr
, UInt32 oldLen
, UInt32 newLen
) 
  84         return realloc(oldPtr
, newLen
); 
  87 #pragma mark *** SSLBuffer-level alloc/free *** 
  89 SSLErr 
SSLAllocBuffer( 
  92         const SystemContext 
*ctx
) 
  94         buf
->data 
= sslMalloc(length
); 
  95         if(buf
->data 
== NULL
) { 
 104 SSLFreeBuffer(SSLBuffer 
*buf
, const SystemContext 
*ctx
) 
 107                 errorLog0("SSLFreeBuffer: NULL buf!\n"); 
 108                 return SSLInternalError
; 
 117 SSLReallocBuffer(SSLBuffer 
*buf
, UInt32 newSize
, const SystemContext 
*ctx
) 
 119         buf
->data 
= sslRealloc(buf
->data
, buf
->length
, newSize
); 
 120         if(buf
->data 
== NULL
) { 
 124         buf
->length 
= newSize
; 
 128 #pragma mark *** Convenience routines *** 
 136         dst 
= sslMalloc(len
); 
 140         memmove(dst
, src
, len
); 
 144 SSLErr 
SSLAllocCopyBuffer( 
 145         const SSLBuffer 
*src
,  
 146         SSLBuffer 
**dst
)                // buffer and data mallocd and returned  
 150         SSLBuffer 
*rtn 
= sslMalloc(sizeof(SSLBuffer
)); 
 154         serr 
= SSLCopyBuffer(src
, rtn
); 
 164 SSLErr 
SSLCopyBuffer( 
 165         const SSLBuffer 
*src
,  
 166         SSLBuffer 
*dst
)         // data mallocd and returned  
 168         dst
->data 
= sslAllocCopy(src
->data
, src
->length
); 
 169         if(dst
->data 
== NULL
) { 
 172     dst
->length 
= src
->length
;