xref: /aoo41x/main/sal/osl/unx/file_error_transl.cxx (revision 87d2adbc)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27  #ifndef _ERRNO_H
28  #include <errno.h>
29  #endif
30 
31  #ifndef _FILE_ERROR_TRANSL_H_
32  #include "file_error_transl.h"
33  #endif
34 
35  #ifndef _OSL_DIAGNOSE_H_
36  #include <osl/diagnose.h>
37  #endif
38 
39 
40 /********************************************
41  * oslTranslateFileError
42  *******************************************/
43 
oslTranslateFileError(sal_Bool bIsError,int Errno)44 oslFileError oslTranslateFileError(sal_Bool bIsError, int Errno)
45 {
46     oslFileError osl_error = osl_File_E_invalidError;
47 
48 	OSL_ENSURE((bIsError && (0 != Errno)) || (!bIsError && (0 == Errno)), "oslTranslateFileError strange input combination!");
49 
50 	/* Have a look at file_error_transl.h for
51 	   the reason that we do this here */
52 	if (bIsError && (0 == Errno))
53 		return osl_error;
54 
55     switch(Errno)
56     {
57         case 0:
58             osl_error = osl_File_E_None;
59             break;
60 
61         case EPERM:
62             osl_error = osl_File_E_PERM;
63             break;
64 
65         case ENOENT:
66             osl_error = osl_File_E_NOENT;
67             break;
68 
69         case ESRCH:
70             osl_error = osl_File_E_SRCH;
71             break;
72 
73         case EINTR:
74             osl_error = osl_File_E_INTR;
75             break;
76 
77         case EIO:
78             osl_error = osl_File_E_IO;
79             break;
80 
81         case ENXIO:
82             osl_error = osl_File_E_IO;
83             break;
84 
85         case E2BIG:
86             osl_error = osl_File_E_2BIG;
87             break;
88 
89         case ENOEXEC:
90             osl_error = osl_File_E_NOEXEC;
91             break;
92 
93         case EBADF:
94             osl_error = osl_File_E_BADF;
95             break;
96 
97         case ECHILD:
98             osl_error = osl_File_E_CHILD;
99             break;
100 
101         case EAGAIN:
102             osl_error = osl_File_E_AGAIN;
103             break;
104 
105         case ENOMEM:
106             osl_error = osl_File_E_NOMEM;
107             break;
108 
109         case EACCES:
110             osl_error = osl_File_E_ACCES;
111             break;
112 
113         case EFAULT:
114             osl_error = osl_File_E_FAULT;
115             break;
116 
117         case EBUSY:
118             osl_error = osl_File_E_BUSY;
119             break;
120 
121         case EEXIST:
122             osl_error = osl_File_E_EXIST;
123             break;
124 
125         case EXDEV:
126             osl_error = osl_File_E_XDEV;
127             break;
128 
129         case ENODEV:
130             osl_error = osl_File_E_NODEV;
131             break;
132 
133         case ENOTDIR:
134             osl_error = osl_File_E_NOTDIR;
135             break;
136 
137         case EISDIR:
138             osl_error = osl_File_E_ISDIR;
139             break;
140 
141         case EINVAL:
142             osl_error = osl_File_E_INVAL;
143             break;
144 
145         case ENFILE:
146             osl_error = osl_File_E_NFILE;
147             break;
148 
149         case EMFILE:
150             osl_error = osl_File_E_MFILE;
151             break;
152 
153         case ENOTTY:
154             osl_error = osl_File_E_NOTTY;
155             break;
156 
157         case EFBIG:
158             osl_error = osl_File_E_FBIG;
159             break;
160 
161         case ENOSPC:
162             osl_error = osl_File_E_NOSPC;
163             break;
164 
165         case ESPIPE:
166             osl_error = osl_File_E_SPIPE;
167             break;
168 
169         case EROFS:
170             osl_error = osl_File_E_ROFS;
171             break;
172 
173         case EMLINK:
174             osl_error = osl_File_E_MLINK;
175             break;
176 
177         case EPIPE:
178             osl_error = osl_File_E_PIPE;
179             break;
180 
181         case EDOM:
182             osl_error = osl_File_E_DOM;
183             break;
184 
185         case ERANGE:
186             osl_error = osl_File_E_RANGE;
187             break;
188 
189         case EDEADLK:
190             osl_error = osl_File_E_DEADLK;
191             break;
192 
193         case ENAMETOOLONG:
194             osl_error = osl_File_E_NAMETOOLONG;
195             break;
196 
197         case ENOLCK:
198             osl_error = osl_File_E_NOLCK;
199             break;
200 
201         case ENOSYS:
202            osl_error = osl_File_E_NOSYS;
203             break;
204 
205         case ENOTEMPTY:
206             osl_error = osl_File_E_NOTEMPTY;
207             break;
208 
209         case ELOOP:
210             osl_error = osl_File_E_LOOP;
211             break;
212 
213 #if !(defined(MACOSX) || defined(NETBSD) || defined(FREEBSD))
214         case EILSEQ:
215             osl_error = osl_File_E_ILSEQ;
216             break;
217 #endif /* MACOSX */
218 
219 #if !(defined(MACOSX) || defined(NETBSD) || defined(FREEBSD))
220         case ENOLINK:
221             osl_error = osl_File_E_NOLINK;
222             break;
223 #endif /* MACOSX */
224 
225 #if !(defined(MACOSX) || defined(NETBSD) || defined(FREEBSD))
226         case EMULTIHOP:
227             osl_error = osl_File_E_MULTIHOP;
228             break;
229 #endif /* MACOSX */
230 
231         case EUSERS:
232             osl_error = osl_File_E_USERS;
233             break;
234 
235         case EOVERFLOW:
236             osl_error = osl_File_E_OVERFLOW;
237             break;
238 
239         case ETIMEDOUT:
240             osl_error = osl_File_E_TIMEDOUT;
241             break;
242 
243         default:
244             /* FIXME translateFileError: is this alright? Or add a new one: osl_File_E_Unknown? */
245             osl_error = osl_File_E_invalidError;
246             break;
247     }
248 
249     return osl_error;
250 }
251 
252