ec_mt_strndup

March 26, 2020 Contributors

Name

ec_mt_strndup — Duplicate a string of the specified message type copying at most the specified number of bytes

Synopsis

#include "ec_malloc.h"

| (char *) **ec_mt_strndup** ( | object_type, |   |
|   | str, |   |
|   | len); |   |

int <var class="pdparam">object_type</var>;
const char * <var class="pdparam">str</var>;
size_t <var class="pdparam">len</var>;

Description

Duplicate a string of the specified message type copying at most the specified number of bytes. A terminating null byte is added. The build-in memtypes are enumerated at the section called “Memory Types”. To create your own memory type use ec_memtype_register.

Note

This function is only valid with VSIZE memory type, not a fixed size type. For more information about memory types see Memory Types.

The ec_strndup function is a macro for duplicating a string of the MEMTYPE_MESSAGE_BODY type: It calls ec_mt_strdup(MEMTYPE_MESSAGE_BODY, __str, len).

Parameters

object_type

This parameter is an integer indicating a specific memory type.

str

A pointer to the string you wish to duplicate.

len

The number of bytes to copy, typically the length of the string.

Return Value

This function returns a pointer to the duplicated string.

Threading

It is legal to call this function in the any thread.

See Also

ec_malloc, ec_malloc_size, ec_realloc, ec_memtype_register and ec_mt_strdup.