blob: 625d8d1c9c4dc76a9629097e5ee95d13c1db4cb8 [file] [log] [blame]
Alex Deymo44666f92014-07-22 20:29:24 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/glib_utils.h"
6
7#include <base/strings/stringprintf.h>
8
9using std::string;
10
11namespace chromeos_update_engine {
12namespace utils {
13
14string GetAndFreeGError(GError** error) {
15 if (!*error) {
16 return "Unknown GLib error.";
17 }
18 string message =
19 base::StringPrintf("GError(%d): %s",
20 (*error)->code,
21 (*error)->message ? (*error)->message : "(unknown)");
22 g_error_free(*error);
Alex Vakulenko88b591f2014-08-28 16:48:57 -070023 *error = nullptr;
Alex Deymo44666f92014-07-22 20:29:24 -070024 return message;
25}
26
Alex Deymo8d2bbe32015-06-23 16:28:59 -070027gchar** StringVectorToGStrv(const std::vector<string> &vec_str) {
28 GPtrArray *p = g_ptr_array_new();
29 for (const string& str : vec_str) {
30 g_ptr_array_add(p, g_strdup(str.c_str()));
31 }
32 g_ptr_array_add(p, nullptr);
33 return reinterpret_cast<gchar**>(g_ptr_array_free(p, FALSE));
34}
35
Alex Deymo44666f92014-07-22 20:29:24 -070036} // namespace utils
37} // namespace chromeos_update_engine