+eina_memdup

for those times when three lines of code should be one

@feature
This commit is contained in:
Mike Blumenkrantz 2014-12-15 14:30:43 -05:00
parent 5cda4c1eb5
commit 10d8199b2f
2 changed files with 22 additions and 0 deletions

View File

@ -662,3 +662,16 @@ eina_str_toupper(char **str)
for (p = *str; (*p); p++)
*p = toupper((unsigned char)(*p));
}
EAPI unsigned char *
eina_memdup(unsigned char *mem, size_t size, Eina_Bool terminate)
{
unsigned char *ret;
terminate = !!terminate;
ret = malloc(size + terminate);
memcpy(ret, mem, size);
if (terminate)
ret[size] = 0;
return ret;
}

View File

@ -345,6 +345,15 @@ static inline size_t eina_str_join(char *dst, size_t size, char sep, const char
static inline size_t eina_strlen_bounded(const char *str, size_t maxlen) EINA_PURE EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
/**
* @brief memory duplication function with optional termination for strings
* @param mem The memory to copy
* @param size The size of @p mem
* @param terminate If true, the returned memory will be nul terminated with '\0'
* @return the copied memory, must be freed
* @since 1.13
*/
EAPI unsigned char *eina_memdup(unsigned char *mem, size_t size, Eina_Bool terminate);
#include "eina_inline_str.x"
/**