GIcon: add g_icon_[de]serialize()
[glib.git] / gio / gioerror.c
blob3a7785fd75bc16ce43d59b8cf2216a58481d93dd
1 /* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2006-2007 Red Hat, Inc.
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.
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.
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.
20 * Author: Alexander Larsson <alexl@redhat.com>
23 #include "config.h"
24 #include <errno.h>
25 #include "gioerror.h"
28 /**
29 * SECTION:gioerror
30 * @short_description: Error helper functions
31 * @include: gio/gio.h
33 * Contains helper functions for reporting errors to the user.
34 **/
36 /**
37 * g_io_error_quark:
39 * Gets the GIO Error Quark.
41 * Return value: a #GQuark.
42 **/
43 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
45 /**
46 * g_io_error_from_errno:
47 * @err_no: Error number as defined in errno.h.
49 * Converts errno.h error codes into GIO error codes.
51 * Returns: #GIOErrorEnum value for the given errno.h error number.
52 **/
53 GIOErrorEnum
54 g_io_error_from_errno (gint err_no)
56 switch (err_no)
58 #ifdef EEXIST
59 case EEXIST:
60 return G_IO_ERROR_EXISTS;
61 break;
62 #endif
64 #ifdef EISDIR
65 case EISDIR:
66 return G_IO_ERROR_IS_DIRECTORY;
67 break;
68 #endif
70 #ifdef EACCES
71 case EACCES:
72 return G_IO_ERROR_PERMISSION_DENIED;
73 break;
74 #endif
76 #ifdef ENAMETOOLONG
77 case ENAMETOOLONG:
78 return G_IO_ERROR_FILENAME_TOO_LONG;
79 break;
80 #endif
82 #ifdef ENOENT
83 case ENOENT:
84 return G_IO_ERROR_NOT_FOUND;
85 break;
86 #endif
88 #ifdef ENOTDIR
89 case ENOTDIR:
90 return G_IO_ERROR_NOT_DIRECTORY;
91 break;
92 #endif
94 #ifdef EROFS
95 case EROFS:
96 return G_IO_ERROR_READ_ONLY;
97 break;
98 #endif
100 #ifdef ELOOP
101 case ELOOP:
102 return G_IO_ERROR_TOO_MANY_LINKS;
103 break;
104 #endif
106 #ifdef ENOSPC
107 case ENOSPC:
108 return G_IO_ERROR_NO_SPACE;
109 break;
110 #endif
112 #ifdef ENOMEM
113 case ENOMEM:
114 return G_IO_ERROR_NO_SPACE;
115 break;
116 #endif
118 #ifdef EINVAL
119 case EINVAL:
120 return G_IO_ERROR_INVALID_ARGUMENT;
121 break;
122 #endif
124 #ifdef EPERM
125 case EPERM:
126 return G_IO_ERROR_PERMISSION_DENIED;
127 break;
128 #endif
130 #ifdef ECANCELED
131 case ECANCELED:
132 return G_IO_ERROR_CANCELLED;
133 break;
134 #endif
136 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
137 case ENOTEMPTY:
138 return G_IO_ERROR_NOT_EMPTY;
139 break;
140 #endif
142 #ifdef ENOTSUP
143 case ENOTSUP:
144 return G_IO_ERROR_NOT_SUPPORTED;
145 break;
146 #endif
148 #ifdef ETIMEDOUT
149 case ETIMEDOUT:
150 return G_IO_ERROR_TIMED_OUT;
151 break;
152 #endif
154 #ifdef EBUSY
155 case EBUSY:
156 return G_IO_ERROR_BUSY;
157 break;
158 #endif
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.
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.
173 # ifdef EAGAIN
174 case EAGAIN:
175 return G_IO_ERROR_WOULD_BLOCK;
176 break;
177 # endif
179 # ifdef EWOULDBLOCK
180 case EWOULDBLOCK:
181 return G_IO_ERROR_WOULD_BLOCK;
182 break;
183 # endif
184 #endif
186 #ifdef EMFILE
187 case EMFILE:
188 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
189 break;
190 #endif
192 #ifdef EADDRINUSE
193 case EADDRINUSE:
194 return G_IO_ERROR_ADDRESS_IN_USE;
195 break;
196 #endif
198 #ifdef EHOSTUNREACH
199 case EHOSTUNREACH:
200 return G_IO_ERROR_HOST_UNREACHABLE;
201 break;
202 #endif
204 #ifdef ENETUNREACH
205 case ENETUNREACH:
206 return G_IO_ERROR_NETWORK_UNREACHABLE;
207 break;
208 #endif
210 #ifdef ECONNREFUSED
211 case ECONNREFUSED:
212 return G_IO_ERROR_CONNECTION_REFUSED;
213 break;
214 #endif
216 #ifdef EPIPE
217 case EPIPE:
218 return G_IO_ERROR_BROKEN_PIPE;
219 break;
220 #endif
222 default:
223 return G_IO_ERROR_FAILED;
224 break;
228 #ifdef G_OS_WIN32
231 * g_io_error_from_win32_error:
232 * @error_code: Windows error number.
234 * Converts some common error codes into GIO error codes. The
235 * fallback value G_IO_ERROR_FAILED is returned for error codes not
236 * handled.
238 * Returns: #GIOErrorEnum value for the given error number.
240 * Since: 2.26
242 GIOErrorEnum
243 g_io_error_from_win32_error (gint error_code)
245 switch (error_code)
247 default:
248 return G_IO_ERROR_FAILED;
249 break;
253 #endif