diff --git a/include/common/mem.h b/include/common/mem.h index 4fd5b349..d0d5fdc5 100644 --- a/include/common/mem.h +++ b/include/common/mem.h @@ -44,6 +44,14 @@ void *xrealloc(void *ptr, size_t size); */ char *xstrdup(const char *str); +/* + * Same as ptr = xstrdup(str) but free + * before assigning the result. + */ +#define xstrdup_replace(ptr, str) do { \ + free(ptr); (ptr) = xstrdup(str); \ +} while (0) + /* * Frees memory pointed to by and sets to NULL. * Does nothing if is already NULL.