add cx_strdup_m() and cx_strdup_ma()

Sat, 22 Apr 2023 19:01:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 22 Apr 2023 19:01:06 +0200
changeset 700
72dccb560084
parent 699
35b2b99ee523
child 701
72a440c437e9

add cx_strdup_m() and cx_strdup_ma()

src/cx/string.h file | annotate | diff | comparison | revisions
--- 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.
  *

mercurial