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, 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>
30 * @short_description: Error helper functions
33 * Contains helper functions for reporting errors to the user.
39 * Gets the GIO Error Quark.
41 * Return value: a #GQuark.
43 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
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.
54 g_io_error_from_errno (gint err_no)
60 return G_IO_ERROR_EXISTS;
66 return G_IO_ERROR_IS_DIRECTORY;
72 return G_IO_ERROR_PERMISSION_DENIED;
78 return G_IO_ERROR_FILENAME_TOO_LONG;
84 return G_IO_ERROR_NOT_FOUND;
90 return G_IO_ERROR_NOT_DIRECTORY;
96 return G_IO_ERROR_READ_ONLY;
102 return G_IO_ERROR_TOO_MANY_LINKS;
108 return G_IO_ERROR_NO_SPACE;
114 return G_IO_ERROR_NO_SPACE;
120 return G_IO_ERROR_INVALID_ARGUMENT;
126 return G_IO_ERROR_PERMISSION_DENIED;
132 return G_IO_ERROR_CANCELLED;
136 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
138 return G_IO_ERROR_NOT_EMPTY;
144 return G_IO_ERROR_NOT_SUPPORTED;
150 return G_IO_ERROR_TIMED_OUT;
156 return G_IO_ERROR_BUSY;
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. */
167 return G_IO_ERROR_WOULD_BLOCK;
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.
175 return G_IO_ERROR_WOULD_BLOCK;
181 return G_IO_ERROR_WOULD_BLOCK;
188 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
194 return G_IO_ERROR_ADDRESS_IN_USE;
200 return G_IO_ERROR_HOST_UNREACHABLE;
206 return G_IO_ERROR_NETWORK_UNREACHABLE;
212 return G_IO_ERROR_CONNECTION_REFUSED;
218 return G_IO_ERROR_BROKEN_PIPE;
223 return G_IO_ERROR_FAILED;
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
238 * Returns: #GIOErrorEnum value for the given error number.
243 g_io_error_from_win32_error (gint error_code)
248 return G_IO_ERROR_FAILED;