Mercurial > trustbridge > nss-cmake-static
comparison nspr/pr/src/md/windows/win32_errors.c @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
5 | |
6 #include "prerror.h" | |
7 #include "prlog.h" | |
8 #include <errno.h> | |
9 #include <windows.h> | |
10 | |
11 /* | |
12 * On Win32, we map three kinds of error codes: | |
13 * - GetLastError(): for Win32 functions | |
14 * - WSAGetLastError(): for Winsock functions | |
15 * - errno: for standard C library functions | |
16 * | |
17 * GetLastError() and WSAGetLastError() return error codes in | |
18 * non-overlapping ranges, so their error codes (ERROR_* and | |
19 * WSAE*) can be mapped by the same function. On the other hand, | |
20 * errno and GetLastError() have overlapping ranges, so we need | |
21 * to use a separate function to map errno. | |
22 * | |
23 * We do not check for WSAEINPROGRESS and WSAEINTR because we do not | |
24 * use blocking Winsock 1.1 calls. | |
25 * | |
26 * Except for the 'socket' call, we do not check for WSAEINITIALISED. | |
27 * It is assumed that if Winsock is not initialized, that fact will | |
28 * be detected at the time we create new sockets. | |
29 */ | |
30 | |
31 static void _MD_win32_map_default_errno(PRInt32 err) | |
32 { | |
33 PRErrorCode prError; | |
34 | |
35 switch (err) { | |
36 case EACCES: | |
37 prError = PR_NO_ACCESS_RIGHTS_ERROR; | |
38 break; | |
39 case ENOENT: | |
40 prError = PR_FILE_NOT_FOUND_ERROR; | |
41 break; | |
42 default: | |
43 prError = PR_UNKNOWN_ERROR; | |
44 break; | |
45 } | |
46 PR_SetError(prError, err); | |
47 } | |
48 | |
49 void _MD_win32_map_default_error(PRInt32 err) | |
50 { | |
51 PRErrorCode prError; | |
52 | |
53 switch (err) { | |
54 case ERROR_ACCESS_DENIED: | |
55 prError = PR_NO_ACCESS_RIGHTS_ERROR; | |
56 break; | |
57 case ERROR_ALREADY_EXISTS: | |
58 prError = PR_FILE_EXISTS_ERROR; | |
59 break; | |
60 case ERROR_CALL_NOT_IMPLEMENTED: | |
61 prError = PR_NOT_IMPLEMENTED_ERROR; | |
62 break; | |
63 case ERROR_DISK_CORRUPT: | |
64 prError = PR_IO_ERROR; | |
65 break; | |
66 case ERROR_DISK_FULL: | |
67 prError = PR_NO_DEVICE_SPACE_ERROR; | |
68 break; | |
69 case ERROR_DISK_OPERATION_FAILED: | |
70 prError = PR_IO_ERROR; | |
71 break; | |
72 case ERROR_DRIVE_LOCKED: | |
73 prError = PR_FILE_IS_LOCKED_ERROR; | |
74 break; | |
75 case ERROR_FILENAME_EXCED_RANGE: | |
76 prError = PR_NAME_TOO_LONG_ERROR; | |
77 break; | |
78 case ERROR_FILE_CORRUPT: | |
79 prError = PR_IO_ERROR; | |
80 break; | |
81 case ERROR_FILE_EXISTS: | |
82 prError = PR_FILE_EXISTS_ERROR; | |
83 break; | |
84 case ERROR_FILE_INVALID: | |
85 prError = PR_BAD_DESCRIPTOR_ERROR; | |
86 break; | |
87 case ERROR_FILE_NOT_FOUND: | |
88 prError = PR_FILE_NOT_FOUND_ERROR; | |
89 break; | |
90 case ERROR_HANDLE_DISK_FULL: | |
91 prError = PR_NO_DEVICE_SPACE_ERROR; | |
92 break; | |
93 case ERROR_INVALID_ADDRESS: | |
94 prError = PR_ACCESS_FAULT_ERROR; | |
95 break; | |
96 case ERROR_INVALID_HANDLE: | |
97 prError = PR_BAD_DESCRIPTOR_ERROR; | |
98 break; | |
99 case ERROR_INVALID_NAME: | |
100 prError = PR_INVALID_ARGUMENT_ERROR; | |
101 break; | |
102 case ERROR_INVALID_PARAMETER: | |
103 prError = PR_INVALID_ARGUMENT_ERROR; | |
104 break; | |
105 case ERROR_INVALID_USER_BUFFER: | |
106 prError = PR_INSUFFICIENT_RESOURCES_ERROR; | |
107 break; | |
108 case ERROR_LOCKED: | |
109 prError = PR_FILE_IS_LOCKED_ERROR; | |
110 break; | |
111 case ERROR_NETNAME_DELETED: | |
112 prError = PR_CONNECT_RESET_ERROR; | |
113 break; | |
114 case ERROR_NOACCESS: | |
115 prError = PR_ACCESS_FAULT_ERROR; | |
116 break; | |
117 case ERROR_NOT_ENOUGH_MEMORY: | |
118 prError = PR_INSUFFICIENT_RESOURCES_ERROR; | |
119 break; | |
120 case ERROR_NOT_ENOUGH_QUOTA: | |
121 prError = PR_OUT_OF_MEMORY_ERROR; | |
122 break; | |
123 case ERROR_NOT_READY: | |
124 prError = PR_IO_ERROR; | |
125 break; | |
126 case ERROR_NO_MORE_FILES: | |
127 prError = PR_NO_MORE_FILES_ERROR; | |
128 break; | |
129 case ERROR_OPEN_FAILED: | |
130 prError = PR_IO_ERROR; | |
131 break; | |
132 case ERROR_OPEN_FILES: | |
133 prError = PR_IO_ERROR; | |
134 break; | |
135 case ERROR_OPERATION_ABORTED: | |
136 prError = PR_OPERATION_ABORTED_ERROR; | |
137 break; | |
138 case ERROR_OUTOFMEMORY: | |
139 prError = PR_INSUFFICIENT_RESOURCES_ERROR; | |
140 break; | |
141 case ERROR_PATH_BUSY: | |
142 prError = PR_IO_ERROR; | |
143 break; | |
144 case ERROR_PATH_NOT_FOUND: | |
145 prError = PR_FILE_NOT_FOUND_ERROR; | |
146 break; | |
147 case ERROR_SEEK_ON_DEVICE: | |
148 prError = PR_IO_ERROR; | |
149 break; | |
150 case ERROR_SHARING_VIOLATION: | |
151 prError = PR_FILE_IS_BUSY_ERROR; | |
152 break; | |
153 case ERROR_STACK_OVERFLOW: | |
154 prError = PR_ACCESS_FAULT_ERROR; | |
155 break; | |
156 case ERROR_TOO_MANY_OPEN_FILES: | |
157 prError = PR_SYS_DESC_TABLE_FULL_ERROR; | |
158 break; | |
159 case ERROR_WRITE_PROTECT: | |
160 prError = PR_NO_ACCESS_RIGHTS_ERROR; | |
161 break; | |
162 case WSAEACCES: | |
163 prError = PR_NO_ACCESS_RIGHTS_ERROR; | |
164 break; | |
165 case WSAEADDRINUSE: | |
166 prError = PR_ADDRESS_IN_USE_ERROR; | |
167 break; | |
168 case WSAEADDRNOTAVAIL: | |
169 prError = PR_ADDRESS_NOT_AVAILABLE_ERROR; | |
170 break; | |
171 case WSAEAFNOSUPPORT: | |
172 prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; | |
173 break; | |
174 case WSAEALREADY: | |
175 prError = PR_ALREADY_INITIATED_ERROR; | |
176 break; | |
177 case WSAEBADF: | |
178 prError = PR_BAD_DESCRIPTOR_ERROR; | |
179 break; | |
180 case WSAECONNABORTED: | |
181 prError = PR_CONNECT_ABORTED_ERROR; | |
182 break; | |
183 case WSAECONNREFUSED: | |
184 prError = PR_CONNECT_REFUSED_ERROR; | |
185 break; | |
186 case WSAECONNRESET: | |
187 prError = PR_CONNECT_RESET_ERROR; | |
188 break; | |
189 case WSAEDESTADDRREQ: | |
190 prError = PR_INVALID_ARGUMENT_ERROR; | |
191 break; | |
192 case WSAEFAULT: | |
193 prError = PR_ACCESS_FAULT_ERROR; | |
194 break; | |
195 case WSAEHOSTUNREACH: | |
196 prError = PR_HOST_UNREACHABLE_ERROR; | |
197 break; | |
198 case WSAEINVAL: | |
199 prError = PR_INVALID_ARGUMENT_ERROR; | |
200 break; | |
201 case WSAEISCONN: | |
202 prError = PR_IS_CONNECTED_ERROR; | |
203 break; | |
204 case WSAEMFILE: | |
205 prError = PR_PROC_DESC_TABLE_FULL_ERROR; | |
206 break; | |
207 case WSAEMSGSIZE: | |
208 prError = PR_BUFFER_OVERFLOW_ERROR; | |
209 break; | |
210 case WSAENETDOWN: | |
211 prError = PR_NETWORK_DOWN_ERROR; | |
212 break; | |
213 case WSAENETRESET: | |
214 prError = PR_CONNECT_ABORTED_ERROR; | |
215 break; | |
216 case WSAENETUNREACH: | |
217 prError = PR_NETWORK_UNREACHABLE_ERROR; | |
218 break; | |
219 case WSAENOBUFS: | |
220 prError = PR_INSUFFICIENT_RESOURCES_ERROR; | |
221 break; | |
222 case WSAENOPROTOOPT: | |
223 prError = PR_INVALID_ARGUMENT_ERROR; | |
224 break; | |
225 case WSAENOTCONN: | |
226 prError = PR_NOT_CONNECTED_ERROR; | |
227 break; | |
228 case WSAENOTSOCK: | |
229 prError = PR_NOT_SOCKET_ERROR; | |
230 break; | |
231 case WSAEOPNOTSUPP: | |
232 prError = PR_OPERATION_NOT_SUPPORTED_ERROR; | |
233 break; | |
234 case WSAEPROTONOSUPPORT: | |
235 prError = PR_PROTOCOL_NOT_SUPPORTED_ERROR; | |
236 break; | |
237 case WSAEPROTOTYPE: | |
238 prError = PR_INVALID_ARGUMENT_ERROR; | |
239 break; | |
240 case WSAESHUTDOWN: | |
241 prError = PR_SOCKET_SHUTDOWN_ERROR; | |
242 break; | |
243 case WSAESOCKTNOSUPPORT: | |
244 prError = PR_INVALID_ARGUMENT_ERROR; | |
245 break; | |
246 case WSAETIMEDOUT: | |
247 prError = PR_CONNECT_ABORTED_ERROR; | |
248 break; | |
249 case WSAEWOULDBLOCK: | |
250 prError = PR_WOULD_BLOCK_ERROR; | |
251 break; | |
252 default: | |
253 prError = PR_UNKNOWN_ERROR; | |
254 break; | |
255 } | |
256 PR_SetError(prError, err); | |
257 } | |
258 | |
259 void _MD_win32_map_opendir_error(PRInt32 err) | |
260 { | |
261 _MD_win32_map_default_error(err); | |
262 } | |
263 | |
264 void _MD_win32_map_closedir_error(PRInt32 err) | |
265 { | |
266 _MD_win32_map_default_error(err); | |
267 } | |
268 | |
269 void _MD_unix_readdir_error(PRInt32 err) | |
270 { | |
271 _MD_win32_map_default_error(err); | |
272 } | |
273 | |
274 void _MD_win32_map_delete_error(PRInt32 err) | |
275 { | |
276 _MD_win32_map_default_error(err); | |
277 } | |
278 | |
279 /* The error code for stat() is in errno. */ | |
280 void _MD_win32_map_stat_error(PRInt32 err) | |
281 { | |
282 _MD_win32_map_default_errno(err); | |
283 } | |
284 | |
285 void _MD_win32_map_fstat_error(PRInt32 err) | |
286 { | |
287 _MD_win32_map_default_error(err); | |
288 } | |
289 | |
290 void _MD_win32_map_rename_error(PRInt32 err) | |
291 { | |
292 _MD_win32_map_default_error(err); | |
293 } | |
294 | |
295 /* The error code for access() is in errno. */ | |
296 void _MD_win32_map_access_error(PRInt32 err) | |
297 { | |
298 _MD_win32_map_default_errno(err); | |
299 } | |
300 | |
301 void _MD_win32_map_mkdir_error(PRInt32 err) | |
302 { | |
303 _MD_win32_map_default_error(err); | |
304 } | |
305 | |
306 void _MD_win32_map_rmdir_error(PRInt32 err) | |
307 { | |
308 _MD_win32_map_default_error(err); | |
309 } | |
310 | |
311 void _MD_win32_map_read_error(PRInt32 err) | |
312 { | |
313 _MD_win32_map_default_error(err); | |
314 } | |
315 | |
316 void _MD_win32_map_transmitfile_error(PRInt32 err) | |
317 { | |
318 _MD_win32_map_default_error(err); | |
319 } | |
320 | |
321 void _MD_win32_map_write_error(PRInt32 err) | |
322 { | |
323 _MD_win32_map_default_error(err); | |
324 } | |
325 | |
326 void _MD_win32_map_lseek_error(PRInt32 err) | |
327 { | |
328 _MD_win32_map_default_error(err); | |
329 } | |
330 | |
331 void _MD_win32_map_fsync_error(PRInt32 err) | |
332 { | |
333 _MD_win32_map_default_error(err); | |
334 } | |
335 | |
336 /* | |
337 * For both CloseHandle() and closesocket(). | |
338 */ | |
339 void _MD_win32_map_close_error(PRInt32 err) | |
340 { | |
341 _MD_win32_map_default_error(err); | |
342 } | |
343 | |
344 void _MD_win32_map_socket_error(PRInt32 err) | |
345 { | |
346 PR_ASSERT(err != WSANOTINITIALISED); | |
347 _MD_win32_map_default_error(err); | |
348 } | |
349 | |
350 void _MD_win32_map_recv_error(PRInt32 err) | |
351 { | |
352 _MD_win32_map_default_error(err); | |
353 } | |
354 | |
355 void _MD_win32_map_recvfrom_error(PRInt32 err) | |
356 { | |
357 _MD_win32_map_default_error(err); | |
358 } | |
359 | |
360 void _MD_win32_map_send_error(PRInt32 err) | |
361 { | |
362 PRErrorCode prError; | |
363 | |
364 switch (err) { | |
365 case WSAEMSGSIZE: | |
366 prError = PR_INVALID_ARGUMENT_ERROR; | |
367 break; | |
368 default: | |
369 _MD_win32_map_default_error(err); | |
370 return; | |
371 } | |
372 PR_SetError(prError, err); | |
373 } | |
374 | |
375 void _MD_win32_map_sendto_error(PRInt32 err) | |
376 { | |
377 PRErrorCode prError; | |
378 | |
379 switch (err) { | |
380 case WSAEMSGSIZE: | |
381 prError = PR_INVALID_ARGUMENT_ERROR; | |
382 break; | |
383 default: | |
384 _MD_win32_map_default_error(err); | |
385 return; | |
386 } | |
387 PR_SetError(prError, err); | |
388 } | |
389 | |
390 void _MD_win32_map_accept_error(PRInt32 err) | |
391 { | |
392 PRErrorCode prError; | |
393 | |
394 switch (err) { | |
395 case WSAEOPNOTSUPP: | |
396 prError = PR_NOT_TCP_SOCKET_ERROR; | |
397 break; | |
398 case WSAEINVAL: | |
399 prError = PR_INVALID_STATE_ERROR; | |
400 break; | |
401 default: | |
402 _MD_win32_map_default_error(err); | |
403 return; | |
404 } | |
405 PR_SetError(prError, err); | |
406 } | |
407 | |
408 void _MD_win32_map_acceptex_error(PRInt32 err) | |
409 { | |
410 _MD_win32_map_default_error(err); | |
411 } | |
412 | |
413 void _MD_win32_map_connect_error(PRInt32 err) | |
414 { | |
415 PRErrorCode prError; | |
416 | |
417 switch (err) { | |
418 case WSAEWOULDBLOCK: | |
419 prError = PR_IN_PROGRESS_ERROR; | |
420 break; | |
421 case WSAEINVAL: | |
422 prError = PR_ALREADY_INITIATED_ERROR; | |
423 break; | |
424 case WSAETIMEDOUT: | |
425 prError = PR_IO_TIMEOUT_ERROR; | |
426 break; | |
427 default: | |
428 _MD_win32_map_default_error(err); | |
429 return; | |
430 } | |
431 PR_SetError(prError, err); | |
432 } | |
433 | |
434 void _MD_win32_map_bind_error(PRInt32 err) | |
435 { | |
436 PRErrorCode prError; | |
437 | |
438 switch (err) { | |
439 case WSAEINVAL: | |
440 prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; | |
441 break; | |
442 default: | |
443 _MD_win32_map_default_error(err); | |
444 return; | |
445 } | |
446 PR_SetError(prError, err); | |
447 } | |
448 | |
449 void _MD_win32_map_listen_error(PRInt32 err) | |
450 { | |
451 PRErrorCode prError; | |
452 | |
453 switch (err) { | |
454 case WSAEOPNOTSUPP: | |
455 prError = PR_NOT_TCP_SOCKET_ERROR; | |
456 break; | |
457 case WSAEINVAL: | |
458 prError = PR_INVALID_STATE_ERROR; | |
459 break; | |
460 default: | |
461 _MD_win32_map_default_error(err); | |
462 return; | |
463 } | |
464 PR_SetError(prError, err); | |
465 } | |
466 | |
467 void _MD_win32_map_shutdown_error(PRInt32 err) | |
468 { | |
469 _MD_win32_map_default_error(err); | |
470 } | |
471 | |
472 void _MD_win32_map_getsockname_error(PRInt32 err) | |
473 { | |
474 PRErrorCode prError; | |
475 | |
476 switch (err) { | |
477 case WSAEINVAL: | |
478 prError = PR_INVALID_STATE_ERROR; | |
479 break; | |
480 default: | |
481 _MD_win32_map_default_error(err); | |
482 return; | |
483 } | |
484 PR_SetError(prError, err); | |
485 } | |
486 | |
487 void _MD_win32_map_getpeername_error(PRInt32 err) | |
488 { | |
489 _MD_win32_map_default_error(err); | |
490 } | |
491 | |
492 void _MD_win32_map_getsockopt_error(PRInt32 err) | |
493 { | |
494 _MD_win32_map_default_error(err); | |
495 } | |
496 | |
497 void _MD_win32_map_setsockopt_error(PRInt32 err) | |
498 { | |
499 _MD_win32_map_default_error(err); | |
500 } | |
501 | |
502 void _MD_win32_map_open_error(PRInt32 err) | |
503 { | |
504 _MD_win32_map_default_error(err); | |
505 } | |
506 | |
507 void _MD_win32_map_gethostname_error(PRInt32 err) | |
508 { | |
509 _MD_win32_map_default_error(err); | |
510 } | |
511 | |
512 /* Win32 select() only works on sockets. So in this | |
513 ** context, WSAENOTSOCK is equivalent to EBADF on Unix. | |
514 */ | |
515 void _MD_win32_map_select_error(PRInt32 err) | |
516 { | |
517 PRErrorCode prError; | |
518 | |
519 switch (err) { | |
520 case WSAENOTSOCK: | |
521 prError = PR_BAD_DESCRIPTOR_ERROR; | |
522 break; | |
523 default: | |
524 _MD_win32_map_default_error(err); | |
525 return; | |
526 } | |
527 PR_SetError(prError, err); | |
528 } | |
529 | |
530 void _MD_win32_map_lockf_error(PRInt32 err) | |
531 { | |
532 _MD_win32_map_default_error(err); | |
533 } |