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>
28 * @short_description: Error helper functions
31 * Contains helper functions for reporting errors to the user.
37 * Gets the GIO Error Quark.
41 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
44 * g_io_error_from_errno:
45 * @err_no: Error number as defined in errno.h.
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).
52 * Returns: #GIOErrorEnum value for the given errno.h error number.
55 g_io_error_from_errno (gint err_no)
61 return G_IO_ERROR_EXISTS;
67 return G_IO_ERROR_IS_DIRECTORY;
73 return G_IO_ERROR_PERMISSION_DENIED;
79 return G_IO_ERROR_FILENAME_TOO_LONG;
85 return G_IO_ERROR_NOT_FOUND;
91 return G_IO_ERROR_NOT_DIRECTORY;
97 return G_IO_ERROR_READ_ONLY;
103 return G_IO_ERROR_TOO_MANY_LINKS;
109 return G_IO_ERROR_NO_SPACE;
115 return G_IO_ERROR_NO_SPACE;
121 return G_IO_ERROR_INVALID_ARGUMENT;
127 return G_IO_ERROR_PERMISSION_DENIED;
133 return G_IO_ERROR_CANCELLED;
137 /* ENOTEMPTY == EEXIST on AIX for backward compatibility reasons */
138 #if defined (ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
140 return G_IO_ERROR_NOT_EMPTY;
146 return G_IO_ERROR_NOT_SUPPORTED;
150 /* EOPNOTSUPP == ENOTSUP on Linux, but POSIX considers them distinct */
151 #if defined (EOPNOTSUPP) && (!defined (ENOTSUP) || (EOPNOTSUPP != ENOTSUP))
153 return G_IO_ERROR_NOT_SUPPORTED;
157 #ifdef EPROTONOSUPPORT
158 case EPROTONOSUPPORT:
159 return G_IO_ERROR_NOT_SUPPORTED;
163 #ifdef ESOCKTNOSUPPORT
164 case ESOCKTNOSUPPORT:
165 return G_IO_ERROR_NOT_SUPPORTED;
171 return G_IO_ERROR_NOT_SUPPORTED;
177 return G_IO_ERROR_NOT_SUPPORTED;
183 return G_IO_ERROR_TIMED_OUT;
189 return G_IO_ERROR_BUSY;
195 return G_IO_ERROR_WOULD_BLOCK;
199 /* EWOULDBLOCK == EAGAIN on most systems, but POSIX considers them distinct */
200 #if defined (EAGAIN) && (!defined (EWOULDBLOCK) || (EWOULDBLOCK != EAGAIN))
202 return G_IO_ERROR_WOULD_BLOCK;
208 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
214 return G_IO_ERROR_ADDRESS_IN_USE;
220 return G_IO_ERROR_HOST_UNREACHABLE;
226 return G_IO_ERROR_NETWORK_UNREACHABLE;
232 return G_IO_ERROR_CONNECTION_REFUSED;
238 return G_IO_ERROR_BROKEN_PIPE;
243 return G_IO_ERROR_FAILED;
251 * g_io_error_from_win32_error:
252 * @error_code: Windows error number.
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).
259 * Returns: #GIOErrorEnum value for the given error number.
264 g_io_error_from_win32_error (gint error_code)
269 return G_IO_ERROR_FAILED;