]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common/mem.h: introduce xstrdup_replace()
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 15 Nov 2024 21:59:57 +0000 (22:59 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 16 Nov 2024 22:13:17 +0000 (22:13 +0000)
include/common/mem.h

index 4fd5b34900e10c3a1ceb666424ab698a456ade91..d0d5fdc59af9bf0ae2bfbe89ab676a089cc50e3c 100644 (file)
@@ -44,6 +44,14 @@ void *xrealloc(void *ptr, size_t size);
  */
 char *xstrdup(const char *str);
 
+/*
+ * Same as ptr = xstrdup(str) but free
+ * <ptr> before assigning the result.
+ */
+#define xstrdup_replace(ptr, str) do { \
+       free(ptr); (ptr) = xstrdup(str); \
+} while (0)
+
 /*
  * Frees memory pointed to by <ptr> and sets <ptr> to NULL.
  * Does nothing if <ptr> is already NULL.