aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-26 22:20:37 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-26 22:20:37 +0200
commit439bc3acd3309099216e8c997887dae321cd09c9 (patch)
treeebd90522ee09f53620470fc2a9d8c4f50d1bba95
parentb29f4705834e2405be1335777c9143bea512a7a5 (diff)
downloadliberty-439bc3acd3309099216e8c997887dae321cd09c9.tar.gz
liberty-439bc3acd3309099216e8c997887dae321cd09c9.tar.xz
liberty-439bc3acd3309099216e8c997887dae321cd09c9.zip
Add str_vector_steal()
-rw-r--r--liberty.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/liberty.c b/liberty.c
index 8ea860f..1ae9df4 100644
--- a/liberty.c
+++ b/liberty.c
@@ -401,13 +401,20 @@ str_vector_add_vector (struct str_vector *self, char **vector)
str_vector_add (self, *vector++);
}
-static void
-str_vector_remove (struct str_vector *self, size_t i)
+static char *
+str_vector_steal (struct str_vector *self, size_t i)
{
hard_assert (i < self->len);
- free (self->vector[i]);
+ char *tmp = self->vector[i];
memmove (self->vector + i, self->vector + i + 1,
(self->len-- - i) * sizeof *self->vector);
+ return tmp;
+}
+
+static void
+str_vector_remove (struct str_vector *self, size_t i)
+{
+ free (str_vector_steal (self, i));
}
// --- Dynamically allocated strings -------------------------------------------