Back to index

lightning-sunbird  0.9+nobinonly
win32err.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file essentially replicates NSPR's source for the functions that
00004  * map system-specific error codes to NSPR error codes.  We would use 
00005  * NSPR's functions, instead of duplicating them, but they're private.
00006  * As long as SSL's server session cache code must do platform native I/O
00007  * to accomplish its job, and NSPR's error mapping functions remain private,
00008  * this code will continue to need to be replicated.
00009  * 
00010  * ***** BEGIN LICENSE BLOCK *****
00011  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00012  *
00013  * The contents of this file are subject to the Mozilla Public License Version
00014  * 1.1 (the "License"); you may not use this file except in compliance with
00015  * the License. You may obtain a copy of the License at
00016  * http://www.mozilla.org/MPL/
00017  *
00018  * Software distributed under the License is distributed on an "AS IS" basis,
00019  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00020  * for the specific language governing rights and limitations under the
00021  * License.
00022  *
00023  * The Original Code is the Netscape security libraries.
00024  *
00025  * The Initial Developer of the Original Code is
00026  * Netscape Communications Corporation.
00027  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00028  * the Initial Developer. All Rights Reserved.
00029  *
00030  * Contributor(s):
00031  *
00032  * Alternatively, the contents of this file may be used under the terms of
00033  * either the GNU General Public License Version 2 or later (the "GPL"), or
00034  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00035  * in which case the provisions of the GPL or the LGPL are applicable instead
00036  * of those above. If you wish to allow use of your version of this file only
00037  * under the terms of either the GPL or the LGPL, and not to allow others to
00038  * use your version of this file under the terms of the MPL, indicate your
00039  * decision by deleting the provisions above and replace them with the notice
00040  * and other provisions required by the GPL or the LGPL. If you do not delete
00041  * the provisions above, a recipient may use your version of this file under
00042  * the terms of any one of the MPL, the GPL or the LGPL.
00043  *
00044  * ***** END LICENSE BLOCK ***** */
00045 /* $Id: win32err.c,v 1.4 2004/04/27 23:04:39 gerv%gerv.net Exp $ */
00046 
00047 #if !defined(_WIN32_WCE)
00048 
00049 #include "prerror.h"
00050 #include "prlog.h"
00051 #include <errno.h>
00052 #include <windows.h>
00053 
00054 /*
00055  * On Win32, we map three kinds of error codes:
00056  * - GetLastError(): for Win32 functions
00057  * - WSAGetLastError(): for Winsock functions
00058  * - errno: for standard C library functions
00059  *
00060  * We do not check for WSAEINPROGRESS and WSAEINTR because we do not
00061  * use blocking Winsock 1.1 calls.
00062  *
00063  * Except for the 'socket' call, we do not check for WSAEINITIALISED.
00064  * It is assumed that if Winsock is not initialized, that fact will
00065  * be detected at the time we create new sockets.
00066  */
00067 
00068 /* forward declaration. */
00069 void nss_MD_win32_map_default_error(PRInt32 err);
00070 
00071 void nss_MD_win32_map_opendir_error(PRInt32 err)
00072 {
00073     nss_MD_win32_map_default_error(err);
00074 }
00075 
00076 void nss_MD_win32_map_closedir_error(PRInt32 err)
00077 {
00078     nss_MD_win32_map_default_error(err);
00079 }
00080 
00081 void nss_MD_win32_map_readdir_error(PRInt32 err)
00082 {
00083     nss_MD_win32_map_default_error(err);
00084 }
00085 
00086 void nss_MD_win32_map_delete_error(PRInt32 err)
00087 {
00088     nss_MD_win32_map_default_error(err);
00089 }
00090 
00091 /* The error code for stat() is in errno. */
00092 void nss_MD_win32_map_stat_error(PRInt32 err)
00093 {
00094     nss_MD_win32_map_default_error(err);
00095 }
00096 
00097 void nss_MD_win32_map_fstat_error(PRInt32 err)
00098 {
00099     nss_MD_win32_map_default_error(err);
00100 }
00101 
00102 void nss_MD_win32_map_rename_error(PRInt32 err)
00103 {
00104     nss_MD_win32_map_default_error(err);
00105 }
00106 
00107 /* The error code for access() is in errno. */
00108 void nss_MD_win32_map_access_error(PRInt32 err)
00109 {
00110     nss_MD_win32_map_default_error(err);
00111 }
00112 
00113 void nss_MD_win32_map_mkdir_error(PRInt32 err)
00114 {
00115     nss_MD_win32_map_default_error(err);
00116 }
00117 
00118 void nss_MD_win32_map_rmdir_error(PRInt32 err)
00119 {
00120     nss_MD_win32_map_default_error(err);
00121 }
00122 
00123 void nss_MD_win32_map_read_error(PRInt32 err)
00124 {
00125     nss_MD_win32_map_default_error(err);
00126 }
00127 
00128 void nss_MD_win32_map_transmitfile_error(PRInt32 err)
00129 {
00130     nss_MD_win32_map_default_error(err);
00131 }
00132 
00133 void nss_MD_win32_map_write_error(PRInt32 err)
00134 {
00135     nss_MD_win32_map_default_error(err);
00136 }
00137 
00138 void nss_MD_win32_map_lseek_error(PRInt32 err)
00139 {
00140     nss_MD_win32_map_default_error(err);
00141 }
00142 
00143 void nss_MD_win32_map_fsync_error(PRInt32 err)
00144 {
00145     nss_MD_win32_map_default_error(err);
00146 }
00147 
00148 /*
00149  * For both CloseHandle() and closesocket().
00150  */
00151 void nss_MD_win32_map_close_error(PRInt32 err)
00152 {
00153     nss_MD_win32_map_default_error(err);
00154 }
00155 
00156 void nss_MD_win32_map_socket_error(PRInt32 err)
00157 {
00158     PR_ASSERT(err != WSANOTINITIALISED);
00159     nss_MD_win32_map_default_error(err);
00160 }
00161 
00162 void nss_MD_win32_map_recv_error(PRInt32 err)
00163 {
00164     nss_MD_win32_map_default_error(err);
00165 }
00166 
00167 void nss_MD_win32_map_recvfrom_error(PRInt32 err)
00168 {
00169     nss_MD_win32_map_default_error(err);
00170 }
00171 
00172 void nss_MD_win32_map_send_error(PRInt32 err)
00173 {
00174     PRErrorCode prError;
00175     switch (err) {
00176     case WSAEMSGSIZE:       prError = PR_INVALID_ARGUMENT_ERROR; break;
00177     default:         nss_MD_win32_map_default_error(err); return;
00178     }
00179     PR_SetError(prError, err);
00180 }
00181 
00182 void nss_MD_win32_map_sendto_error(PRInt32 err)
00183 {
00184     PRErrorCode prError;
00185     switch (err) {
00186     case WSAEMSGSIZE:       prError = PR_INVALID_ARGUMENT_ERROR; break;
00187     default:         nss_MD_win32_map_default_error(err); return;
00188     }
00189     PR_SetError(prError, err);
00190 }
00191 
00192 void nss_MD_win32_map_accept_error(PRInt32 err)
00193 {
00194     PRErrorCode prError;
00195     switch (err) {
00196     case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
00197     case WSAEINVAL:  prError = PR_INVALID_STATE_ERROR; break;
00198     default:         nss_MD_win32_map_default_error(err); return;
00199     }
00200     PR_SetError(prError, err);
00201 }
00202 
00203 void nss_MD_win32_map_acceptex_error(PRInt32 err)
00204 {
00205     nss_MD_win32_map_default_error(err);
00206 }
00207 
00208 void nss_MD_win32_map_connect_error(PRInt32 err)
00209 {
00210     PRErrorCode prError;
00211     switch (err) {
00212     case WSAEWOULDBLOCK: prError = PR_IN_PROGRESS_ERROR; break;
00213     case WSAEINVAL:  prError = PR_ALREADY_INITIATED_ERROR; break;
00214     case WSAETIMEDOUT:      prError = PR_IO_TIMEOUT_ERROR; break;
00215     default:         nss_MD_win32_map_default_error(err); return;
00216     }
00217     PR_SetError(prError, err);
00218 }
00219 
00220 void nss_MD_win32_map_bind_error(PRInt32 err)
00221 {
00222     PRErrorCode prError;
00223     switch (err) {
00224     case WSAEINVAL:  prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; break;
00225     default:         nss_MD_win32_map_default_error(err); return;
00226     }
00227     PR_SetError(prError, err);
00228 }
00229 
00230 void nss_MD_win32_map_listen_error(PRInt32 err)
00231 {
00232     PRErrorCode prError;
00233     switch (err) {
00234     case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break;
00235     case WSAEINVAL:  prError = PR_INVALID_STATE_ERROR; break;
00236     default:         nss_MD_win32_map_default_error(err); return;
00237     }
00238     PR_SetError(prError, err);
00239 }
00240 
00241 void nss_MD_win32_map_shutdown_error(PRInt32 err)
00242 {
00243     nss_MD_win32_map_default_error(err);
00244 }
00245 
00246 void nss_MD_win32_map_getsockname_error(PRInt32 err)
00247 {
00248     PRErrorCode prError;
00249     switch (err) {
00250     case WSAEINVAL:  prError = PR_INVALID_STATE_ERROR; break;
00251     default:         nss_MD_win32_map_default_error(err); return;
00252     }
00253     PR_SetError(prError, err);
00254 }
00255 
00256 void nss_MD_win32_map_getpeername_error(PRInt32 err)
00257 {
00258     nss_MD_win32_map_default_error(err);
00259 }
00260 
00261 void nss_MD_win32_map_getsockopt_error(PRInt32 err)
00262 {
00263     nss_MD_win32_map_default_error(err);
00264 }
00265 
00266 void nss_MD_win32_map_setsockopt_error(PRInt32 err)
00267 {
00268     nss_MD_win32_map_default_error(err);
00269 }
00270 
00271 void nss_MD_win32_map_open_error(PRInt32 err)
00272 {
00273     nss_MD_win32_map_default_error(err);
00274 }
00275 
00276 void nss_MD_win32_map_gethostname_error(PRInt32 err)
00277 {
00278     nss_MD_win32_map_default_error(err);
00279 }
00280 
00281 /* Win32 select() only works on sockets.  So in this
00282 ** context, WSAENOTSOCK is equivalent to EBADF on Unix.  
00283 */
00284 void nss_MD_win32_map_select_error(PRInt32 err)
00285 {
00286     PRErrorCode prError;
00287     switch (err) {
00288     case WSAENOTSOCK:       prError = PR_BAD_DESCRIPTOR_ERROR; break;
00289     default:         nss_MD_win32_map_default_error(err); return;
00290     }
00291     PR_SetError(prError, err);
00292 }
00293 
00294 void nss_MD_win32_map_lockf_error(PRInt32 err)
00295 {
00296     nss_MD_win32_map_default_error(err);
00297 }
00298 
00299 
00300 
00301 void nss_MD_win32_map_default_error(PRInt32 err)
00302 {
00303     PRErrorCode prError;
00304 
00305     switch (err) {
00306     case EACCES:            prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
00307     case ENOENT:            prError = PR_FILE_NOT_FOUND_ERROR; break;
00308     case ERROR_ACCESS_DENIED:      prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
00309     case ERROR_ALREADY_EXISTS:     prError = PR_FILE_EXISTS_ERROR; break;
00310     case ERROR_DISK_CORRUPT:       prError = PR_IO_ERROR; break;
00311     case ERROR_DISK_FULL:   prError = PR_NO_DEVICE_SPACE_ERROR; break;
00312     case ERROR_DISK_OPERATION_FAILED: prError = PR_IO_ERROR; break;
00313     case ERROR_DRIVE_LOCKED:       prError = PR_FILE_IS_LOCKED_ERROR; break;
00314     case ERROR_FILENAME_EXCED_RANGE: prError = PR_NAME_TOO_LONG_ERROR; break;
00315     case ERROR_FILE_CORRUPT:       prError = PR_IO_ERROR; break;
00316     case ERROR_FILE_EXISTS:        prError = PR_FILE_EXISTS_ERROR; break;
00317     case ERROR_FILE_INVALID:       prError = PR_BAD_DESCRIPTOR_ERROR; break;
00318 #if ERROR_FILE_NOT_FOUND != ENOENT
00319     case ERROR_FILE_NOT_FOUND:     prError = PR_FILE_NOT_FOUND_ERROR; break;
00320 #endif
00321     case ERROR_HANDLE_DISK_FULL: prError = PR_NO_DEVICE_SPACE_ERROR; break;
00322     case ERROR_INVALID_ADDRESS: prError = PR_ACCESS_FAULT_ERROR; break;
00323     case ERROR_INVALID_HANDLE:     prError = PR_BAD_DESCRIPTOR_ERROR; break;
00324     case ERROR_INVALID_NAME:       prError = PR_INVALID_ARGUMENT_ERROR; break;
00325     case ERROR_INVALID_PARAMETER: prError = PR_INVALID_ARGUMENT_ERROR; break;
00326     case ERROR_INVALID_USER_BUFFER: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
00327     case ERROR_LOCKED:             prError = PR_FILE_IS_LOCKED_ERROR; break;
00328     case ERROR_NETNAME_DELETED: prError = PR_CONNECT_RESET_ERROR; break;
00329     case ERROR_NOACCESS:    prError = PR_ACCESS_FAULT_ERROR; break;
00330     case ERROR_NOT_ENOUGH_MEMORY: prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
00331     case ERROR_NOT_ENOUGH_QUOTA: prError = PR_OUT_OF_MEMORY_ERROR; break;
00332     case ERROR_NOT_READY:   prError = PR_IO_ERROR; break;
00333     case ERROR_NO_MORE_FILES:      prError = PR_NO_MORE_FILES_ERROR; break;
00334     case ERROR_OPEN_FAILED:        prError = PR_IO_ERROR; break;
00335     case ERROR_OPEN_FILES:  prError = PR_IO_ERROR; break;
00336     case ERROR_OUTOFMEMORY:        prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
00337     case ERROR_PATH_BUSY:   prError = PR_IO_ERROR; break;
00338     case ERROR_PATH_NOT_FOUND:     prError = PR_FILE_NOT_FOUND_ERROR; break;
00339     case ERROR_SEEK_ON_DEVICE:     prError = PR_IO_ERROR; break;
00340     case ERROR_SHARING_VIOLATION: prError = PR_FILE_IS_BUSY_ERROR; break;
00341     case ERROR_STACK_OVERFLOW:     prError = PR_ACCESS_FAULT_ERROR; break;
00342     case ERROR_TOO_MANY_OPEN_FILES: prError = PR_SYS_DESC_TABLE_FULL_ERROR; break;
00343     case ERROR_WRITE_PROTECT:      prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
00344     case WSAEACCES:         prError = PR_NO_ACCESS_RIGHTS_ERROR; break;
00345     case WSAEADDRINUSE:     prError = PR_ADDRESS_IN_USE_ERROR; break;
00346     case WSAEADDRNOTAVAIL:  prError = PR_ADDRESS_NOT_AVAILABLE_ERROR; break;
00347     case WSAEAFNOSUPPORT:   prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break;
00348     case WSAEALREADY:              prError = PR_ALREADY_INITIATED_ERROR; break;
00349     case WSAEBADF:          prError = PR_BAD_DESCRIPTOR_ERROR; break;
00350     case WSAECONNABORTED:   prError = PR_CONNECT_ABORTED_ERROR; break;
00351     case WSAECONNREFUSED:   prError = PR_CONNECT_REFUSED_ERROR; break;
00352     case WSAECONNRESET:     prError = PR_CONNECT_RESET_ERROR; break;
00353     case WSAEDESTADDRREQ:   prError = PR_INVALID_ARGUMENT_ERROR; break;
00354     case WSAEFAULT:         prError = PR_ACCESS_FAULT_ERROR; break;
00355     case WSAEHOSTUNREACH:   prError = PR_HOST_UNREACHABLE_ERROR; break;
00356     case WSAEINVAL:         prError = PR_INVALID_ARGUMENT_ERROR; break;
00357     case WSAEISCONN:               prError = PR_IS_CONNECTED_ERROR; break;
00358     case WSAEMFILE:         prError = PR_PROC_DESC_TABLE_FULL_ERROR; break;
00359     case WSAEMSGSIZE:              prError = PR_BUFFER_OVERFLOW_ERROR; break;
00360     case WSAENETDOWN:              prError = PR_NETWORK_DOWN_ERROR; break;
00361     case WSAENETRESET:             prError = PR_CONNECT_ABORTED_ERROR; break;
00362     case WSAENETUNREACH:    prError = PR_NETWORK_UNREACHABLE_ERROR; break;
00363     case WSAENOBUFS:               prError = PR_INSUFFICIENT_RESOURCES_ERROR; break;
00364     case WSAENOPROTOOPT:    prError = PR_INVALID_ARGUMENT_ERROR; break;
00365     case WSAENOTCONN:              prError = PR_NOT_CONNECTED_ERROR; break;
00366     case WSAENOTSOCK:              prError = PR_NOT_SOCKET_ERROR; break;
00367     case WSAEOPNOTSUPP:     prError = PR_OPERATION_NOT_SUPPORTED_ERROR; break;
00368     case WSAEPROTONOSUPPORT:       prError = PR_PROTOCOL_NOT_SUPPORTED_ERROR; break;
00369     case WSAEPROTOTYPE:     prError = PR_INVALID_ARGUMENT_ERROR; break;
00370     case WSAESHUTDOWN:             prError = PR_SOCKET_SHUTDOWN_ERROR; break;
00371     case WSAESOCKTNOSUPPORT:       prError = PR_INVALID_ARGUMENT_ERROR; break;
00372     case WSAETIMEDOUT:             prError = PR_CONNECT_ABORTED_ERROR; break;
00373     case WSAEWOULDBLOCK:    prError = PR_WOULD_BLOCK_ERROR; break;
00374     default:                prError = PR_UNKNOWN_ERROR; break;
00375     }
00376     PR_SetError(prError, err);
00377 }
00378 
00379 #endif