summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2014-12-15 14:30:43 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2014-12-15 14:32:42 -0500
commit10d8199b2f5562c1ed6b907865e707a2ccfaee34 (patch)
tree451460d9ac8401f515332fba510d6677a48606ba
parent5cda4c1eb523ed65311ac17dfe42c752772a316d (diff)
+eina_memdup
for those times when three lines of code should be one @feature
-rw-r--r--src/lib/eina/eina_str.c13
-rw-r--r--src/lib/eina/eina_str.h9
2 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c
index be88c75ec3..770a644049 100644
--- a/src/lib/eina/eina_str.c
+++ b/src/lib/eina/eina_str.c
@@ -662,3 +662,16 @@ eina_str_toupper(char **str)
662 for (p = *str; (*p); p++) 662 for (p = *str; (*p); p++)
663 *p = toupper((unsigned char)(*p)); 663 *p = toupper((unsigned char)(*p));
664} 664}
665
666EAPI unsigned char *
667eina_memdup(unsigned char *mem, size_t size, Eina_Bool terminate)
668{
669 unsigned char *ret;
670
671 terminate = !!terminate;
672 ret = malloc(size + terminate);
673 memcpy(ret, mem, size);
674 if (terminate)
675 ret[size] = 0;
676 return ret;
677}
diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h
index dae592bac6..f3e9f9f53e 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
345 345
346static inline size_t eina_strlen_bounded(const char *str, size_t maxlen) EINA_PURE EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); 346static inline size_t eina_strlen_bounded(const char *str, size_t maxlen) EINA_PURE EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
347 347
348/**
349 * @brief memory duplication function with optional termination for strings
350 * @param mem The memory to copy
351 * @param size The size of @p mem
352 * @param terminate If true, the returned memory will be nul terminated with '\0'
353 * @return the copied memory, must be freed
354 * @since 1.13
355 */
356EAPI unsigned char *eina_memdup(unsigned char *mem, size_t size, Eina_Bool terminate);
348#include "eina_inline_str.x" 357#include "eina_inline_str.x"
349 358
350/** 359/**