Commit 0fb81c1d authored by osku's avatar osku

Add mem_heap_dup().

parent 66946183
......@@ -297,8 +297,8 @@ char*
mem_heap_strdup(
/*============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str); /* in: string to be copied */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str); /* in: string to be copied */
/**************************************************************************
Makes a NUL-terminated copy of a nonterminated string,
allocated from a memory heap. */
......@@ -322,6 +322,17 @@ mem_heap_strcat(
const char* s1, /* in: string 1 */
const char* s2); /* in: string 2 */
/**************************************************************************
Duplicate a block of data, allocated from a memory heap. */
void*
mem_heap_dup(
/*=========*/
/* out, own: a copy of the data */
mem_heap_t* heap, /* in: memory heap where copy is allocated */
const void* data, /* in: data to be copied */
ulint len); /* in: length of data, in bytes */
#ifdef MEM_PERIODIC_CHECK
/**********************************************************************
Goes through the list of all allocated mem blocks, checks their magic
......
......@@ -107,11 +107,24 @@ char*
mem_heap_strdup(
/*============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str) /* in: string to be copied */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str) /* in: string to be copied */
{
return(mem_heap_dup(heap, str, strlen(str) + 1));
}
/**************************************************************************
Duplicate a block of data, allocated from a memory heap. */
void*
mem_heap_dup(
/*=========*/
/* out, own: a copy of the data */
mem_heap_t* heap, /* in: memory heap where copy is allocated */
const void* data, /* in: data to be copied */
ulint len) /* in: length of data, in bytes */
{
ulint len = strlen(str) + 1;
return(memcpy(mem_heap_alloc(heap, len), str, len));
return(memcpy(mem_heap_alloc(heap, len), data, len));
}
/**************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment