2 Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */
22 #include "mysys_priv.h"
23 #include "mysys_err.h"
26 /* My memory allocator */
28 void *my_malloc(size_t size
, myf my_flags
)
31 DBUG_ENTER("my_malloc");
32 DBUG_PRINT("my",("size: %lu my_flags: %d", (ulong
) size
, my_flags
));
37 point
= (char *) malloc(size
);
38 DBUG_EXECUTE_IF("simulate_out_of_memory",
47 if (my_flags
& MY_FAE
)
48 error_handler_hook
=fatal_error_handler_hook
;
49 if (my_flags
& (MY_FAE
+MY_WME
))
50 my_error(EE_OUTOFMEMORY
, MYF(ME_BELL
+ME_WAITTANG
+ME_NOREFRESH
),size
);
51 DBUG_EXECUTE_IF("simulate_out_of_memory",
52 DBUG_SET("-d,simulate_out_of_memory"););
53 if (my_flags
& MY_FAE
)
56 else if (my_flags
& MY_ZEROFILL
)
58 DBUG_PRINT("exit",("ptr: 0x%lx", (long) point
));
59 DBUG_RETURN((void*) point
);
63 /* Free memory allocated with my_malloc */
66 void my_no_flags_free(void* ptr
)
68 DBUG_ENTER("my_free");
69 DBUG_PRINT("my",("ptr: 0x%lx", (long) ptr
));
78 void* my_memdup(const void *from
, size_t length
, myf my_flags
)
81 if ((ptr
= my_malloc(length
,my_flags
)) != 0)
82 memcpy(ptr
, from
, length
);
87 char *my_strdup(const char *from
, myf my_flags
)
90 size_t length
= strlen(from
)+1;
91 if ((ptr
= (char*) my_malloc(length
, my_flags
)))
92 memcpy((uchar
*) ptr
, (uchar
*) from
,(size_t) length
);
97 char *my_strndup(const char *from
, size_t length
, myf my_flags
)
100 if ((ptr
= (char*) my_malloc(length
+1,my_flags
)) != 0)
102 memcpy((uchar
*) ptr
, (uchar
*) from
, length
);