1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/*
3 * This file essentially replicates NSPR's source for the functions that
4 * map system-specific error codes to NSPR error codes.  We would use
5 * NSPR's functions, instead of duplicating them, but they're private.
6 * As long as SSL's server session cache code must do platform native I/O
7 * to accomplish its job, and NSPR's error mapping functions remain private,
8 * this code will continue to need to be replicated.
9 *
10 * This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this
12 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
13
14#include "prerror.h"
15#include "prlog.h"
16#include <errno.h>
17
18
19/*
20 * Based on win32err.c
21 * OS2TODO Stub everything for now to build. HCT
22 */
23
24/* forward declaration. */
25void nss_MD_os2_map_default_error(PRInt32 err);
26
27void nss_MD_os2_map_opendir_error(PRInt32 err)
28{
29    nss_MD_os2_map_default_error(err);
30}
31
32void nss_MD_os2_map_closedir_error(PRInt32 err)
33{
34    nss_MD_os2_map_default_error(err);
35}
36
37void nss_MD_os2_map_readdir_error(PRInt32 err)
38{
39    nss_MD_os2_map_default_error(err);
40}
41
42void nss_MD_os2_map_delete_error(PRInt32 err)
43{
44    nss_MD_os2_map_default_error(err);
45}
46
47/* The error code for stat() is in errno. */
48void nss_MD_os2_map_stat_error(PRInt32 err)
49{
50    nss_MD_os2_map_default_error(err);
51}
52
53void nss_MD_os2_map_fstat_error(PRInt32 err)
54{
55    nss_MD_os2_map_default_error(err);
56}
57
58void nss_MD_os2_map_rename_error(PRInt32 err)
59{
60    nss_MD_os2_map_default_error(err);
61}
62
63/* The error code for access() is in errno. */
64void nss_MD_os2_map_access_error(PRInt32 err)
65{
66    nss_MD_os2_map_default_error(err);
67}
68
69void nss_MD_os2_map_mkdir_error(PRInt32 err)
70{
71    nss_MD_os2_map_default_error(err);
72}
73
74void nss_MD_os2_map_rmdir_error(PRInt32 err)
75{
76    nss_MD_os2_map_default_error(err);
77}
78
79void nss_MD_os2_map_read_error(PRInt32 err)
80{
81    nss_MD_os2_map_default_error(err);
82}
83
84void nss_MD_os2_map_transmitfile_error(PRInt32 err)
85{
86    nss_MD_os2_map_default_error(err);
87}
88
89void nss_MD_os2_map_write_error(PRInt32 err)
90{
91    nss_MD_os2_map_default_error(err);
92}
93
94void nss_MD_os2_map_lseek_error(PRInt32 err)
95{
96    nss_MD_os2_map_default_error(err);
97}
98
99void nss_MD_os2_map_fsync_error(PRInt32 err)
100{
101    nss_MD_os2_map_default_error(err);
102}
103
104/*
105 * For both CloseHandle() and closesocket().
106 */
107void nss_MD_os2_map_close_error(PRInt32 err)
108{
109    nss_MD_os2_map_default_error(err);
110}
111
112void nss_MD_os2_map_socket_error(PRInt32 err)
113{
114//  PR_ASSERT(err != WSANOTINITIALISED);
115    nss_MD_os2_map_default_error(err);
116}
117
118void nss_MD_os2_map_recv_error(PRInt32 err)
119{
120    nss_MD_os2_map_default_error(err);
121}
122
123void nss_MD_os2_map_recvfrom_error(PRInt32 err)
124{
125    nss_MD_os2_map_default_error(err);
126}
127
128void nss_MD_os2_map_send_error(PRInt32 err)
129{
130    PRErrorCode prError;
131    switch (err) {
132//     case WSAEMSGSIZE: 	prError = PR_INVALID_ARGUMENT_ERROR; break;
133    default:		nss_MD_os2_map_default_error(err); return;
134    }
135    PR_SetError(prError, err);
136}
137
138void nss_MD_os2_map_sendto_error(PRInt32 err)
139{
140    PRErrorCode prError;
141    switch (err) {
142//    case WSAEMSGSIZE: 	prError = PR_INVALID_ARGUMENT_ERROR; break;
143    default:		nss_MD_os2_map_default_error(err); return;
144    }
145    PR_SetError(prError, err);
146}
147
148void nss_MD_os2_map_accept_error(PRInt32 err)
149{
150    PRErrorCode prError;
151    switch (err) {
152//    case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
153//    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
154    default:		nss_MD_os2_map_default_error(err); return;
155    }
156    PR_SetError(prError, err);
157}
158
159void nss_MD_os2_map_acceptex_error(PRInt32 err)
160{
161    nss_MD_os2_map_default_error(err);
162}
163
164void nss_MD_os2_map_connect_error(PRInt32 err)
165{
166    PRErrorCode prError;
167    switch (err) {
168//    case WSAEWOULDBLOCK: prError = PR_IN_PROGRESS_ERROR; break;
169//    case WSAEINVAL: 	prError = PR_ALREADY_INITIATED_ERROR; break;
170//    case WSAETIMEDOUT: 	prError = PR_IO_TIMEOUT_ERROR; break;
171    default:		nss_MD_os2_map_default_error(err); return;
172    }
173    PR_SetError(prError, err);
174}
175
176void nss_MD_os2_map_bind_error(PRInt32 err)
177{
178    PRErrorCode prError;
179    switch (err) {
180//  case WSAEINVAL: 	prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; break;
181    default:		nss_MD_os2_map_default_error(err); return;
182    }
183    PR_SetError(prError, err);
184}
185
186void nss_MD_os2_map_listen_error(PRInt32 err)
187{
188    PRErrorCode prError;
189    switch (err) {
190//    case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
191//    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
192    default:		nss_MD_os2_map_default_error(err); return;
193    }
194    PR_SetError(prError, err);
195}
196
197void nss_MD_os2_map_shutdown_error(PRInt32 err)
198{
199    nss_MD_os2_map_default_error(err);
200}
201
202void nss_MD_os2_map_getsockname_error(PRInt32 err)
203{
204    PRErrorCode prError;
205    switch (err) {
206//    case WSAEINVAL: 	prError = PR_INVALID_STATE_ERROR; break;
207    default:		nss_MD_os2_map_default_error(err); return;
208    }
209    PR_SetError(prError, err);
210}
211
212void nss_MD_os2_map_getpeername_error(PRInt32 err)
213{
214    nss_MD_os2_map_default_error(err);
215}
216
217void nss_MD_os2_map_getsockopt_error(PRInt32 err)
218{
219    nss_MD_os2_map_default_error(err);
220}
221
222void nss_MD_os2_map_setsockopt_error(PRInt32 err)
223{
224    nss_MD_os2_map_default_error(err);
225}
226
227void nss_MD_os2_map_open_error(PRInt32 err)
228{
229    nss_MD_os2_map_default_error(err);
230}
231
232void nss_MD_os2_map_gethostname_error(PRInt32 err)
233{
234    nss_MD_os2_map_default_error(err);
235}
236
237/* Win32 select() only works on sockets.  So in this
238** context, WSAENOTSOCK is equivalent to EBADF on Unix.
239*/
240void nss_MD_os2_map_select_error(PRInt32 err)
241{
242    PRErrorCode prError;
243    switch (err) {
244//    case WSAENOTSOCK:	prError = PR_BAD_DESCRIPTOR_ERROR; break;
245    default:		nss_MD_os2_map_default_error(err); return;
246    }
247    PR_SetError(prError, err);
248}
249
250void nss_MD_os2_map_lockf_error(PRInt32 err)
251{
252    nss_MD_os2_map_default_error(err);
253}
254
255
256
257void nss_MD_os2_map_default_error(PRInt32 err)
258{
259    PRErrorCode prError;
260
261    switch (err) {
262//    case ENOENT: 		prError = PR_FILE_NOT_FOUND_ERROR; break;
263//    case ERROR_ACCESS_DENIED: 	prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
264//    case ERROR_ALREADY_EXISTS: 	prError = PR_FILE_EXISTS_ERROR; break;
265//    case ERROR_DISK_CORRUPT: 	prError = PR_IO_ERROR; break;
266//    case ERROR_DISK_FULL: 	prError = PR_NO_DEVICE_SPACE_ERROR; break;
267//    case ERROR_DISK_OPERATION_FAILED: prError = PR_IO_ERROR; break;
268//    case ERROR_DRIVE_LOCKED: 	prError = PR_FILE_IS_LOCKED_ERROR; break;
269//    case ERROR_FILENAME_EXCED_RANGE: prError = PR_NAME_TOO_LONG_ERROR; break;
270//    case ERROR_FILE_CORRUPT: 	prError = PR_IO_ERROR; break;
271//    case ERROR_FILE_EXISTS: 	prError = PR_FILE_EXISTS_ERROR; break;
272//    case ERROR_FILE_INVALID: 	prError = PR_BAD_DESCRIPTOR_ERROR; break;
273#if ERROR_FILE_NOT_FOUND != ENOENT
274//    case ERROR_FILE_NOT_FOUND: 	prError = PR_FILE_NOT_FOUND_ERROR; break;
275#endif
276    default: 			prError = PR_UNKNOWN_ERROR; break;
277    }
278    PR_SetError(prError, err);
279}
280
281