cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers memory.c Source File

memory.c

00001 /* memory.c 
00002  *
00003  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023     #include <config.h>
00024 #endif
00025 
00026 /* submitted by eof */
00027 
00028 
00029 #include <cyassl/ctaocrypt/settings.h>
00030 
00031 #ifdef USE_CYASSL_MEMORY
00032 
00033 #include <cyassl/ctaocrypt/memory.h>
00034 #include <cyassl/ctaocrypt/error.h>
00035 
00036 
00037 /* Set these to default values initially. */
00038 static CyaSSL_Malloc_cb  malloc_function = 0;
00039 static CyaSSL_Free_cb    free_function = 0;
00040 static CyaSSL_Realloc_cb realloc_function = 0;
00041 
00042 int CyaSSL_SetAllocators(CyaSSL_Malloc_cb  mf,
00043                          CyaSSL_Free_cb    ff,
00044                          CyaSSL_Realloc_cb rf)
00045 {
00046     int res = 0;
00047 
00048     if (mf)
00049         malloc_function = mf;
00050     else
00051         res = BAD_FUNC_ARG;
00052 
00053     if (ff)
00054         free_function = ff;
00055     else
00056         res = BAD_FUNC_ARG;
00057 
00058     if (rf)
00059         realloc_function = rf;
00060     else
00061         res = BAD_FUNC_ARG;
00062 
00063     return res;
00064 }
00065 
00066 
00067 void* CyaSSL_Malloc(size_t size)
00068 {
00069     void* res = 0;
00070 
00071     if (malloc_function)
00072         res = malloc_function(size);
00073     else
00074         res = malloc(size);
00075 
00076     return res;
00077 }
00078 
00079 void CyaSSL_Free(void *ptr)
00080 {
00081     if (free_function)
00082         free_function(ptr);
00083     else
00084         free(ptr);
00085 }
00086 
00087 void* CyaSSL_Realloc(void *ptr, size_t size)
00088 {
00089     void* res = 0;
00090 
00091     if (realloc_function)
00092         res = realloc_function(ptr, size);
00093     else
00094         res = realloc(ptr, size);
00095 
00096     return res;
00097 }
00098 
00099 #endif /* USE_CYASSL_MEMORY */