gio: don't quote quark names for G_DEFINE_QUARK
[platform/upstream/glib.git] / gio / gioerror.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include "config.h"
24 #include <errno.h>
25 #include "gioerror.h"
26
27
28 /**
29  * SECTION:gioerror
30  * @short_description: Error helper functions
31  * @include: gio/gio.h
32  *
33  * Contains helper functions for reporting errors to the user.
34  **/
35
36 /**
37  * g_io_error_quark:
38  *
39  * Gets the GIO Error Quark.
40  *
41  * Return value: a #GQuark.
42  **/
43 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
44
45 /**
46  * g_io_error_from_errno:
47  * @err_no: Error number as defined in errno.h.
48  *
49  * Converts errno.h error codes into GIO error codes.
50  *
51  * Returns: #GIOErrorEnum value for the given errno.h error number.
52  **/
53 GIOErrorEnum
54 g_io_error_from_errno (gint err_no)
55 {
56   switch (err_no)
57     {
58 #ifdef EEXIST
59     case EEXIST:
60       return G_IO_ERROR_EXISTS;
61       break;
62 #endif
63
64 #ifdef EISDIR
65     case EISDIR:
66       return G_IO_ERROR_IS_DIRECTORY;
67       break;
68 #endif
69
70 #ifdef EACCES
71     case EACCES:
72       return G_IO_ERROR_PERMISSION_DENIED;
73       break;
74 #endif
75
76 #ifdef ENAMETOOLONG
77     case ENAMETOOLONG:
78       return G_IO_ERROR_FILENAME_TOO_LONG;
79       break;
80 #endif
81
82 #ifdef ENOENT
83     case ENOENT:
84       return G_IO_ERROR_NOT_FOUND;
85       break;
86 #endif
87
88 #ifdef ENOTDIR
89     case ENOTDIR:
90       return G_IO_ERROR_NOT_DIRECTORY;
91       break;
92 #endif
93
94 #ifdef EROFS
95     case EROFS:
96       return G_IO_ERROR_READ_ONLY;
97       break;
98 #endif
99
100 #ifdef ELOOP
101     case ELOOP:
102       return G_IO_ERROR_TOO_MANY_LINKS;
103       break;
104 #endif
105
106 #ifdef ENOSPC
107     case ENOSPC:
108       return G_IO_ERROR_NO_SPACE;
109       break;
110 #endif
111
112 #ifdef ENOMEM
113     case ENOMEM:
114       return G_IO_ERROR_NO_SPACE;
115       break;
116 #endif
117       
118 #ifdef EINVAL
119     case EINVAL:
120       return G_IO_ERROR_INVALID_ARGUMENT;
121       break;
122 #endif
123
124 #ifdef EPERM
125     case EPERM:
126       return G_IO_ERROR_PERMISSION_DENIED;
127       break;
128 #endif
129
130 #ifdef ECANCELED
131     case ECANCELED:
132       return G_IO_ERROR_CANCELLED;
133       break;
134 #endif
135
136 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
137     case ENOTEMPTY:
138       return G_IO_ERROR_NOT_EMPTY;
139       break;
140 #endif
141
142 #ifdef ENOTSUP
143     case ENOTSUP:
144       return G_IO_ERROR_NOT_SUPPORTED;
145       break;
146 #endif
147
148 #ifdef ETIMEDOUT
149     case ETIMEDOUT:
150       return G_IO_ERROR_TIMED_OUT;
151       break;
152 #endif
153
154 #ifdef EBUSY
155     case EBUSY:
156       return G_IO_ERROR_BUSY;
157       break;
158 #endif
159
160 /* some magic to deal with EWOULDBLOCK and EAGAIN.
161  * apparently on HP-UX these are actually defined to different values,
162  * but on Linux, for example, they are the same.
163  */
164 #if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK == EAGAIN
165     /* we have both and they are the same: only emit one case. */
166     case EAGAIN:
167       return G_IO_ERROR_WOULD_BLOCK;
168       break;
169 #else
170     /* else: consider each of them separately.  this handles both the
171      * case of having only one and the case where they are different values.
172      */
173 # ifdef EAGAIN
174     case EAGAIN:
175       return G_IO_ERROR_WOULD_BLOCK;
176       break;
177 # endif
178
179 # ifdef EWOULDBLOCK
180     case EWOULDBLOCK:
181       return G_IO_ERROR_WOULD_BLOCK;
182       break;
183 # endif
184 #endif
185
186 #ifdef EMFILE
187     case EMFILE:
188       return G_IO_ERROR_TOO_MANY_OPEN_FILES;
189       break;
190 #endif
191
192 #ifdef EADDRINUSE
193     case EADDRINUSE:
194       return G_IO_ERROR_ADDRESS_IN_USE;
195       break;
196 #endif
197
198 #ifdef EHOSTUNREACH
199     case EHOSTUNREACH:
200       return G_IO_ERROR_HOST_UNREACHABLE;
201       break;
202 #endif
203
204 #ifdef ENETUNREACH
205     case ENETUNREACH:
206       return G_IO_ERROR_NETWORK_UNREACHABLE;
207       break;
208 #endif
209
210 #ifdef ECONNREFUSED
211     case ECONNREFUSED:
212       return G_IO_ERROR_CONNECTION_REFUSED;
213       break;
214 #endif
215
216     default:
217       return G_IO_ERROR_FAILED;
218       break;
219     }
220 }
221
222 #ifdef G_OS_WIN32
223
224 /**
225  * g_io_error_from_win32_error:
226  * @error_code: Windows error number.
227  *
228  * Converts some common error codes into GIO error codes. The
229  * fallback value G_IO_ERROR_FAILED is returned for error codes not
230  * handled.
231  *
232  * Returns: #GIOErrorEnum value for the given error number.
233  *
234  * Since: 2.26
235  **/
236 GIOErrorEnum
237 g_io_error_from_win32_error (gint error_code)
238 {
239   switch (error_code)
240     {
241     default:
242       return G_IO_ERROR_FAILED;
243       break;
244     }
245 }
246
247 #endif