strv: introduce strv_free_and_replace()
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Nov 2017 22:21:57 +0000 (23:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2017 15:43:15 +0000 (16:43 +0100)
it's like free_and_replace() but uses strv_free()

src/basic/strv.h

index c793b2c..0ed6b74 100644 (file)
@@ -181,3 +181,11 @@ char **strv_skip(char **l, size_t n);
 int strv_extend_n(char ***l, const char *value, size_t n);
 
 int fputstrv(FILE *f, char **l, const char *separator, bool *space);
+
+#define strv_free_and_replace(a, b)             \
+        ({                                      \
+                strv_free(a);                   \
+                (a) = (b);                      \
+                (b) = NULL;                     \
+                0;                              \
+        })