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 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
139 return G_IO_ERROR_NOT_EMPTY;
145 return G_IO_ERROR_NOT_SUPPORTED;
151 return G_IO_ERROR_TIMED_OUT;
157 return G_IO_ERROR_BUSY;
161 /* some magic to deal with EWOULDBLOCK and EAGAIN.
162 * apparently on HP-UX these are actually defined to different values,
163 * but on Linux, for example, they are the same.
165 #if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK == EAGAIN
166 /* we have both and they are the same: only emit one case. */
168 return G_IO_ERROR_WOULD_BLOCK;
171 /* else: consider each of them separately. this handles both the
172 * case of having only one and the case where they are different values.
176 return G_IO_ERROR_WOULD_BLOCK;
182 return G_IO_ERROR_WOULD_BLOCK;
189 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
195 return G_IO_ERROR_ADDRESS_IN_USE;
201 return G_IO_ERROR_HOST_UNREACHABLE;
207 return G_IO_ERROR_NETWORK_UNREACHABLE;
213 return G_IO_ERROR_CONNECTION_REFUSED;
219 return G_IO_ERROR_BROKEN_PIPE;
224 return G_IO_ERROR_FAILED;
232 * g_io_error_from_win32_error:
233 * @error_code: Windows error number.
235 * Converts some common error codes into GIO error codes. The fallback
236 * value %G_IO_ERROR_FAILED is returned for error codes not currently
237 * handled (but note that future GLib releases may return a more
238 * specific value instead).
240 * Returns: #GIOErrorEnum value for the given error number.
245 g_io_error_from_win32_error (gint error_code)
250 return G_IO_ERROR_FAILED;