# HG changeset patch # User Mike Becker # Date 1682182866 -7200 # Node ID 72dccb56008460858077057666109f4bc1ee85b7 # Parent 35b2b99ee523a9686b59f7061b81825c0643de9d add cx_strdup_m() and cx_strdup_ma() diff -r 35b2b99ee523 -r 72dccb560084 src/cx/string.h --- a/src/cx/string.h Sat Apr 22 14:21:02 2023 +0200 +++ b/src/cx/string.h Sat Apr 22 19:01:06 2023 +0200 @@ -774,6 +774,35 @@ */ #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) + +/** + * Creates a duplicate of the specified string. + * + * The new string will contain a copy allocated by \p allocator. + * + * \note The returned string is guaranteed to be zero-terminated. + * + * @param allocator the allocator to use + * @param string the string to duplicate + * @return a duplicate of the string + * @see cx_strdup_m() + */ +#define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string)) + +/** + * Creates a duplicate of the specified string. + * + * The new string will contain a copy allocated by standard + * \c malloc(). So developers \em must pass the return value to cx_strfree(). + * + * \note The returned string is guaranteed to be zero-terminated. + * + * @param string the string to duplicate + * @return a duplicate of the string + * @see cx_strdup_ma() + */ +#define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string)) + /** * Omits leading and trailing spaces. *