update_engine: Move glib related utils to glib_utils.h.
This patch move the remaining glib.h functions used from utils.h to
glib_utils.h.
BUG=chromium:499886
TEST=emerge-link update_engine
Change-Id: Ia727cf3d4ee29fb33fa4db500ca83ea37d23a335
Reviewed-on: https://chromium-review.googlesource.com/281446
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
diff --git a/glib_utils.h b/glib_utils.h
index 0c941ca..97020cb 100644
--- a/glib_utils.h
+++ b/glib_utils.h
@@ -6,6 +6,7 @@
#define UPDATE_ENGINE_GLIB_UTILS_H_
#include <string>
+#include <vector>
#include <glib.h>
@@ -16,6 +17,29 @@
// object and resets error to null.
std::string GetAndFreeGError(GError** error);
+// Converts a vector of strings to a NUL-terminated array of
+// strings. The resulting array should be freed with g_strfreev()
+// when are you done with it.
+gchar** StringVectorToGStrv(const std::vector<std::string>& vec_str);
+
+// A base::FreeDeleter that frees memory using g_free(). Useful when
+// integrating with GLib since it can be used with std::unique_ptr to
+// automatically free memory when going out of scope.
+struct GLibFreeDeleter {
+ inline void operator()(void* ptr) const {
+ g_free(static_cast<gpointer>(ptr));
+ }
+};
+
+// A base::FreeDeleter that frees memory using g_strfreev(). Useful
+// when integrating with GLib since it can be used with std::unique_ptr to
+// automatically free memory when going out of scope.
+struct GLibStrvFreeDeleter {
+ inline void operator()(void* ptr) const {
+ g_strfreev(static_cast<gchar**>(ptr));
+ }
+};
+
} // namespace utils
} // namespace chromeos_update_engine