Added. Added. Added. Added.
[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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include <errno.h>
25 #include "gioerror.h"
26
27 #include "gioalias.h"
28
29 /**
30  * SECTION:gioerror
31  * @short_description: Error helper functions
32  *
33  **/
34
35 /**
36  * g_io_error_quark:
37  * 
38  * Gets the GIO Error Quark.
39  *
40  * Return value: a #GQuark.
41  **/
42 GQuark
43 g_io_error_quark (void)
44 {
45   return g_quark_from_static_string ("g-io-error-quark");
46 }
47
48 /**
49  * g_io_error_from_errno:
50  * @err_no: Error number as defined in errno.h.
51  *
52  * Converts errno.h error codes into GIO error codes.
53  *
54  * Returns: #GIOErrorEnum value for the given errno.h error number.
55  **/
56 GIOErrorEnum
57 g_io_error_from_errno (gint err_no)
58 {
59   switch (err_no)
60     {
61 #ifdef EEXIST
62     case EEXIST:
63       return G_IO_ERROR_EXISTS;
64       break;
65 #endif
66
67 #ifdef EISDIR
68     case EISDIR:
69       return G_IO_ERROR_IS_DIRECTORY;
70       break;
71 #endif
72
73 #ifdef EACCES
74     case EACCES:
75       return G_IO_ERROR_PERMISSION_DENIED;
76       break;
77 #endif
78
79 #ifdef ENAMETOOLONG
80     case ENAMETOOLONG:
81       return G_IO_ERROR_FILENAME_TOO_LONG;
82       break;
83 #endif
84
85 #ifdef ENOENT
86     case ENOENT:
87       return G_IO_ERROR_NOT_FOUND;
88       break;
89 #endif
90
91 #ifdef ENOTDIR
92     case ENOTDIR:
93       return G_IO_ERROR_NOT_DIRECTORY;
94       break;
95 #endif
96
97 #ifdef EROFS
98     case EROFS:
99       return G_IO_ERROR_READ_ONLY;
100       break;
101 #endif
102
103 #ifdef ELOOP
104     case ELOOP:
105       return G_IO_ERROR_TOO_MANY_LINKS;
106       break;
107 #endif
108
109 #ifdef ENOSPC
110     case ENOSPC:
111       return G_IO_ERROR_NO_SPACE;
112       break;
113 #endif
114
115 #ifdef ENOMEM
116     case ENOMEM:
117       return G_IO_ERROR_NO_SPACE;
118       break;
119 #endif
120       
121 #ifdef EINVAL
122     case EINVAL:
123       return G_IO_ERROR_INVALID_ARGUMENT;
124       break;
125 #endif
126
127 #ifdef EPERM
128     case EPERM:
129       return G_IO_ERROR_PERMISSION_DENIED;
130       break;
131 #endif
132
133 #ifdef ECANCELED
134     case ECANCELED:
135       return G_IO_ERROR_CANCELLED;
136       break;
137 #endif
138
139 #ifdef ENOTEMPTY
140     case ENOTEMPTY:
141       return G_IO_ERROR_NOT_EMPTY;
142       break;
143 #endif
144
145 #ifdef ENOTSUP
146     case ENOTSUP:
147       return G_IO_ERROR_NOT_SUPPORTED;
148       break;
149 #endif
150
151 #ifdef ETIMEDOUT
152     case ETIMEDOUT:
153       return G_IO_ERROR_TIMED_OUT;
154       break;
155 #endif
156
157 #ifdef EBUSY
158     case EBUSY:
159       return G_IO_ERROR_BUSY;
160       break;
161 #endif
162
163 #ifdef EWOULDBLOCK
164     case EWOULDBLOCK:
165       return G_IO_ERROR_WOULD_BLOCK;
166       break;
167 #endif
168       
169     default:
170       return G_IO_ERROR_FAILED;
171       break;
172     }
173 }
174
175 #define __G_IO_ERROR_C__
176 #include "gioaliasdef.c"