1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
19
/* My memory re allocator */
22
@brief wrapper around realloc()
24
@param oldpoint pointer to currently allocated area
25
@param size new size requested, must be >0
28
@note if size==0 realloc() may return NULL; my_realloc() treats this as an
29
error which is not the intention of realloc()
31
void* my_realloc(void* oldpoint, size_t size, myf my_flags)
34
DBUG_ENTER("my_realloc");
35
DBUG_PRINT("my",("ptr: 0x%lx size: %lu my_flags: %d", (long) oldpoint,
36
(ulong) size, my_flags));
38
DBUG_ASSERT(size > 0);
39
if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
40
DBUG_RETURN(my_malloc(size,my_flags));
42
if (!(point = malloc(size)))
44
if (my_flags & MY_FREE_ON_ERROR)
45
my_free(oldpoint,my_flags);
46
if (my_flags & MY_HOLD_ON_ERROR)
47
DBUG_RETURN(oldpoint);
49
if (my_flags & MY_FAE+MY_WME)
50
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),size);
54
memcpy(point,oldpoint,size);
58
if ((point= (uchar*) realloc(oldpoint,size)) == NULL)
60
if (my_flags & MY_FREE_ON_ERROR)
61
my_free(oldpoint, my_flags);
62
if (my_flags & MY_HOLD_ON_ERROR)
63
DBUG_RETURN(oldpoint);
65
if (my_flags & (MY_FAE+MY_WME))
66
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), size);
69
DBUG_PRINT("exit",("ptr: 0x%lx", (long) point));