diff --git a/src/lib/eina/eina_binbuf.h b/src/lib/eina/eina_binbuf.h index e10728e11a..8c6d3a46a4 100644 --- a/src/lib/eina/eina_binbuf.h +++ b/src/lib/eina/eina_binbuf.h @@ -388,6 +388,17 @@ EAPI Eina_Slice eina_binbuf_slice_get(const Eina_Binbuf *buf) EINA_WARN_UNUSED_R * @since 1.19 */ EAPI Eina_Rw_Slice eina_binbuf_rw_slice_get(const Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); +/** + * @brief Get the content of the buffer and free the buffer + * + * @param buf the buffer to get the content from and which will be freed + * + * @return The content contained by buf. The caller must release the memory of the returned content by calling + * free(). + * + * @since 1.19 + */ +EAPI unsigned char* eina_binbuf_release(Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); /** * @} diff --git a/src/lib/eina/eina_binbuf_template_c.x b/src/lib/eina/eina_binbuf_template_c.x index 72b6fd7972..2699997f9d 100644 --- a/src/lib/eina/eina_binbuf_template_c.x +++ b/src/lib/eina/eina_binbuf_template_c.x @@ -216,3 +216,14 @@ _FUNC_EXPAND(rw_slice_get)(const _STRBUF_STRUCT_NAME *buf) EINA_MAGIC_CHECK_STRBUF(buf, ret); return eina_strbuf_common_rw_slice_get(buf); } + +EAPI _STRBUF_DATA_TYPE* +_FUNC_EXPAND(release)(_STRBUF_STRUCT_NAME *buf) +{ + _STRBUF_DATA_TYPE *result; + + result = _FUNC_EXPAND(string_steal)(buf); + _FUNC_EXPAND(string_free)(buf); + + return result; +} diff --git a/src/lib/eina/eina_strbuf.c b/src/lib/eina/eina_strbuf.c index b784a701ab..81ab30a45f 100644 --- a/src/lib/eina/eina_strbuf.c +++ b/src/lib/eina/eina_strbuf.c @@ -220,17 +220,6 @@ eina_strbuf_substr_get(Eina_Strbuf *buf, size_t pos, size_t len) return eina_strbuf_manage_new(str); } -EAPI char* -eina_strbuf_free_return(Eina_Strbuf *buf) -{ - char *result; - - result = eina_strbuf_string_steal(buf); - eina_strbuf_free(buf); - - return result; -} - /* Unicode */ #include "eina_strbuf_template_c.x" diff --git a/src/lib/eina/eina_strbuf.h b/src/lib/eina/eina_strbuf.h index 9c2506c816..cd70a3dc8d 100644 --- a/src/lib/eina/eina_strbuf.h +++ b/src/lib/eina/eina_strbuf.h @@ -729,7 +729,7 @@ EAPI Eina_Rw_Slice eina_strbuf_rw_slice_get(const Eina_Strbuf *buf) EINA_WARN_UN * * @since 1.19 */ -EAPI char* eina_strbuf_free_return(Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); +EAPI char* eina_strbuf_release(Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); /** * @} diff --git a/src/lib/eina/eina_ustrbuf.h b/src/lib/eina/eina_ustrbuf.h index b0c6799772..f186b2cc7d 100644 --- a/src/lib/eina/eina_ustrbuf.h +++ b/src/lib/eina/eina_ustrbuf.h @@ -468,6 +468,18 @@ EAPI Eina_Slice eina_ustrbuf_slice_get(const Eina_UStrbuf *buf) EINA_WARN_UNUSED */ EAPI Eina_Rw_Slice eina_ustrbuf_rw_slice_get(const Eina_UStrbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); +/** + * @brief Get the string of the buffer and free the buffer + * + * @param buf the buffer to get the string from and which will be freed + * + * @return The string contained by buf. The caller must release the memory of the returned string by calling + * free(). + * + * @since 1.19 + */ +EAPI Eina_Unicode* eina_ustrbuf_release(Eina_UStrbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); + /** * @} */ diff --git a/src/tests/eina/eina_test_strbuf.c b/src/tests/eina/eina_test_strbuf.c index 8206720ed3..0511d96011 100644 --- a/src/tests/eina/eina_test_strbuf.c +++ b/src/tests/eina/eina_test_strbuf.c @@ -646,17 +646,17 @@ START_TEST(strbuf_prepend_print) } END_TEST -START_TEST(strbuf_free_return_test) +START_TEST(strbuf_release_test) { Eina_Strbuf *buf; char *string; buf = eina_strbuf_new(); ck_assert_ptr_ne(buf, NULL); - eina_strbuf_append(buf, "strbuf_free_return_test"); + eina_strbuf_append(buf, "strbuf_release_test"); - string = eina_strbuf_free_return(buf); - ck_assert_str_eq(string, "strbuf_free_return_test"); + string = eina_strbuf_release(buf); + ck_assert_str_eq(string, "strbuf_release_test"); } END_TEST @@ -676,5 +676,5 @@ eina_test_strbuf(TCase *tc) tcase_add_test(tc, strbuf_tolower); tcase_add_test(tc, strbuf_substr_get); tcase_add_test(tc, strbuf_prepend_print); - tcase_add_test(tc, strbuf_free_return_test); + tcase_add_test(tc, strbuf_release_test); }