[lxc-devel] [PATCH 2/6] Delete string from array Add function to delete a string from a non-null terminated buffer

Christian Brauner christianvanbrauner at gmail.com
Sun Sep 6 08:38:17 UTC 2015


Signed-off-by: Christian Brauner <christianvanbrauner at gmail.com>

 100.0% src/lxc/
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 7ced314..5940542 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1466,3 +1466,17 @@ err:
 	close(fd);
 	return ret;
 }
+
+bool lxc_delete_string_in_array(char *haystack, size_t haystacklen,
+				const char *needle, size_t needlelen)
+{
+	char *del = NULL;
+	bool bret = false;
+
+	if ((del = memmem(haystack, haystacklen, needle, needlelen))) {
+		memmove(del, del + needlelen, strlen(del) - needlelen + 1);
+		bret = true;
+	}
+	return bret;
+}
+
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index ee12dde..715d125 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -243,6 +243,9 @@ extern char *lxc_append_paths(const char *first, const char *second);
 extern bool lxc_string_in_list(const char *needle, const char *haystack, char sep);
 extern char **lxc_string_split(const char *string, char sep);
 extern char **lxc_string_split_and_trim(const char *string, char sep);
+/* Delete a string from a non-null terminated buffer. */
+bool lxc_delete_string_in_array(char *haystack, size_t haystacklen,
+				const char *needle, size_t needlelen);
 
 /* some simple array manipulation utilities */
 typedef void (*lxc_free_fn)(void *);
-- 
2.5.1



More information about the lxc-devel mailing list