Back to index

lightning-sunbird  0.9+nobinonly
os2_errors.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "prerror.h"
00039 #include "primpl.h"
00040 
00041 void _MD_os2_map_default_error(PRInt32 err)
00042 {
00043        switch (err) {
00044               case EWOULDBLOCK:
00045                      PR_SetError(PR_WOULD_BLOCK_ERROR, err);
00046                      break;
00047               case EBADF:
00048                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00049                      break;
00050               case ENOTSOCK:
00051                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00052                      break;
00053               case EMSGSIZE:
00054               case EINVAL:
00055                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00056                      break;
00057               case ENOBUFS:
00058                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00059                      break;
00060               case ECONNREFUSED:
00061                      PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
00062                      break;
00063               case EISCONN:
00064                      PR_SetError(PR_IS_CONNECTED_ERROR, err);
00065                      break;
00066 #ifdef SOCEFAULT
00067               case SOCEFAULT:
00068                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00069                      break;
00070 #endif
00071               case ERROR_NETNAME_DELETED:
00072                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00073                      break;
00074               default:
00075                      PR_SetError(PR_UNKNOWN_ERROR, err);
00076                      break;
00077        }
00078 }
00079 void _MD_os2_map_opendir_error(PRInt32 err)
00080 {
00081        switch (err) {
00082               case ERROR_FILE_NOT_FOUND:
00083               case ERROR_PATH_NOT_FOUND:
00084                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00085                      break;
00086               case ERROR_ACCESS_DENIED:
00087                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00088                      break;
00089       case ERROR_INVALID_ADDRESS:
00090       case ERROR_INVALID_ACCESS:
00091                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00092                      break;
00093       case ERROR_INVALID_NAME:
00094       case ERROR_INVALID_PARAMETER:
00095                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00096                      break;
00097       case ERROR_TOO_MANY_OPEN_FILES:
00098               case ERROR_NOT_DOS_DISK:
00099               case ERROR_NOT_READY:
00100               case ERROR_OPEN_FAILED:
00101       case ERROR_PATH_BUSY:
00102       case ERROR_CANNOT_MAKE:
00103                      PR_SetError(PR_IO_ERROR, err);
00104                      break;
00105       case ERROR_DRIVE_LOCKED:
00106       case ERROR_DEVICE_IN_USE:
00107                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00108                      break;
00109               case ERROR_FILENAME_EXCED_RANGE:
00110                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
00111                      break;
00112               case ERROR_NOT_ENOUGH_MEMORY:
00113               case ERROR_SHARING_BUFFER_EXCEEDED:
00114                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00115                      break;
00116               default:
00117                      PR_SetError(PR_UNKNOWN_ERROR, err);
00118                      break;
00119        }
00120 }
00121 
00122 void _MD_os2_map_closedir_error(PRInt32 err)
00123 {
00124        switch (err) {
00125       case ERROR_FILE_NOT_FOUND:
00126       case ERROR_ACCESS_DENIED:
00127               case ERROR_INVALID_HANDLE:
00128                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00129                      break;
00130               default:
00131                      PR_SetError(PR_UNKNOWN_ERROR, err);
00132                      break;
00133        }
00134 }
00135 
00136 void _MD_os2_readdir_error(PRInt32 err)
00137 {
00138 
00139        switch (err) {
00140               case ERROR_NO_MORE_FILES:
00141                      PR_SetError(PR_NO_MORE_FILES_ERROR, err);
00142                      break;
00143               case ERROR_FILE_NOT_FOUND:
00144               case ERROR_INVALID_HANDLE:
00145                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00146                      break;
00147               case ERROR_INVALID_ADDRESS:
00148                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00149                      break;
00150               case ERROR_NOT_DOS_DISK:
00151               case ERROR_LOCK_VIOLATION:
00152               case ERROR_BROKEN_PIPE:
00153               case ERROR_NOT_READY:
00154                      PR_SetError(PR_IO_ERROR, err);
00155                      break;
00156               case ERROR_NOT_ENOUGH_MEMORY:
00157       case ERROR_MORE_DATA:
00158                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00159                      break;
00160               default:
00161                      PR_SetError(PR_UNKNOWN_ERROR, err);
00162                      break;
00163        }
00164 }
00165 
00166 void _MD_os2_map_delete_error(PRInt32 err)
00167 {
00168        switch (err) {
00169               case ERROR_FILE_NOT_FOUND:
00170               case ERROR_PATH_NOT_FOUND:
00171                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00172                      break;
00173               case ERROR_ACCESS_DENIED:
00174               case ERROR_WRITE_PROTECT:
00175                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00176                      break;
00177               case ERROR_INVALID_ADDRESS:
00178                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00179                      break;
00180               case ERROR_DRIVE_LOCKED:
00181               case ERROR_LOCKED:
00182               case ERROR_SHARING_VIOLATION:
00183                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00184                      break;
00185               default:
00186                      PR_SetError(PR_UNKNOWN_ERROR, err);
00187                      break;
00188        }
00189 }
00190 
00191 /* The error code for stat() is in errno. */
00192 void _MD_os2_map_stat_error(PRInt32 err)
00193 {
00194     switch (err) {
00195         case ENOENT:
00196             PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00197             break;
00198         case EACCES:
00199             PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00200             break;
00201         default:
00202             PR_SetError(PR_UNKNOWN_ERROR, err);
00203     }
00204 }
00205 
00206 void _MD_os2_map_fstat_error(PRInt32 err)
00207 {
00208        switch (err) {
00209               case ERROR_ACCESS_DENIED:
00210                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00211                      break;
00212               case ERROR_INVALID_HANDLE:
00213                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00214                      break;
00215               case ERROR_INVALID_ADDRESS:
00216                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00217                      break;
00218               case ERROR_NOT_READY:
00219               case ERROR_PATH_BUSY:
00220                      PR_SetError(PR_IO_ERROR, err);
00221                      break;
00222               case ERROR_NOT_ENOUGH_MEMORY:
00223               case ERROR_MORE_DATA:
00224                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00225                      break;
00226               case ERROR_DRIVE_LOCKED:
00227               case ERROR_LOCKED:
00228                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00229                      break;
00230               default:
00231                      PR_SetError(PR_UNKNOWN_ERROR, err);
00232                      break;
00233        }
00234 }
00235 
00236 void _MD_os2_map_rename_error(PRInt32 err)
00237 {
00238        switch (err) {
00239               case ERROR_FILE_NOT_FOUND:
00240               case ERROR_PATH_NOT_FOUND:
00241                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00242                      break;
00243               case ERROR_ACCESS_DENIED:
00244                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00245                      break;
00246               case ERROR_INVALID_ADDRESS:
00247                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00248                      break;
00249               case ERROR_INVALID_NAME:
00250                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00251                      break;
00252               case ERROR_NOT_READY:
00253               case ERROR_PATH_BUSY:
00254                      PR_SetError(PR_IO_ERROR, err);
00255                      break;
00256               case ERROR_DRIVE_LOCKED:
00257                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00258                      break;
00259               case ERROR_FILENAME_EXCED_RANGE:
00260                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
00261                      break;
00262               case ERROR_NOT_ENOUGH_MEMORY:
00263               case ERROR_MORE_DATA:
00264                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00265                      break;
00266               case ERROR_ALREADY_EXISTS:
00267               case ERROR_FILE_EXISTS:
00268                      PR_SetError(PR_FILE_EXISTS_ERROR, err);
00269                      break;
00270               default:
00271                      PR_SetError(PR_UNKNOWN_ERROR, err);
00272                      break;
00273        }
00274 }
00275 
00276 /* The error code for access() is in errno. */
00277 void _MD_os2_map_access_error(PRInt32 err)
00278 {
00279     switch (err) {
00280         case ENOENT:
00281             PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00282             break;
00283         case EACCES:
00284             PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00285             break;
00286         default:
00287             PR_SetError(PR_UNKNOWN_ERROR, err);
00288     }
00289 }
00290 
00291 void _MD_os2_map_mkdir_error(PRInt32 err)
00292 {
00293        switch (err) {
00294               case ERROR_ALREADY_EXISTS:
00295               case ERROR_FILE_EXISTS:
00296                      PR_SetError(PR_FILE_EXISTS_ERROR, err);
00297                      break;
00298               case ERROR_FILE_NOT_FOUND:
00299                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00300                      break;
00301               case ERROR_ACCESS_DENIED:
00302                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00303                      break;
00304               case ERROR_INVALID_ADDRESS:
00305                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00306                      break;
00307               case ERROR_INVALID_NAME:
00308                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00309                      break;
00310               case ERROR_NOT_READY:
00311               case ERROR_PATH_BUSY:
00312                      PR_SetError(PR_IO_ERROR, err);
00313                      break;
00314               case ERROR_DRIVE_LOCKED:
00315                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00316                      break;
00317               case ERROR_FILENAME_EXCED_RANGE:
00318                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
00319                      break;
00320               case ERROR_TOO_MANY_OPEN_FILES:
00321                      PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
00322                      break;
00323               case ERROR_PATH_NOT_FOUND:
00324                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00325                      break;
00326               case ERROR_NOT_ENOUGH_MEMORY:
00327               case ERROR_MORE_DATA:
00328                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00329                      break;
00330               case ERROR_DISK_FULL:
00331               case ERROR_HANDLE_DISK_FULL:
00332                      PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
00333                      break;
00334               case ERROR_WRITE_PROTECT:
00335                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00336                      break;
00337               default:
00338                      PR_SetError(PR_UNKNOWN_ERROR, err);
00339                      break;
00340        }
00341 }
00342 
00343 void _MD_os2_map_rmdir_error(PRInt32 err)
00344 {
00345 
00346        switch (err) {
00347               case ERROR_FILE_NOT_FOUND:
00348                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00349                      break;
00350               case ERROR_ACCESS_DENIED:
00351                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00352                      break;
00353               case ERROR_INVALID_ADDRESS:
00354                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00355                      break;
00356               case ERROR_INVALID_NAME:
00357                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00358                      break;
00359               case ERROR_NOT_READY:
00360               case ERROR_PATH_BUSY:
00361                      PR_SetError(PR_IO_ERROR, err);
00362                      break;
00363               case ERROR_DRIVE_LOCKED:
00364                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00365                      break;
00366               case ERROR_FILENAME_EXCED_RANGE:
00367                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
00368                      break;
00369               case ERROR_TOO_MANY_OPEN_FILES:
00370                      PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
00371                      break;
00372               case ERROR_PATH_NOT_FOUND:
00373                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00374                      break;
00375               case ERROR_NOT_ENOUGH_MEMORY:
00376               case ERROR_MORE_DATA:
00377                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00378                      break;
00379               case ERROR_WRITE_PROTECT:
00380                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00381                      break;
00382               default:
00383                      PR_SetError(PR_UNKNOWN_ERROR, err);
00384                      break;
00385        }
00386 }
00387 
00388 void _MD_os2_map_read_error(PRInt32 err)
00389 {
00390        switch (err) {
00391               case ERROR_ACCESS_DENIED:
00392                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00393                      break;
00394               case ERROR_INVALID_HANDLE:
00395                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00396                      break;
00397               case ERROR_INVALID_ADDRESS:
00398                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00399                      break;
00400               case ERROR_NOT_READY:
00401               case ERROR_PATH_BUSY:
00402                      PR_SetError(PR_IO_ERROR, err);
00403                      break;
00404               case ERROR_NOT_ENOUGH_MEMORY:
00405               case ERROR_MORE_DATA:
00406                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00407                      break;
00408               case ERROR_DRIVE_LOCKED:
00409               case ERROR_LOCKED:
00410               case ERROR_SHARING_VIOLATION:
00411                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00412                      break;
00413               case ERROR_NETNAME_DELETED:
00414                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00415                      break;
00416               case EBADF:
00417                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00418                      break; 
00419               case ENOTSOCK:
00420                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00421                      break;
00422 #ifdef SOCEFAULT
00423               case SOCEFAULT:
00424                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00425                      break;
00426 #endif
00427               default:
00428                      PR_SetError(PR_UNKNOWN_ERROR, err);
00429                      break;
00430        }
00431 }
00432 
00433 void _MD_os2_map_transmitfile_error(PRInt32 err)
00434 {
00435        switch (err) {
00436               case ERROR_ACCESS_DENIED:
00437                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00438                      break;
00439               case ERROR_INVALID_HANDLE:
00440                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00441                      break;
00442               case ERROR_INVALID_ADDRESS:
00443                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00444                      break;
00445               case ERROR_NOT_READY:
00446               case ERROR_PATH_BUSY:
00447                      PR_SetError(PR_IO_ERROR, err);
00448                      break;
00449               case ERROR_NOT_ENOUGH_MEMORY:
00450               case ERROR_MORE_DATA:
00451                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00452                      break;
00453               case ERROR_DRIVE_LOCKED:
00454               case ERROR_LOCKED:
00455               case ERROR_SHARING_VIOLATION:
00456                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00457                      break;
00458               case ERROR_FILENAME_EXCED_RANGE:
00459                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
00460                      break;
00461               case ERROR_TOO_MANY_OPEN_FILES:
00462                      PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
00463                      break;
00464               case ERROR_PATH_NOT_FOUND:
00465                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
00466                      break;
00467               case EBADF:
00468                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00469                      break;
00470               case ENOTSOCK:
00471                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00472                      break;
00473 #ifdef SOCEFAULT
00474               case SOCEFAULT:
00475                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00476                      break;
00477 #endif
00478               default:
00479                      PR_SetError(PR_UNKNOWN_ERROR, err);
00480                      break;
00481        }
00482 }
00483 
00484 void _MD_os2_map_write_error(PRInt32 err)
00485 {
00486        switch (err) {
00487               case ERROR_ACCESS_DENIED:
00488               case ERROR_WRITE_PROTECT:
00489                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00490                      break;
00491               case ERROR_INVALID_HANDLE:
00492                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00493                      break;
00494               case ERROR_INVALID_ADDRESS:
00495                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00496                      break;
00497               case ERROR_NOT_READY:
00498               case ERROR_PATH_BUSY:
00499                      PR_SetError(PR_IO_ERROR, err);
00500                      break;
00501               case ERROR_DRIVE_LOCKED:
00502               case ERROR_LOCKED:
00503               case ERROR_SHARING_VIOLATION:
00504                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
00505                      break;
00506               case ERROR_NOT_ENOUGH_MEMORY:
00507               case ERROR_MORE_DATA:
00508               case ERROR_DISK_FULL:
00509       case ERROR_HANDLE_DISK_FULL:
00510       case ENOSPC:
00511                      PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
00512                      break;
00513               case ERROR_NETNAME_DELETED:
00514                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00515                      break;
00516               case EBADF:
00517                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00518                      break;
00519               case ENOTSOCK:
00520                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00521                      break;
00522               case EMSGSIZE:
00523               case EINVAL:
00524                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00525                      break;
00526               case ENOBUFS:
00527                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00528                      break;
00529               case ECONNREFUSED:
00530                      PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
00531                      break;
00532               case EISCONN:
00533                      PR_SetError(PR_IS_CONNECTED_ERROR, err);
00534                      break;
00535 #ifdef SOCEFAULT
00536               case SOCEFAULT:
00537                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00538                      break;
00539 #endif
00540               default:
00541                      PR_SetError(PR_UNKNOWN_ERROR, err);
00542                      break;
00543        }
00544 }
00545 
00546 void _MD_os2_map_lseek_error(PRInt32 err)
00547 {
00548        switch (err) {
00549               case ERROR_INVALID_HANDLE:
00550                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00551                      break;
00552               case ERROR_SEEK_ON_DEVICE:
00553                      PR_SetError(PR_IO_ERROR, err);
00554                      break;
00555               default:
00556                      PR_SetError(PR_UNKNOWN_ERROR, err);
00557                      break;
00558        }
00559 }
00560 
00561 void _MD_os2_map_fsync_error(PRInt32 err)
00562 {
00563        switch (err) {
00564               case ERROR_ACCESS_DENIED:
00565               case ERROR_WRITE_PROTECT:
00566                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00567                      break;
00568               case ERROR_INVALID_HANDLE:
00569                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00570                      break;
00571               case ERROR_NOT_ENOUGH_MEMORY:
00572               case ERROR_MORE_DATA:
00573                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00574                      break;
00575               case ERROR_DISK_FULL:
00576               case ERROR_HANDLE_DISK_FULL:
00577                      PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
00578                      break;
00579               default:
00580                      PR_SetError(PR_UNKNOWN_ERROR, err);
00581                      break;
00582        }
00583 }
00584 
00585 void _MD_os2_map_close_error(PRInt32 err)
00586 {
00587        switch (err) {
00588               case ERROR_INVALID_HANDLE:
00589               case EBADF:
00590                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00591                      break;
00592               case ERROR_NOT_READY:
00593               case ERROR_PATH_BUSY:
00594                      PR_SetError(PR_IO_ERROR, err);
00595                      break;
00596               default:
00597                      PR_SetError(PR_UNKNOWN_ERROR, err);
00598                      break;
00599        }
00600 }
00601 
00602 void _MD_os2_map_socket_error(PRInt32 err)
00603 {
00604        switch (err) {
00605               case EPROTONOSUPPORT:
00606                      PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
00607                      break;
00608               case EACCES:
00609                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00610                      break;
00611               case ERROR_NOT_ENOUGH_MEMORY:
00612               case ERROR_MORE_DATA:
00613               case ENOBUFS:
00614                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00615                      break;
00616               default:
00617                      PR_SetError(PR_UNKNOWN_ERROR, err);
00618                      break;
00619        }
00620 }
00621 
00622 void _MD_os2_map_recv_error(PRInt32 err)
00623 {
00624        switch (err) {
00625               case EWOULDBLOCK:
00626                      PR_SetError(PR_WOULD_BLOCK_ERROR, err);
00627                      break;
00628               case EBADF:
00629                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00630                      break;
00631               case ENOTSOCK:
00632                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00633                      break;
00634 #ifdef SOCEFAULT
00635               case SOCEFAULT:
00636                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00637                      break;
00638 #endif
00639               case ERROR_NETNAME_DELETED:
00640                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00641                      break;
00642               default:
00643                      PR_SetError(PR_UNKNOWN_ERROR, err);
00644                      break;
00645        }
00646 }
00647 
00648 void _MD_os2_map_recvfrom_error(PRInt32 err)
00649 {
00650        switch (err) {
00651               case EWOULDBLOCK:
00652                      PR_SetError(PR_WOULD_BLOCK_ERROR, err);
00653                      break;
00654               case EBADF:
00655                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00656                      break;
00657               case ENOTSOCK:
00658                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00659                      break;
00660 #ifdef SOCEFAULT
00661               case SOCEFAULT:
00662                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00663                      break;
00664 #endif
00665               case ERROR_NETNAME_DELETED:
00666                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00667                      break;
00668               default:
00669                      PR_SetError(PR_UNKNOWN_ERROR, err);
00670                      break;
00671        }
00672 }
00673 
00674 void _MD_os2_map_send_error(PRInt32 err)
00675 {
00676        switch (err) {
00677               case EWOULDBLOCK:
00678                      PR_SetError(PR_WOULD_BLOCK_ERROR, err);
00679                      break;
00680               case EBADF:
00681                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00682                      break;
00683               case ENOTSOCK:
00684                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00685                      break;
00686               case EMSGSIZE:
00687               case EINVAL:
00688                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00689                      break;
00690               case ENOBUFS:
00691                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00692                      break;
00693               case ECONNREFUSED:
00694                      PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
00695                      break;
00696               case EISCONN:
00697                      PR_SetError(PR_IS_CONNECTED_ERROR, err);
00698                      break;
00699 #ifdef SOCEFAULT
00700               case SOCEFAULT:
00701                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00702                      break;
00703 #endif
00704               case ERROR_NETNAME_DELETED:
00705                      PR_SetError(PR_CONNECT_RESET_ERROR, err);
00706                      break;
00707               default:
00708                      PR_SetError(PR_UNKNOWN_ERROR, err);
00709                      break;
00710        }
00711 }
00712 
00713 void _MD_os2_map_sendto_error(PRInt32 err)
00714 {
00715   _MD_os2_map_default_error(err);
00716 }
00717 
00718 void _MD_os2_map_writev_error(int err)
00719 {
00720   _MD_os2_map_default_error(err);
00721 }
00722 
00723 void _MD_os2_map_accept_error(PRInt32 err)
00724 {
00725   _MD_os2_map_default_error(err);
00726 }
00727 
00728 void _MD_os2_map_acceptex_error(PRInt32 err)
00729 {
00730        switch (err) {
00731               case ERROR_INVALID_HANDLE:
00732                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00733                      break;
00734               case ERROR_INVALID_ADDRESS:
00735                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00736                      break;
00737               case ERROR_NOT_ENOUGH_MEMORY:
00738               case ERROR_MORE_DATA:
00739                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00740                      break;
00741               default:
00742                      PR_SetError(PR_UNKNOWN_ERROR, err);
00743                      break;
00744        }
00745 }
00746 
00747 /*
00748  * An error code of 0 means that the nonblocking connect succeeded.
00749  */
00750 
00751 int _MD_os2_get_nonblocking_connect_error(int osfd)
00752 {
00753     int err;
00754     int len = sizeof(err);
00755     if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == -1) {
00756         return sock_errno();
00757     } else {
00758         return err;
00759     }
00760 }
00761 
00762 void _MD_os2_map_connect_error(PRInt32 err)
00763 {
00764        switch (err) {
00765        case EWOULDBLOCK:
00766                      PR_SetError(PR_WOULD_BLOCK_ERROR, err);
00767                      break;
00768         case EINPROGRESS:
00769                      PR_SetError(PR_IN_PROGRESS_ERROR, err);
00770                      break;
00771               case EALREADY:
00772               case EINVAL:
00773                      PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
00774                      break;
00775               case EBADF:
00776                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00777                      break;
00778               case EADDRNOTAVAIL:
00779                      PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
00780                      break;
00781               case ENOTSOCK:
00782                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00783                      break;
00784               case EAFNOSUPPORT:
00785                      PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
00786                      break;
00787               case ETIMEDOUT:
00788                      PR_SetError(PR_IO_TIMEOUT_ERROR, err);
00789                      break;
00790               case ECONNREFUSED:
00791                      PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
00792                      break;
00793               case ENETUNREACH:
00794                      PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
00795                      break;
00796               case EADDRINUSE:
00797                      PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
00798                      break;
00799       case EISCONN:
00800          PR_SetError(PR_IS_CONNECTED_ERROR, err);
00801          break;
00802 #ifdef SOCEFAULT
00803               case SOCEFAULT:
00804                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00805                      break;
00806 #endif
00807               default:
00808                      PR_SetError(PR_UNKNOWN_ERROR, err);
00809                      break;
00810        }
00811 }
00812 
00813 void _MD_os2_map_bind_error(PRInt32 err)
00814 {
00815        switch (err) {
00816               case EBADF:
00817                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00818                      break;
00819               case ENOTSOCK:
00820                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00821                      break;
00822 #ifdef SOCEFAULT
00823               case SOCEFAULT:
00824                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00825                      break;
00826 #endif
00827               case EADDRNOTAVAIL:
00828                      PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
00829                      break;
00830               case EADDRINUSE:
00831                      PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
00832                      break;
00833               case EACCES:
00834                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
00835                      break;
00836               case EINVAL:
00837                      PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
00838                      break;
00839               default:
00840                      PR_SetError(PR_UNKNOWN_ERROR, err);
00841                      break;
00842        }
00843 }
00844 
00845 void _MD_os2_map_listen_error(PRInt32 err)
00846 {
00847        switch (err) {
00848               case EBADF:
00849                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00850                      break;
00851               case ENOTSOCK:
00852                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00853                      break;
00854               case EOPNOTSUPP:
00855                      PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
00856                      break;
00857               default:
00858                      PR_SetError(PR_UNKNOWN_ERROR, err);
00859                      break;
00860        }
00861 }
00862 
00863 void _MD_os2_map_shutdown_error(PRInt32 err)
00864 {
00865        switch (err) {
00866               case EBADF:
00867                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00868                      break;
00869               case ENOTSOCK:
00870                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00871                      break;
00872               case ENOTCONN:
00873                      PR_SetError(PR_NOT_CONNECTED_ERROR, err);
00874                      break;
00875               default:
00876                      PR_SetError(PR_UNKNOWN_ERROR, err);
00877                      break;
00878        }
00879 }
00880 
00881 #ifndef XP_OS2_VACPP
00882 void _MD_os2_map_socketpair_error(PRInt32 err)
00883 {
00884   switch (err) {
00885     case ENOMEM:
00886       PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00887       break;
00888     case EAFNOSUPPORT:
00889       PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
00890       break;
00891     case EPROTONOSUPPORT:
00892       PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
00893       break;
00894     case EOPNOTSUPP:
00895       PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
00896       break;
00897     case EPROTOTYPE:
00898       PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
00899       break;
00900     default:
00901       _MD_os2_map_default_error(err);
00902       return;
00903   }
00904 }
00905 #endif
00906 
00907 void _MD_os2_map_getsockname_error(PRInt32 err)
00908 {
00909        switch (err) {
00910               case EBADF:
00911                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00912                      break;
00913               case ENOTSOCK:
00914                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00915                      break;
00916 #ifdef SOCEFAULT
00917               case SOCEFAULT:
00918                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00919                      break;
00920 #endif
00921               case ENOBUFS:
00922                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00923                      break;
00924               default:
00925                      PR_SetError(PR_UNKNOWN_ERROR, err);
00926                      break;
00927        }
00928 }
00929 
00930 void _MD_os2_map_getpeername_error(PRInt32 err)
00931 {
00932 
00933        switch (err) {
00934               case EBADF:
00935                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00936                      break;
00937               case ENOTSOCK:
00938                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00939                      break;
00940               case ENOTCONN:
00941                      PR_SetError(PR_NOT_CONNECTED_ERROR, err);
00942                      break;
00943 #ifdef SOCEFAULT
00944               case SOCEFAULT:
00945                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00946                      break;
00947 #endif
00948               case ENOBUFS:
00949                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
00950                      break;
00951               default:
00952                      PR_SetError(PR_UNKNOWN_ERROR, err);
00953                      break;
00954        }
00955 }
00956 
00957 void _MD_os2_map_getsockopt_error(PRInt32 err)
00958 {
00959        switch (err) {
00960               case EBADF:
00961                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00962                      break;
00963               case ENOTSOCK:
00964                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00965                      break;
00966               case ENOPROTOOPT:
00967                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00968                      break;
00969 #ifdef SOCEFAULT
00970               case SOCEFAULT:
00971                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00972                      break;
00973 #endif
00974               case EINVAL:
00975                      PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
00976                      break;
00977               default:
00978                      PR_SetError(PR_UNKNOWN_ERROR, err);
00979                      break;
00980        }
00981 }
00982 
00983 void _MD_os2_map_setsockopt_error(PRInt32 err)
00984 {
00985        switch (err) {
00986               case EBADF:
00987                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
00988                      break;
00989               case ENOTSOCK:
00990                      PR_SetError(PR_NOT_SOCKET_ERROR, err);
00991                      break;
00992               case ENOPROTOOPT:
00993                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
00994                      break;
00995 #ifdef SOCEFAULT
00996               case SOCEFAULT:
00997                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
00998                      break;
00999 #endif
01000               case EINVAL:
01001                      PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
01002                      break;
01003               default:
01004                      PR_SetError(PR_UNKNOWN_ERROR, err);
01005                      break;
01006        }
01007 }
01008 
01009 void _MD_os2_map_open_error(PRInt32 err)
01010 {
01011        switch (err) {
01012               case ERROR_ALREADY_EXISTS:
01013               case ERROR_FILE_EXISTS:
01014                      PR_SetError(PR_FILE_EXISTS_ERROR, err);
01015                      break;
01016               case ERROR_FILE_NOT_FOUND:
01017                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
01018                      break;
01019               case ERROR_ACCESS_DENIED:
01020                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
01021                      break;
01022               case ERROR_INVALID_ADDRESS:
01023                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
01024                      break;
01025               case ERROR_INVALID_NAME:
01026                      PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
01027                      break;
01028               case ERROR_NOT_READY:
01029               case ERROR_OPEN_FAILED:
01030               case ERROR_PATH_BUSY:
01031                      PR_SetError(PR_IO_ERROR, err);
01032                      break;
01033               case ERROR_DRIVE_LOCKED:
01034                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
01035                      break;
01036               case ERROR_FILENAME_EXCED_RANGE:
01037                      PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
01038                      break;
01039               case ERROR_TOO_MANY_OPEN_FILES:
01040                      PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
01041                      break;
01042               case ERROR_PATH_NOT_FOUND:
01043                      PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
01044                      break;
01045               case ERROR_NOT_ENOUGH_MEMORY:
01046               case ERROR_MORE_DATA:
01047                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
01048                      break;
01049               case ERROR_DISK_FULL:
01050               case ERROR_HANDLE_DISK_FULL:
01051                      PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
01052                      break;
01053               case ERROR_WRITE_PROTECT:
01054                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
01055                      break;
01056               default:
01057                      PR_SetError(PR_UNKNOWN_ERROR, err);
01058                      break;
01059        }
01060 }
01061 
01062 void _MD_os2_map_gethostname_error(PRInt32 err)
01063 {
01064     switch (err) {
01065 #ifdef SOCEFAULT
01066               case SOCEFAULT:
01067                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
01068                      break;
01069 #endif
01070               case ENETDOWN:
01071               case EINPROGRESS:
01072               default:
01073                      PR_SetError(PR_UNKNOWN_ERROR, err);
01074                      break;
01075     }
01076 }
01077 
01078 void _MD_os2_map_select_error(PRInt32 err)
01079 {
01080     PRErrorCode prerror;
01081 
01082     switch (err) {
01083         /*
01084          * OS/2 select() only works on sockets.  So in this
01085          * context, ENOTSOCK is equivalent to EBADF on Unix.
01086          */
01087         case ENOTSOCK:
01088             prerror = PR_BAD_DESCRIPTOR_ERROR;
01089             break;
01090         case EINVAL:
01091             prerror = PR_INVALID_ARGUMENT_ERROR;
01092             break;
01093 #ifdef SOCEFAULT
01094         case SOCEFAULT:
01095             prerror = PR_ACCESS_FAULT_ERROR;
01096             break;
01097 #endif
01098         default:
01099             prerror = PR_UNKNOWN_ERROR;
01100     }
01101     PR_SetError(prerror, err);
01102 }
01103 
01104 void _MD_os2_map_lockf_error(PRInt32 err)
01105 {
01106     switch (err) {
01107               case ERROR_ACCESS_DENIED:
01108                      PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
01109                      break;
01110               case ERROR_INVALID_HANDLE:
01111                      PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
01112                      break;
01113               case ERROR_INVALID_ADDRESS:
01114                      PR_SetError(PR_ACCESS_FAULT_ERROR, err);
01115                      break;
01116               case ERROR_DRIVE_LOCKED:
01117               case ERROR_LOCKED:
01118               case ERROR_SHARING_VIOLATION:
01119                      PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
01120                      break;
01121               case ERROR_NOT_ENOUGH_MEMORY:
01122               case ERROR_MORE_DATA:
01123                      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
01124                      break;
01125               default:
01126                      PR_SetError(PR_UNKNOWN_ERROR, err);
01127                      break;
01128     }
01129 }