Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 1 | // 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 | |
| 9 | using std::string; |
| 10 | |
| 11 | namespace chromeos_update_engine { |
| 12 | namespace utils { |
| 13 | |
| 14 | string 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 Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 23 | *error = nullptr; |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 24 | return message; |
| 25 | } |
| 26 | |
Alex Deymo | 8d2bbe3 | 2015-06-23 16:28:59 -0700 | [diff] [blame] | 27 | gchar** 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 Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 36 | } // namespace utils |
| 37 | } // namespace chromeos_update_engine |