16 #include "mysys_priv.h"
17 #include "mysys_err.h"
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));
39 DBUG_EXECUTE_IF(
"simulate_out_of_memory",
44 DBUG_EXECUTE_IF(
"simulate_persistent_out_of_memory",
53 if (my_flags & MY_FAE)
54 error_handler_hook=fatal_error_handler_hook;
55 if (my_flags & (MY_FAE+MY_WME))
56 my_error(EE_OUTOFMEMORY, MYF(ME_BELL + ME_WAITTANG +
57 ME_NOREFRESH + ME_FATALERROR),
size);
58 DBUG_EXECUTE_IF(
"simulate_out_of_memory",
59 DBUG_SET(
"-d,simulate_out_of_memory"););
60 if (my_flags & MY_FAE)
63 else if (my_flags & MY_ZEROFILL)
64 memset(point, 0, size);
65 DBUG_PRINT(
"exit",(
"ptr: %p", point));
80 void *my_realloc(
void *oldpoint,
size_t size, myf my_flags)
83 DBUG_ENTER(
"my_realloc");
84 DBUG_PRINT(
"my",(
"ptr: %p size: %lu my_flags: %d", oldpoint,
85 (ulong) size, my_flags));
87 DBUG_ASSERT(size > 0);
88 DBUG_EXECUTE_IF(
"simulate_out_of_memory",
91 if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
92 DBUG_RETURN(my_malloc(size, my_flags));
96 point= realloc(oldpoint, size);
103 if (my_flags & MY_FREE_ON_ERROR)
105 if (my_flags & MY_HOLD_ON_ERROR)
106 DBUG_RETURN(oldpoint);
108 if (my_flags & (MY_FAE+MY_WME))
109 my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ ME_WAITTANG + ME_FATALERROR),
111 DBUG_EXECUTE_IF(
"simulate_out_of_memory",
112 DBUG_SET(
"-d,simulate_out_of_memory"););
117 memcpy(point,oldpoint,size);
121 DBUG_PRINT(
"exit",(
"ptr: %p", point));
133 void my_free(
void *ptr)
135 DBUG_ENTER(
"my_free");
136 DBUG_PRINT(
"my",(
"ptr: %p", ptr));
142 void *my_memdup(
const void *from,
size_t length, myf my_flags)
145 if ((ptr= my_malloc(length,my_flags)) != 0)
146 memcpy(ptr, from, length);
151 char *my_strdup(
const char *from, myf my_flags)
154 size_t length= strlen(from)+1;
155 if ((ptr= (
char*) my_malloc(length, my_flags)))
156 memcpy(ptr, from, length);
161 char *my_strndup(
const char *from,
size_t length, myf my_flags)
164 if ((ptr= (
char*) my_malloc(length+1, my_flags)))
166 memcpy(ptr, from, length);