1 | /*************************************** 2 | $Revision: 1.2 $ 3 | 4 | Utilities (ut). memwrap.c - memory allocation wrappers. 5 | Facilitate easy changing a memory allocation 6 | library and provide uniform error codes. 7 | 8 | Status: NOT REVUED, TESTED, 9 | 10 | Design and implementation by: Marek Bukowy 11 | 12 | ******************/ /****************** 13 | Copyright (c) 1999 RIPE NCC 14 | 15 | All Rights Reserved 16 | 17 | Permission to use, copy, modify, and distribute this software and its 18 | documentation for any purpose and without fee is hereby granted, 19 | provided that the above copyright notice appear in all copies and that 20 | both that copyright notice and this permission notice appear in 21 | supporting documentation, and that the name of the author not be 22 | used in advertising or publicity pertaining to distribution of the 23 | software without specific, written prior permission. 24 | 25 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 26 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 27 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 28 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 29 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | ***************************************/ 32 | 33 | #include <stdlib.h> 34 | #include <erroutines.h> 35 | #include <stubs.h> 36 | 37 | er_ret_t 38 | wr_malloc(void **ptr, size_t size) 39 | { 40 | if( (*ptr = malloc(size)) == NULL ) { 41 | // die; /* this should return an appropriate error number */ 42 | return UT_OUTMEM; 43 | } 44 | else 45 | return UT_OK; 46 | } 47 | 48 | er_ret_t 49 | wr_calloc(void **ptr, size_t num, size_t size) 50 | { 51 | void *newalloc; 52 | 53 | newalloc = calloc(num, size); 54 | 55 | if( newalloc == NULL ) { 56 | //die; /* this should return an appropriate error number */ 57 | return UT_OUTMEM; 58 | } 59 | else { 60 | *ptr=newalloc; 61 | return UT_OK; 62 | } 63 | } 64 | 65 | 66 | er_ret_t 67 | wr_realloc(void **ptr, void *oldptr, size_t size) 68 | { 69 | if( (*ptr = realloc(oldptr, size)) == NULL ) { 70 | // die; /* this should return an appropriate error number */ 71 | return UT_OUTMEM; 72 | } 73 | else 74 | return UT_OK; 75 | } 76 | 77 | er_ret_t 78 | wr_free(void *ptr) 79 | { 80 | free(ptr); 81 | return UT_OK; 82 | } 83 | 84 |