coan 4.2.4
|
00001 /*************************************************************************** 00002 * Copyright (C) 2004, 2006 Symbian Software Ltd. * 00003 * All rights reserved. * 00004 * * 00005 * Contributed originally by Mike Kinghan, imk@strudl.org * 00006 * * 00007 * Redistribution and use in source and binary forms, with or without * 00008 * modification, are permitted provided that the following conditions * 00009 * are met: * 00010 * * 00011 * Redistributions of source code must retain the above copyright * 00012 * notice, this list of conditions and the following disclaimer. * 00013 * * 00014 * Redistributions in binary form must reproduce the above copyright * 00015 * notice, this list of conditions and the following disclaimer in the * 00016 * documentation and/or other materials provided with the distribution. * 00017 * * 00018 * Neither the name of Symbian Software Ltd. nor the names of its * 00019 * contributors may be used to endorse or promote products derived from * 00020 * this software without specific prior written permission. * 00021 * * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 00029 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * 00030 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 00032 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00033 * DAMAGE. * 00034 * * 00035 **************************************************************************/ 00036 #include "report.h" 00037 #include "memory.h" 00038 00044 /* Helpers **********************************************************/ 00045 00048 00055 static void * 00056 no_alloc_fail(void *ptr) 00057 { 00058 if (!ptr) { 00059 bail(GRIPE_OUT_OF_MEMORY,"Out of memory"); 00060 } 00061 return ptr; 00062 } 00065 /* API **************************************************************/ 00066 00067 void * 00068 allocate(size_t bytes) 00069 { 00070 return no_alloc_fail(malloc(bytes)); 00071 } 00072 00073 00074 void * 00075 zallocate(size_t bytes) 00076 { 00077 return no_alloc_fail(calloc(bytes,1)); 00078 } 00079 00080 void * 00081 reallocate(void *ptr, size_t bytes) 00082 { 00083 return no_alloc_fail(realloc(ptr,bytes)); 00084 } 00085 00086 void * 00087 callocate(size_t items, size_t size) 00088 { 00089 return no_alloc_fail(calloc(items,size)); 00090 } 00091 00092 void release(void **pp) 00093 { 00094 if (*pp) { 00095 free(*pp); 00096 *pp = NULL; 00097 } 00098 } 00099 00100 void * 00101 clone(void const *src, size_t len) 00102 { 00103 char *dest = NULL; 00104 if (src) { 00105 if (!len) { 00106 len = strlen(src); 00107 } 00108 dest = allocate(len + 1); 00109 ((char *)memcpy(dest,src,len))[len] = 0; 00110 } 00111 return dest; 00112 } 00113 00114 00115 /* EOF*/