discomfitor pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=10d8199b2f5562c1ed6b907865e707a2ccfaee34
commit 10d8199b2f5562c1ed6b907865e707a2ccfaee34 Author: Mike Blumenkrantz <[email protected]> Date: Mon Dec 15 14:30:43 2014 -0500 +eina_memdup for those times when three lines of code should be one @feature --- src/lib/eina/eina_str.c | 13 +++++++++++++ src/lib/eina/eina_str.h | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c index be88c75..770a644 100644 --- a/src/lib/eina/eina_str.c +++ b/src/lib/eina/eina_str.c @@ -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; +} diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h index dae592b..f3e9f9f 100644 --- a/src/lib/eina/eina_str.h +++ b/src/lib/eina/eina_str.h @@ -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" /** --
