chiark / gitweb /
shared: strv - add strv_clear()
authorTom Gundersen <teg@jklm.no>
Wed, 17 Dec 2014 00:08:56 +0000 (01:08 +0100)
committerTom Gundersen <teg@jklm.no>
Wed, 17 Dec 2014 00:09:16 +0000 (01:09 +0100)
This frees the elements of the strv without freeing the strv itself.

src/shared/strv.c
src/shared/strv.h

index fdb658c0a33696a0e5d644f1c2636748ce0c3a5e..f86dddaf811223b0df1caa8f71c6f0c316440f7b 100644 (file)
@@ -69,7 +69,7 @@ char *strv_find_startswith(char **l, const char *name) {
         return NULL;
 }
 
         return NULL;
 }
 
-void strv_free(char **l) {
+void strv_clear(char **l) {
         char **k;
 
         if (!l)
         char **k;
 
         if (!l)
@@ -78,6 +78,11 @@ void strv_free(char **l) {
         for (k = l; *k; k++)
                 free(*k);
 
         for (k = l; *k; k++)
                 free(*k);
 
+        *l = NULL;
+}
+
+void strv_free(char **l) {
+        strv_clear(l);
         free(l);
 }
 
         free(l);
 }
 
index 2c0280b71307ccab1624ef2ff196cb62c1f8ba47..9e5b1bb8b0de69e465f755927a0df69d3b04bef3 100644 (file)
@@ -34,6 +34,8 @@ void strv_free(char **l);
 DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
 #define _cleanup_strv_free_ _cleanup_(strv_freep)
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
 #define _cleanup_strv_free_ _cleanup_(strv_freep)
 
+void strv_clear(char **l);
+
 char **strv_copy(char * const *l);
 unsigned strv_length(char * const *l) _pure_;
 
 char **strv_copy(char * const *l);
 unsigned strv_length(char * const *l) _pure_;