~ubuntu-branches/ubuntu/oneiric/gconf/oneiric-proposed

« back to all changes in this revision

Viewing changes to gconf/gconf-glib.c

  • Committer: Bazaar Package Importer
  • Author(s): Takuo KITAME
  • Date: 2002-03-17 01:51:39 UTC
  • Revision ID: james.westby@ubuntu.com-20020317015139-z4f8fdg1hoe049g0
Tags: upstream-1.0.9
ImportĀ upstreamĀ versionĀ 1.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GConf
 
2
 * Copyright (C) 1999, 2000 Red Hat Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "gconf-glib-public.h"
 
21
#include "gconf-glib-private.h"
 
22
#include <string.h>
 
23
 
 
24
static GError* 
 
25
g_error_new_valist(GQuark         domain,
 
26
                   gint           code,
 
27
                   const gchar   *format,
 
28
                   va_list        args)
 
29
{
 
30
  GError *error;
 
31
  
 
32
  error = g_new (GError, 1);
 
33
  
 
34
  error->domain = domain;
 
35
  error->code = code;
 
36
  error->message = g_strdup_vprintf (format, args);
 
37
  
 
38
  return error;
 
39
}
 
40
 
 
41
GError*
 
42
g_error_new (GQuark       domain,
 
43
             gint         code,
 
44
             const gchar *format,
 
45
             ...)
 
46
{
 
47
  GError* error;
 
48
  va_list args;
 
49
 
 
50
  g_return_val_if_fail (format != NULL, NULL);
 
51
  g_return_val_if_fail (domain != 0, NULL);
 
52
 
 
53
  va_start (args, format);
 
54
  error = g_error_new_valist (domain, code, format, args);
 
55
  va_end (args);
 
56
 
 
57
  return error;
 
58
}
 
59
 
 
60
GError*
 
61
g_error_new_literal (GQuark         domain,
 
62
                     gint           code,
 
63
                     const gchar   *message)
 
64
{
 
65
  GError* err;
 
66
 
 
67
  g_return_val_if_fail (message != NULL, NULL);
 
68
  g_return_val_if_fail (domain != 0, NULL);
 
69
 
 
70
  err = g_new (GError, 1);
 
71
 
 
72
  err->domain = domain;
 
73
  err->code = code;
 
74
  err->message = g_strdup (message);
 
75
  
 
76
  return err;
 
77
}
 
78
 
 
79
void
 
80
g_error_free (GError *error)
 
81
{
 
82
  g_return_if_fail (error != NULL);  
 
83
 
 
84
  g_free (error->message);
 
85
 
 
86
  g_free (error);
 
87
}
 
88
 
 
89
GError*
 
90
g_error_copy (const GError *error)
 
91
{
 
92
  GError *copy;
 
93
  
 
94
  g_return_val_if_fail (error != NULL, NULL);
 
95
 
 
96
  copy = g_new (GError, 1);
 
97
 
 
98
  *copy = *error;
 
99
 
 
100
  copy->message = g_strdup (error->message);
 
101
 
 
102
  return copy;
 
103
}
 
104
 
 
105
gboolean
 
106
g_error_matches (const GError *error,
 
107
                 GQuark        domain,
 
108
                 gint          code)
 
109
{
 
110
  return error &&
 
111
    error->domain == domain &&
 
112
    error->code == code;
 
113
}
 
114
 
 
115
void
 
116
g_set_error (GError     **err,
 
117
             GQuark       domain,
 
118
             gint         code,
 
119
             const gchar *format,
 
120
             ...)
 
121
{
 
122
  va_list args;
 
123
 
 
124
  if (err == NULL)
 
125
    return;
 
126
 
 
127
  if (*err != NULL)
 
128
    g_warning ("GError set over the top of a previous GError or uninitialized memory.\n"
 
129
               "This indicates a bug in someone's code. You must ensure an error is NULL before it's set.");
 
130
  
 
131
  va_start (args, format);
 
132
  *err = g_error_new_valist (domain, code, format, args);
 
133
  va_end (args);
 
134
}
 
135
 
 
136
#define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
 
137
               "This indicates a bug in someone's code. You must ensure an error is NULL before it's set."
 
138
 
 
139
/**
 
140
 * g_propagate_error:
 
141
 * @dest: error return location
 
142
 * @src: error to move into the return location
 
143
 * 
 
144
 * If @dest is NULL, free @src; otherwise,
 
145
 * moves @src into *@dest. *@dest must be NULL.
 
146
 **/
 
147
void    
 
148
g_propagate_error (GError       **dest,
 
149
                   GError        *src)
 
150
{
 
151
  g_return_if_fail (src != NULL);
 
152
  
 
153
  if (dest == NULL)
 
154
    {
 
155
      if (src)
 
156
        g_error_free (src);
 
157
      return;
 
158
    }
 
159
  else
 
160
    {
 
161
      if (*dest != NULL)
 
162
        g_warning (ERROR_OVERWRITTEN_WARNING);
 
163
      
 
164
      *dest = src;
 
165
    }
 
166
}
 
167
 
 
168
void
 
169
g_clear_error (GError **err)
 
170
{
 
171
  if (err && *err)
 
172
    {
 
173
      g_error_free (*err);
 
174
      *err = NULL;
 
175
    }
 
176
}