1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2008 Kouhei Sutou <kou@cozmixng.org>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif /* HAVE_CONFIG_H */
23
24 #include "gcut-error.h"
25
26 gboolean
gcut_error_equal(const GError * error1,const GError * error2)27 gcut_error_equal (const GError *error1, const GError *error2)
28 {
29 if (error1 == error2)
30 return TRUE;
31
32 if (error1 == NULL || error2 == NULL)
33 return FALSE;
34
35 if (error1->domain != error2->domain)
36 return FALSE;
37
38 if (error1->code != error2->code)
39 return FALSE;
40
41 if (error1->message == NULL && error2->message == NULL)
42 return TRUE;
43
44 if (error1->message == NULL || error2->message == NULL)
45 return FALSE;
46
47 return g_str_equal(error1->message, error2->message);
48 }
49
50 gchar *
gcut_error_inspect(const GError * error)51 gcut_error_inspect (const GError *error)
52 {
53 GString *inspected;
54
55 if (!error)
56 return g_strdup("No error");
57
58 inspected = g_string_new(g_quark_to_string(error->domain));
59 g_string_append_printf(inspected, ":%d", error->code);
60 if (error->message) {
61 g_string_append(inspected, ": ");
62 g_string_append(inspected, error->message);
63 }
64
65 return g_string_free(inspected, FALSE);
66 }
67
68 /*
69 vi:ts=4:nowrap:ai:expandtab:sw=4
70 */
71