1 /* GIO - GLib Input, Output and Streaming Library
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, see <http://www.gnu.org/licenses/>.
18 * Author: Alexander Larsson <alexl@redhat.com>
31 * @short_description: Error helper functions
34 * Contains helper functions for reporting errors to the user.
40 * Gets the GIO Error Quark.
44 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
47 * g_io_error_from_errno:
48 * @err_no: Error number as defined in errno.h.
50 * Converts errno.h error codes into GIO error codes. The fallback
51 * value %G_IO_ERROR_FAILED is returned for error codes not currently
52 * handled (but note that future GLib releases may return a more
53 * specific value instead).
55 * Returns: #GIOErrorEnum value for the given errno.h error number.
58 g_io_error_from_errno (gint err_no)
64 return G_IO_ERROR_EXISTS;
70 return G_IO_ERROR_IS_DIRECTORY;
76 return G_IO_ERROR_PERMISSION_DENIED;
82 return G_IO_ERROR_FILENAME_TOO_LONG;
88 return G_IO_ERROR_NOT_FOUND;
94 return G_IO_ERROR_NOT_DIRECTORY;
100 return G_IO_ERROR_READ_ONLY;
106 return G_IO_ERROR_TOO_MANY_LINKS;
112 return G_IO_ERROR_NO_SPACE;
118 return G_IO_ERROR_NO_SPACE;
124 return G_IO_ERROR_INVALID_ARGUMENT;
130 return G_IO_ERROR_PERMISSION_DENIED;
136 return G_IO_ERROR_CANCELLED;
140 /* ENOTEMPTY == EEXIST on AIX for backward compatibility reasons */
141 #if defined (ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
143 return G_IO_ERROR_NOT_EMPTY;
149 return G_IO_ERROR_NOT_SUPPORTED;
153 /* EOPNOTSUPP == ENOTSUP on Linux, but POSIX considers them distinct */
154 #if defined (EOPNOTSUPP) && (!defined (ENOTSUP) || (EOPNOTSUPP != ENOTSUP))
156 return G_IO_ERROR_NOT_SUPPORTED;
160 #ifdef EPROTONOSUPPORT
161 case EPROTONOSUPPORT:
162 return G_IO_ERROR_NOT_SUPPORTED;
166 #ifdef ESOCKTNOSUPPORT
167 case ESOCKTNOSUPPORT:
168 return G_IO_ERROR_NOT_SUPPORTED;
174 return G_IO_ERROR_NOT_SUPPORTED;
180 return G_IO_ERROR_NOT_SUPPORTED;
186 return G_IO_ERROR_TIMED_OUT;
192 return G_IO_ERROR_BUSY;
198 return G_IO_ERROR_WOULD_BLOCK;
202 /* EWOULDBLOCK == EAGAIN on most systems, but POSIX considers them distinct */
203 #if defined (EAGAIN) && (!defined (EWOULDBLOCK) || (EWOULDBLOCK != EAGAIN))
205 return G_IO_ERROR_WOULD_BLOCK;
211 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
217 return G_IO_ERROR_ADDRESS_IN_USE;
223 return G_IO_ERROR_HOST_UNREACHABLE;
229 return G_IO_ERROR_NETWORK_UNREACHABLE;
235 return G_IO_ERROR_CONNECTION_REFUSED;
241 return G_IO_ERROR_BROKEN_PIPE;
246 return G_IO_ERROR_FAILED;
254 * g_io_error_from_win32_error:
255 * @error_code: Windows error number.
257 * Converts some common error codes (as returned from GetLastError()
258 * or WSAGetLastError()) into GIO error codes. The fallback value
259 * %G_IO_ERROR_FAILED is returned for error codes not currently
260 * handled (but note that future GLib releases may return a more
261 * specific value instead).
263 * You can use g_win32_error_message() to get a localized string
264 * corresponding to @error_code. (But note that unlike g_strerror(),
265 * g_win32_error_message() returns a string that must be freed.)
267 * Returns: #GIOErrorEnum value for the given error number.
272 g_io_error_from_win32_error (gint error_code)
274 /* Note: Winsock errors are a subset of Win32 error codes as a
275 * whole. (The fact that the Winsock API makes them look like they
276 * aren't is just because the API predates Win32.)
282 return G_IO_ERROR_ADDRESS_IN_USE;
285 return G_IO_ERROR_WOULD_BLOCK;
288 return G_IO_ERROR_PERMISSION_DENIED;
290 case WSA_INVALID_HANDLE:
291 case WSA_INVALID_PARAMETER:
294 return G_IO_ERROR_INVALID_ARGUMENT;
296 case WSAEPROTONOSUPPORT:
297 return G_IO_ERROR_NOT_SUPPORTED;
300 return G_IO_ERROR_CANCELLED;
302 case WSAESOCKTNOSUPPORT:
304 case WSAEPFNOSUPPORT:
305 case WSAEAFNOSUPPORT:
306 return G_IO_ERROR_NOT_SUPPORTED;
309 return G_IO_ERROR_FAILED;