docs: use "Returns:" consistently
[platform/upstream/glib.git] / gio / gioerror.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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/>.
17  *
18  * Author: Alexander Larsson <alexl@redhat.com>
19  */
20
21 #include "config.h"
22 #include <errno.h>
23 #include "gioerror.h"
24
25
26 /**
27  * SECTION:gioerror
28  * @short_description: Error helper functions
29  * @include: gio/gio.h
30  *
31  * Contains helper functions for reporting errors to the user.
32  **/
33
34 /**
35  * g_io_error_quark:
36  *
37  * Gets the GIO Error Quark.
38  *
39  * Returns: a #GQuark.
40  **/
41 G_DEFINE_QUARK (g-io-error-quark, g_io_error)
42
43 /**
44  * g_io_error_from_errno:
45  * @err_no: Error number as defined in errno.h.
46  *
47  * Converts errno.h error codes into GIO error codes.
48  *
49  * Returns: #GIOErrorEnum value for the given errno.h error number.
50  **/
51 GIOErrorEnum
52 g_io_error_from_errno (gint err_no)
53 {
54   switch (err_no)
55     {
56 #ifdef EEXIST
57     case EEXIST:
58       return G_IO_ERROR_EXISTS;
59       break;
60 #endif
61
62 #ifdef EISDIR
63     case EISDIR:
64       return G_IO_ERROR_IS_DIRECTORY;
65       break;
66 #endif
67
68 #ifdef EACCES
69     case EACCES:
70       return G_IO_ERROR_PERMISSION_DENIED;
71       break;
72 #endif
73
74 #ifdef ENAMETOOLONG
75     case ENAMETOOLONG:
76       return G_IO_ERROR_FILENAME_TOO_LONG;
77       break;
78 #endif
79
80 #ifdef ENOENT
81     case ENOENT:
82       return G_IO_ERROR_NOT_FOUND;
83       break;
84 #endif
85
86 #ifdef ENOTDIR
87     case ENOTDIR:
88       return G_IO_ERROR_NOT_DIRECTORY;
89       break;
90 #endif
91
92 #ifdef EROFS
93     case EROFS:
94       return G_IO_ERROR_READ_ONLY;
95       break;
96 #endif
97
98 #ifdef ELOOP
99     case ELOOP:
100       return G_IO_ERROR_TOO_MANY_LINKS;
101       break;
102 #endif
103
104 #ifdef ENOSPC
105     case ENOSPC:
106       return G_IO_ERROR_NO_SPACE;
107       break;
108 #endif
109
110 #ifdef ENOMEM
111     case ENOMEM:
112       return G_IO_ERROR_NO_SPACE;
113       break;
114 #endif
115       
116 #ifdef EINVAL
117     case EINVAL:
118       return G_IO_ERROR_INVALID_ARGUMENT;
119       break;
120 #endif
121
122 #ifdef EPERM
123     case EPERM:
124       return G_IO_ERROR_PERMISSION_DENIED;
125       break;
126 #endif
127
128 #ifdef ECANCELED
129     case ECANCELED:
130       return G_IO_ERROR_CANCELLED;
131       break;
132 #endif
133
134 #if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
135     case ENOTEMPTY:
136       return G_IO_ERROR_NOT_EMPTY;
137       break;
138 #endif
139
140 #ifdef ENOTSUP
141     case ENOTSUP:
142       return G_IO_ERROR_NOT_SUPPORTED;
143       break;
144 #endif
145
146 #ifdef ETIMEDOUT
147     case ETIMEDOUT:
148       return G_IO_ERROR_TIMED_OUT;
149       break;
150 #endif
151
152 #ifdef EBUSY
153     case EBUSY:
154       return G_IO_ERROR_BUSY;
155       break;
156 #endif
157
158 /* some magic to deal with EWOULDBLOCK and EAGAIN.
159  * apparently on HP-UX these are actually defined to different values,
160  * but on Linux, for example, they are the same.
161  */
162 #if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK == EAGAIN
163     /* we have both and they are the same: only emit one case. */
164     case EAGAIN:
165       return G_IO_ERROR_WOULD_BLOCK;
166       break;
167 #else
168     /* else: consider each of them separately.  this handles both the
169      * case of having only one and the case where they are different values.
170      */
171 # ifdef EAGAIN
172     case EAGAIN:
173       return G_IO_ERROR_WOULD_BLOCK;
174       break;
175 # endif
176
177 # ifdef EWOULDBLOCK
178     case EWOULDBLOCK:
179       return G_IO_ERROR_WOULD_BLOCK;
180       break;
181 # endif
182 #endif
183
184 #ifdef EMFILE
185     case EMFILE:
186       return G_IO_ERROR_TOO_MANY_OPEN_FILES;
187       break;
188 #endif
189
190 #ifdef EADDRINUSE
191     case EADDRINUSE:
192       return G_IO_ERROR_ADDRESS_IN_USE;
193       break;
194 #endif
195
196 #ifdef EHOSTUNREACH
197     case EHOSTUNREACH:
198       return G_IO_ERROR_HOST_UNREACHABLE;
199       break;
200 #endif
201
202 #ifdef ENETUNREACH
203     case ENETUNREACH:
204       return G_IO_ERROR_NETWORK_UNREACHABLE;
205       break;
206 #endif
207
208 #ifdef ECONNREFUSED
209     case ECONNREFUSED:
210       return G_IO_ERROR_CONNECTION_REFUSED;
211       break;
212 #endif
213
214 #ifdef EPIPE
215     case EPIPE:
216       return G_IO_ERROR_BROKEN_PIPE;
217       break;
218 #endif
219
220     default:
221       return G_IO_ERROR_FAILED;
222       break;
223     }
224 }
225
226 #ifdef G_OS_WIN32
227
228 /**
229  * g_io_error_from_win32_error:
230  * @error_code: Windows error number.
231  *
232  * Converts some common error codes into GIO error codes. The
233  * fallback value G_IO_ERROR_FAILED is returned for error codes not
234  * handled.
235  *
236  * Returns: #GIOErrorEnum value for the given error number.
237  *
238  * Since: 2.26
239  **/
240 GIOErrorEnum
241 g_io_error_from_win32_error (gint error_code)
242 {
243   switch (error_code)
244     {
245     default:
246       return G_IO_ERROR_FAILED;
247       break;
248     }
249 }
250
251 #endif