1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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 */
|
|
15 |
||
16 |
#include "mysys_priv.h" |
|
17 |
#include "mysys_err.h" |
|
18 |
||
19 |
/* My memory re allocator */
|
|
20 |
||
21 |
/**
|
|
22 |
@brief wrapper around realloc()
|
|
23 |
||
24 |
@param oldpoint pointer to currently allocated area
|
|
25 |
@param size new size requested, must be >0
|
|
26 |
@param my_flags flags
|
|
27 |
||
28 |
@note if size==0 realloc() may return NULL; my_realloc() treats this as an
|
|
29 |
error which is not the intention of realloc()
|
|
30 |
*/
|
|
31 |
void* my_realloc(void* oldpoint, size_t size, myf my_flags) |
|
32 |
{
|
|
33 |
void *point; |
|
34 |
DBUG_ENTER("my_realloc"); |
|
35 |
DBUG_PRINT("my",("ptr: 0x%lx size: %lu my_flags: %d", (long) oldpoint, |
|
36 |
(ulong) size, my_flags)); |
|
37 |
||
38 |
DBUG_ASSERT(size > 0); |
|
39 |
if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR)) |
|
40 |
DBUG_RETURN(my_malloc(size,my_flags)); |
|
41 |
#ifdef USE_HALLOC
|
|
42 |
if (!(point = malloc(size))) |
|
43 |
{
|
|
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); |
|
48 |
my_errno=errno; |
|
49 |
if (my_flags & MY_FAE+MY_WME) |
|
50 |
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),size); |
|
51 |
}
|
|
52 |
else
|
|
53 |
{
|
|
54 |
memcpy(point,oldpoint,size); |
|
55 |
free(oldpoint); |
|
56 |
}
|
|
57 |
#else
|
|
58 |
if ((point= (uchar*) realloc(oldpoint,size)) == NULL) |
|
59 |
{
|
|
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); |
|
64 |
my_errno=errno; |
|
65 |
if (my_flags & (MY_FAE+MY_WME)) |
|
66 |
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), size); |
|
67 |
}
|
|
68 |
#endif
|
|
69 |
DBUG_PRINT("exit",("ptr: 0x%lx", (long) point)); |
|
70 |
DBUG_RETURN(point); |
|
71 |
} /* my_realloc */ |