gioerror: map some more values to G_IO_ERROR_NOT_SUPPORTED
[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, see <http://www.gnu.org/licenses/>.
17  *
18  * Author: Alexander Larsson <alexl@redhat.com>
19  */
20
21 #include "config.h"
22 #include <errno.h>
23 #include "gioerror.h"
24
25
26 /**
27  * SECTION:gioerror
28  * @short_description: Error helper functions
29  * @include: gio/gio.h
30  *
31  * Contains helper functions for reporting errors to the user.
32  **/
33
34 /**
35  * g_io_error_quark:
36  *
37  * Gets the GIO Error Quark.
38  *
39  * Returns: a #GQuark.
40  **/
41 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
42
43 /**
44  * g_io_error_from_errno:
45  * @err_no: Error number as defined in errno.h.
46  *
47  * Converts errno.h error codes into GIO error codes. The fallback
48  * value %G_IO_ERROR_FAILED is returned for error codes not currently
49  * handled (but note that future GLib releases may return a more
50  * specific value instead).
51  *
52  * Returns: #GIOErrorEnum value for the given errno.h error number.
53  **/
54 GIOErrorEnum
55 g_io_error_from_errno (gint err_no)
56 {
57   switch (err_no)
58     {
59 #ifdef EEXIST
60     case EEXIST:
61       return G_IO_ERROR_EXISTS;
62       break;
63 #endif
64
65 #ifdef EISDIR
66     case EISDIR:
67       return G_IO_ERROR_IS_DIRECTORY;
68       break;
69 #endif
70
71 #ifdef EACCES
72     case EACCES:
73       return G_IO_ERROR_PERMISSION_DENIED;
74       break;
75 #endif
76
77 #ifdef ENAMETOOLONG
78     case ENAMETOOLONG:
79       return G_IO_ERROR_FILENAME_TOO_LONG;
80       break;
81 #endif
82
83 #ifdef ENOENT
84     case ENOENT:
85       return G_IO_ERROR_NOT_FOUND;
86       break;
87 #endif
88
89 #ifdef ENOTDIR
90     case ENOTDIR:
91       return G_IO_ERROR_NOT_DIRECTORY;
92       break;
93 #endif
94
95 #ifdef EROFS
96     case EROFS:
97       return G_IO_ERROR_READ_ONLY;
98       break;
99 #endif
100
101 #ifdef ELOOP
102     case ELOOP:
103       return G_IO_ERROR_TOO_MANY_LINKS;
104       break;
105 #endif
106
107 #ifdef ENOSPC
108     case ENOSPC:
109       return G_IO_ERROR_NO_SPACE;
110       break;
111 #endif
112
113 #ifdef ENOMEM
114     case ENOMEM:
115       return G_IO_ERROR_NO_SPACE;
116       break;
117 #endif
118       
119 #ifdef EINVAL
120     case EINVAL:
121       return G_IO_ERROR_INVALID_ARGUMENT;
122       break;
123 #endif
124
125 #ifdef EPERM
126     case EPERM:
127       return G_IO_ERROR_PERMISSION_DENIED;
128       break;
129 #endif
130
131 #ifdef ECANCELED
132     case ECANCELED:
133       return G_IO_ERROR_CANCELLED;
134       break;
135 #endif
136
137     /* ENOTEMPTY == EEXIST on AIX for backward compatibility reasons */
138 #if defined (ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
139     case ENOTEMPTY:
140       return G_IO_ERROR_NOT_EMPTY;
141       break;
142 #endif
143
144 #ifdef ENOTSUP
145     case ENOTSUP:
146       return G_IO_ERROR_NOT_SUPPORTED;
147       break;
148 #endif
149
150     /* EOPNOTSUPP == ENOTSUP on Linux, but POSIX considers them distinct */
151 #if defined (EOPNOTSUPP) && (!defined (ENOTSUP) || (EOPNOTSUPP != ENOTSUP))
152     case EOPNOTSUPP:
153       return G_IO_ERROR_NOT_SUPPORTED;
154       break;
155 #endif
156
157 #ifdef EPROTONOSUPPORT
158     case EPROTONOSUPPORT:
159       return G_IO_ERROR_NOT_SUPPORTED;
160       break;
161 #endif
162
163 #ifdef ESOCKTNOSUPPORT
164     case ESOCKTNOSUPPORT:
165       return G_IO_ERROR_NOT_SUPPORTED;
166       break;
167 #endif
168
169 #ifdef EPFNOSUPPORT
170     case EPFNOSUPPORT:
171       return G_IO_ERROR_NOT_SUPPORTED;
172       break;
173 #endif
174
175 #ifdef EAFNOSUPPORT
176     case EAFNOSUPPORT:
177       return G_IO_ERROR_NOT_SUPPORTED;
178       break;
179 #endif
180
181 #ifdef ETIMEDOUT
182     case ETIMEDOUT:
183       return G_IO_ERROR_TIMED_OUT;
184       break;
185 #endif
186
187 #ifdef EBUSY
188     case EBUSY:
189       return G_IO_ERROR_BUSY;
190       break;
191 #endif
192
193 #ifdef EWOULDBLOCK
194     case EWOULDBLOCK:
195       return G_IO_ERROR_WOULD_BLOCK;
196       break;
197 #endif
198
199     /* EWOULDBLOCK == EAGAIN on most systems, but POSIX considers them distinct */
200 #if defined (EAGAIN) && (!defined (EWOULDBLOCK) || (EWOULDBLOCK != EAGAIN))
201     case EAGAIN:
202       return G_IO_ERROR_WOULD_BLOCK;
203       break;
204 #endif
205
206 #ifdef EMFILE
207     case EMFILE:
208       return G_IO_ERROR_TOO_MANY_OPEN_FILES;
209       break;
210 #endif
211
212 #ifdef EADDRINUSE
213     case EADDRINUSE:
214       return G_IO_ERROR_ADDRESS_IN_USE;
215       break;
216 #endif
217
218 #ifdef EHOSTUNREACH
219     case EHOSTUNREACH:
220       return G_IO_ERROR_HOST_UNREACHABLE;
221       break;
222 #endif
223
224 #ifdef ENETUNREACH
225     case ENETUNREACH:
226       return G_IO_ERROR_NETWORK_UNREACHABLE;
227       break;
228 #endif
229
230 #ifdef ECONNREFUSED
231     case ECONNREFUSED:
232       return G_IO_ERROR_CONNECTION_REFUSED;
233       break;
234 #endif
235
236 #ifdef EPIPE
237     case EPIPE:
238       return G_IO_ERROR_BROKEN_PIPE;
239       break;
240 #endif
241
242     default:
243       return G_IO_ERROR_FAILED;
244       break;
245     }
246 }
247
248 #ifdef G_OS_WIN32
249
250 /**
251  * g_io_error_from_win32_error:
252  * @error_code: Windows error number.
253  *
254  * Converts some common error codes into GIO error codes. The fallback
255  * value %G_IO_ERROR_FAILED is returned for error codes not currently
256  * handled (but note that future GLib releases may return a more
257  * specific value instead).
258  *
259  * Returns: #GIOErrorEnum value for the given error number.
260  *
261  * Since: 2.26
262  **/
263 GIOErrorEnum
264 g_io_error_from_win32_error (gint error_code)
265 {
266   switch (error_code)
267     {
268     default:
269       return G_IO_ERROR_FAILED;
270       break;
271     }
272 }
273
274 #endif