Move markup collect tests to the test framework
[glib.git] / gio / gioerror.c
blob9bd4004550ec56fa62d7efae7836ac219286f1e5
1 /* GIO - GLib Input, Output and Streaming Library
2 *
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>
23 #include "config.h"
24 #include <errno.h>
25 #include "gioerror.h"
28 /**
29 * SECTION:gioerror
30 * @short_description: Error helper functions
31 * @include: gio/gio.h
33 * Contains helper functions for reporting errors to the user.
34 **/
36 /**
37 * g_io_error_quark:
39 * Gets the GIO Error Quark.
41 * Return value: a #GQuark.
42 **/
43 GQuark
44 g_io_error_quark (void)
46 return g_quark_from_static_string ("g-io-error-quark");
49 /**
50 * g_io_error_from_errno:
51 * @err_no: Error number as defined in errno.h.
53 * Converts errno.h error codes into GIO error codes.
55 * Returns: #GIOErrorEnum value for the given errno.h error number.
56 **/
57 GIOErrorEnum
58 g_io_error_from_errno (gint err_no)
60 switch (err_no)
62 #ifdef EEXIST
63 case EEXIST:
64 return G_IO_ERROR_EXISTS;
65 break;
66 #endif
68 #ifdef EISDIR
69 case EISDIR:
70 return G_IO_ERROR_IS_DIRECTORY;
71 break;
72 #endif
74 #ifdef EACCES
75 case EACCES:
76 return G_IO_ERROR_PERMISSION_DENIED;
77 break;
78 #endif
80 #ifdef ENAMETOOLONG
81 case ENAMETOOLONG:
82 return G_IO_ERROR_FILENAME_TOO_LONG;
83 break;
84 #endif
86 #ifdef ENOENT
87 case ENOENT:
88 return G_IO_ERROR_NOT_FOUND;
89 break;
90 #endif
92 #ifdef ENOTDIR
93 case ENOTDIR:
94 return G_IO_ERROR_NOT_DIRECTORY;
95 break;
96 #endif
98 #ifdef EROFS
99 case EROFS:
100 return G_IO_ERROR_READ_ONLY;
101 break;
102 #endif
104 #ifdef ELOOP
105 case ELOOP:
106 return G_IO_ERROR_TOO_MANY_LINKS;
107 break;
108 #endif
110 #ifdef ENOSPC
111 case ENOSPC:
112 return G_IO_ERROR_NO_SPACE;
113 break;
114 #endif
116 #ifdef ENOMEM
117 case ENOMEM:
118 return G_IO_ERROR_NO_SPACE;
119 break;
120 #endif
122 #ifdef EINVAL
123 case EINVAL:
124 return G_IO_ERROR_INVALID_ARGUMENT;
125 break;
126 #endif
128 #ifdef EPERM
129 case EPERM:
130 return G_IO_ERROR_PERMISSION_DENIED;
131 break;
132 #endif
134 #ifdef ECANCELED
135 case ECANCELED:
136 return G_IO_ERROR_CANCELLED;
137 break;
138 #endif
140 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
141 case ENOTEMPTY:
142 return G_IO_ERROR_NOT_EMPTY;
143 break;
144 #endif
146 #ifdef ENOTSUP
147 case ENOTSUP:
148 return G_IO_ERROR_NOT_SUPPORTED;
149 break;
150 #endif
152 #ifdef ETIMEDOUT
153 case ETIMEDOUT:
154 return G_IO_ERROR_TIMED_OUT;
155 break;
156 #endif
158 #ifdef EBUSY
159 case EBUSY:
160 return G_IO_ERROR_BUSY;
161 break;
162 #endif
164 /* some magic to deal with EWOULDBLOCK and EAGAIN.
165 * apparently on HP-UX these are actually defined to different values,
166 * but on Linux, for example, they are the same.
168 #if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK == EAGAIN
169 /* we have both and they are the same: only emit one case. */
170 case EAGAIN:
171 return G_IO_ERROR_WOULD_BLOCK;
172 break;
173 #else
174 /* else: consider each of them separately. this handles both the
175 * case of having only one and the case where they are different values.
177 # ifdef EAGAIN
178 case EAGAIN:
179 return G_IO_ERROR_WOULD_BLOCK;
180 break;
181 # endif
183 # ifdef EWOULDBLOCK
184 case EWOULDBLOCK:
185 return G_IO_ERROR_WOULD_BLOCK;
186 break;
187 # endif
188 #endif
190 #ifdef EMFILE
191 case EMFILE:
192 return G_IO_ERROR_TOO_MANY_OPEN_FILES;
193 break;
194 #endif
196 #ifdef EADDRINUSE
197 case EADDRINUSE:
198 return G_IO_ERROR_ADDRESS_IN_USE;
199 break;
200 #endif
202 default:
203 return G_IO_ERROR_FAILED;
204 break;
208 #ifdef G_OS_WIN32
211 * g_io_error_from_win32_error:
212 * @error_code: Windows error number.
214 * Converts some common error codes into GIO error codes. The
215 * fallback value G_IO_ERROR_FAILED is returned for error codes not
216 * handled.
218 * Returns: #GIOErrorEnum value for the given error number.
220 * Since: 2.26
222 GIOErrorEnum
223 g_io_error_from_win32_error (gint error_code)
225 switch (error_code)
227 default:
228 return G_IO_ERROR_FAILED;
229 break;
233 #endif