Main Page | File List | Globals

src/errno.c

Go to the documentation of this file.
00001 /*
00002      This file is part of PlibC.
00003      (C) 2005 Nils Durner (and other contributing authors)
00004 
00005            This library is free software; you can redistribute it and/or
00006            modify it under the terms of the GNU Lesser General Public
00007            License as published by the Free Software Foundation; either
00008            version 2.1 of the License, or (at your option) any later version.
00009         
00010            This library is distributed in the hope that it will be useful,
00011            but WITHOUT ANY WARRANTY; without even the implied warranty of
00012            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013            Lesser General Public License for more details.
00014         
00015            You should have received a copy of the GNU Lesser General Public
00016            License along with this library; if not, write to the Free Software
00017            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00025 #include "plibc_private.h"
00026 
00031 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine)
00032 {
00033   switch(lWinError)
00034   {
00035     case ERROR_SUCCESS:
00036       errno = 0;
00037       break;
00038 
00039     case ERROR_INVALID_FUNCTION:
00040       errno = EBADRQC;
00041       break;
00042 
00043     case ERROR_FILE_NOT_FOUND:
00044       errno = ENOENT;
00045       break;
00046 
00047     case ERROR_PATH_NOT_FOUND:
00048       errno = ENOENT;
00049       break;
00050 
00051     case ERROR_TOO_MANY_OPEN_FILES:
00052       errno = EMFILE;
00053       break;
00054 
00055     case ERROR_ACCESS_DENIED:
00056       errno = EACCES;
00057       break;
00058 
00059     case ERROR_INVALID_HANDLE:
00060       errno = EBADF;
00061       break;
00062 
00063     case ERROR_NOT_ENOUGH_MEMORY:
00064       errno = ENOMEM;
00065       break;
00066 
00067     case ERROR_INVALID_DATA:
00068       errno = EINVAL;
00069       break;
00070 
00071     case ERROR_OUTOFMEMORY:
00072       errno = ENOMEM;
00073       break;
00074 
00075     case ERROR_INVALID_DRIVE:
00076       errno = ENODEV;
00077       break;
00078 
00079     case ERROR_NOT_SAME_DEVICE:
00080       errno = EXDEV;
00081       break;
00082 
00083     case ERROR_NO_MORE_FILES:
00084       errno = ENMFILE;
00085       break;
00086 
00087     case ERROR_WRITE_PROTECT:
00088       errno = EROFS;
00089       break;
00090 
00091     case ERROR_BAD_UNIT:
00092       errno = ENODEV;
00093       break;
00094 
00095     case ERROR_SHARING_VIOLATION:
00096       errno = EACCES;
00097       break;
00098 
00099     case ERROR_LOCK_VIOLATION:
00100       errno = EACCES;
00101       break;
00102 
00103     case ERROR_SHARING_BUFFER_EXCEEDED:
00104       errno = ENOLCK;
00105       break;
00106 
00107     case ERROR_HANDLE_EOF:
00108       errno = ENODATA;
00109       break;
00110 
00111     case ERROR_HANDLE_DISK_FULL:
00112       errno = ENOSPC;
00113       break;
00114 
00115     case ERROR_NOT_SUPPORTED:
00116       errno = ENOSYS;
00117       break;
00118 
00119     case ERROR_REM_NOT_LIST:
00120       errno = ENONET;
00121       break;
00122 
00123     case ERROR_DUP_NAME:
00124       errno = ENOTUNIQ;
00125       break;
00126 
00127     case ERROR_BAD_NETPATH:
00128       errno = ENOSHARE;
00129       break;
00130 
00131     case ERROR_BAD_NET_NAME:
00132       errno = ENOSHARE;
00133       break;
00134 
00135     case ERROR_FILE_EXISTS:
00136       errno = EEXIST;
00137       break;
00138 
00139     case ERROR_CANNOT_MAKE:
00140       errno = EPERM;
00141       break;
00142 
00143     case ERROR_INVALID_PARAMETER:
00144       errno = EINVAL;
00145       break;
00146 
00147     case ERROR_NO_PROC_SLOTS:
00148       errno = EAGAIN;
00149       break;
00150 
00151     case ERROR_BROKEN_PIPE:
00152       errno = EPIPE;
00153       break;
00154 
00155     case ERROR_OPEN_FAILED:
00156       errno = EIO;
00157       break;
00158 
00159     case ERROR_NO_MORE_SEARCH_HANDLES:
00160       errno = ENFILE;
00161       break;
00162 
00163     case ERROR_CALL_NOT_IMPLEMENTED:
00164       errno = ENOSYS;
00165       break;
00166 
00167     case ERROR_INVALID_NAME:
00168       errno = ENOENT;
00169       break;
00170 
00171     case ERROR_WAIT_NO_CHILDREN:
00172       errno = ECHILD;
00173       break;
00174 
00175     case ERROR_CHILD_NOT_COMPLETE:
00176       errno = EBUSY;
00177       break;
00178 
00179     case ERROR_DIR_NOT_EMPTY:
00180       errno = ENOTEMPTY;
00181       break;
00182 
00183     case ERROR_SIGNAL_REFUSED:
00184       errno = EIO;
00185       break;
00186 
00187     case ERROR_BAD_PATHNAME:
00188       errno = ENOENT;
00189       break;
00190 
00191     case ERROR_SIGNAL_PENDING:
00192       errno = EBUSY;
00193       break;
00194 
00195     case ERROR_MAX_THRDS_REACHED:
00196       errno = EAGAIN;
00197       break;
00198 
00199     case ERROR_BUSY:
00200       errno = EBUSY;
00201       break;
00202 
00203     case ERROR_ALREADY_EXISTS:
00204       errno = EEXIST;
00205       break;
00206 
00207     case ERROR_NO_SIGNAL_SENT:
00208       errno = EIO;
00209       break;
00210 
00211     case ERROR_FILENAME_EXCED_RANGE:
00212       errno = EINVAL;
00213       break;
00214 
00215     case ERROR_META_EXPANSION_TOO_LONG:
00216       errno = EINVAL;
00217       break;
00218 
00219     case ERROR_INVALID_SIGNAL_NUMBER:
00220       errno = EINVAL;
00221       break;
00222 
00223     case ERROR_THREAD_1_INACTIVE:
00224       errno = EINVAL;
00225       break;
00226 
00227     case ERROR_BAD_PIPE:
00228       errno = EINVAL;
00229       break;
00230 
00231     case ERROR_PIPE_BUSY:
00232       errno = EBUSY;
00233       break;
00234 
00235     case ERROR_NO_DATA:
00236       errno = EPIPE;
00237       break;
00238 
00239     case ERROR_PIPE_NOT_CONNECTED:
00240       errno = ECOMM;
00241       break;
00242 
00243     case ERROR_MORE_DATA:
00244       errno = EAGAIN;
00245       break;
00246 
00247     case ERROR_DIRECTORY:
00248       errno = ENOTDIR;
00249       break;
00250 
00251     case ERROR_PIPE_CONNECTED:
00252       errno = EBUSY;
00253       break;
00254 
00255     case ERROR_PIPE_LISTENING:
00256       errno = ECOMM;
00257       break;
00258 
00259     case ERROR_NO_TOKEN:
00260       errno = EINVAL;
00261       break;
00262 
00263     case ERROR_PROCESS_ABORTED:
00264       errno = EFAULT;
00265       break;
00266 
00267     case ERROR_BAD_DEVICE:
00268       errno = ENODEV;
00269       break;
00270 
00271     case ERROR_BAD_USERNAME:
00272       errno = EINVAL;
00273       break;
00274 
00275     case ERROR_NOT_CONNECTED:
00276       errno = ENOLINK;
00277       break;
00278 
00279     case ERROR_OPEN_FILES:
00280       errno = EAGAIN;
00281       break;
00282 
00283     case ERROR_ACTIVE_CONNECTIONS:
00284       errno = EAGAIN;
00285       break;
00286 
00287     case ERROR_DEVICE_IN_USE:
00288       errno = EAGAIN;
00289       break;
00290 
00291     case ERROR_INVALID_AT_INTERRUPT_TIME:
00292       errno = EINTR;
00293       break;
00294 
00295     case ERROR_IO_DEVICE:
00296       errno = EIO;
00297       break;
00298 
00299     case ERROR_NOT_OWNER:
00300       errno = EPERM;
00301       break;
00302 
00303     case ERROR_END_OF_MEDIA:
00304       errno = ENOSPC;
00305       break;
00306 
00307     case ERROR_EOM_OVERFLOW:
00308       errno = ENOSPC;
00309       break;
00310 
00311     case ERROR_BEGINNING_OF_MEDIA:
00312       errno = ESPIPE;
00313       break;
00314 
00315     case ERROR_SETMARK_DETECTED:
00316       errno = ESPIPE;
00317       break;
00318 
00319     case ERROR_NO_DATA_DETECTED:
00320       errno = ENOSPC;
00321       break;
00322 
00323     case ERROR_POSSIBLE_DEADLOCK:
00324       errno = EDEADLOCK;
00325       break;
00326 
00327     case ERROR_CRC:
00328       errno = EIO;
00329       break;
00330 
00331     case ERROR_NEGATIVE_SEEK:
00332       errno = EINVAL;
00333       break;
00334 
00335     case ERROR_NOT_READY:
00336       errno = ENOMEDIUM;
00337       break;
00338 
00339     case ERROR_DISK_FULL:
00340       errno = ENOSPC;
00341       break;
00342 
00343     case ERROR_NOACCESS:
00344       errno = EFAULT;
00345       break;
00346 
00347     case ERROR_FILE_INVALID:
00348       errno = ENXIO;
00349       break;
00350 
00351     case ERROR_INVALID_ADDRESS:
00352       errno = EFAULT;
00353       break;
00354 
00355     case ERROR_BUFFER_OVERFLOW:
00356       errno = ENOMEM;
00357       break;
00358 
00359     case ERROR_SERVICE_DOES_NOT_EXIST:
00360       errno = ESRCH;
00361       break;
00362 
00363     case ERROR_SERVICE_EXISTS:
00364       errno = EEXIST;
00365       break;
00366 
00367     default:
00368         {
00369                 char szPanic[1001];
00370                 
00371               errno = ESTALE;
00372               _win_snprintf(szPanic, 1000, "Unknown error %i in PlibC "\
00373                         "SetErrnoFromWinError(). Source: %s:%i\n", lWinError, pszCaller,
00374                         iLine);
00375               szPanic[1000] = 0;
00376               __plibc_panic(3, szPanic);
00377               break;
00378         }
00379   }
00380 }
00381 
00386 void SetErrnoFromWinsockError(long lWinError)
00387 {
00388   switch(lWinError)
00389   {
00390     case 0:
00391       errno = 0;
00392       break;
00393     case WSAEINTR:
00394       errno = EINTR;
00395       break;
00396 
00397     case WSAEWOULDBLOCK:
00398       errno = EWOULDBLOCK;
00399       break;
00400 
00401     case WSAEINPROGRESS:
00402       errno = EINPROGRESS;
00403       break;
00404 
00405     case WSAEALREADY:
00406       errno = EALREADY;
00407       break;
00408 
00409     case WSAENOTSOCK:
00410       errno = ENOTSOCK;
00411       break;
00412 
00413     case WSAEDESTADDRREQ:
00414       errno = EDESTADDRREQ;
00415       break;
00416 
00417     case WSAEMSGSIZE:
00418       errno = EMSGSIZE;
00419       break;
00420 
00421     case WSAEPROTOTYPE:
00422       errno = EPROTOTYPE;
00423       break;
00424 
00425     case WSAENOPROTOOPT:
00426       errno = ENOPROTOOPT;
00427       break;
00428 
00429     case WSAEPROTONOSUPPORT:
00430       errno = EPROTONOSUPPORT;
00431       break;
00432 
00433     case WSAESOCKTNOSUPPORT:
00434       errno = ESOCKTNOSUPPORT;
00435       break;
00436 
00437     case WSAEOPNOTSUPP:
00438       errno = EOPNOTSUPP;
00439       break;
00440 
00441     case WSAEPFNOSUPPORT:
00442       errno = EPFNOSUPPORT;
00443       break;
00444 
00445     case WSAEAFNOSUPPORT:
00446       errno = EAFNOSUPPORT;
00447       break;
00448 
00449     case WSAEADDRINUSE:
00450       errno = EADDRINUSE;
00451       break;
00452 
00453     case WSAEADDRNOTAVAIL:
00454       errno = EADDRNOTAVAIL;
00455       break;
00456 
00457     case WSAENETDOWN:
00458       errno = ENETDOWN;
00459       break;
00460 
00461     case WSAENETUNREACH:
00462       errno = ENETUNREACH;
00463       break;
00464 
00465     case WSAENETRESET:
00466       errno = ENETRESET;
00467       break;
00468 
00469     case WSAECONNABORTED:
00470       errno = ECONNABORTED;
00471       break;
00472 
00473     case WSAECONNRESET:
00474       errno = ECONNRESET;
00475       break;
00476 
00477     case WSAENOBUFS:
00478       errno = ENOBUFS;
00479       break;
00480 
00481     case WSAEISCONN:
00482       errno = EISCONN;
00483       break;
00484 
00485     case WSAENOTCONN:
00486       errno = ENOTCONN;
00487       break;
00488 
00489     case WSAESHUTDOWN:
00490       errno = ESHUTDOWN;
00491       break;
00492 
00493     case WSAETOOMANYREFS:
00494       errno = ETOOMANYREFS;
00495       break;
00496 
00497     case WSAETIMEDOUT:
00498       errno = ETIMEDOUT;
00499       break;
00500 
00501     case WSAECONNREFUSED:
00502       errno = ECONNREFUSED;
00503       break;
00504 
00505     case WSAELOOP:
00506       errno = ELOOP;
00507       break;
00508 
00509     case WSAENAMETOOLONG:
00510       errno = ENAMETOOLONG;
00511       break;
00512 
00513     case WSAEHOSTDOWN:
00514       errno = EHOSTDOWN;
00515       break;
00516 
00517     case WSAEHOSTUNREACH:
00518       errno = EHOSTUNREACH;
00519       break;
00520 
00521     case WSAENOTEMPTY:
00522       errno = ENOTEMPTY;
00523       break;
00524 
00525     case WSAEPROCLIM:
00526       errno = EPROCLIM;
00527       break;
00528 
00529     case WSAEUSERS:
00530       errno = EUSERS;
00531       break;
00532 
00533     case WSAEDQUOT:
00534       errno = EDQUOT;
00535       break;
00536 
00537     case WSAESTALE:
00538       errno = ESTALE;
00539       break;
00540 
00541     case WSAEREMOTE:
00542       errno = EREMOTE;
00543       break;
00544 
00545     case WSAEINVAL:
00546       errno = EINVAL;
00547       break;
00548 
00549     case WSAEFAULT:
00550       errno = EFAULT;
00551       break;
00552       
00553     case WSANO_DATA:
00554         errno = ENODATA;
00555         break;
00556 
00557     default:
00558         {
00559                 char szPanic[1001];
00560                 
00561               errno = ESTALE;
00562               _win_snprintf(szPanic, 1000, "Unknown error %i in " \
00563                         "SetErrnoFromWinsockError()", lWinError);
00564               szPanic[1000] = 0;
00565                 __plibc_panic(4, szPanic);
00566                 
00567               break;
00568         }
00569   }
00570 }
00571 
00575 void SetErrnoFromHRESULT(HRESULT hRes)
00576 {
00577   switch(hRes)
00578   {
00579     case NOERROR:
00580       errno = 0;
00581       break;
00582     case E_UNEXPECTED:
00583     case E_FAIL:
00584     case S_FALSE:
00585       errno = ESTALE;
00586     case E_NOTIMPL:
00587       errno = ENOSYS;
00588       break;
00589     case E_OUTOFMEMORY:
00590       errno = ENOMEM;
00591       break;
00592     case E_INVALIDARG:
00593     case E_NOINTERFACE:
00594       errno = EINVAL;
00595       break;
00596     case E_POINTER:
00597     case E_ABORT:
00598       errno = EFAULT;
00599       break;
00600     case E_HANDLE:
00601       errno = EBADF;
00602       break;
00603     case E_ACCESSDENIED:
00604       errno = EACCES;
00605       break;
00606     case E_PENDING:
00607       errno = EBUSY;
00608       break;
00609     default:
00610       SetErrnoFromWinError(HRESULT_CODE(hRes));
00611   }
00612 }
00613 
00618 void SetHErrnoFromWinError(long lWinError)
00619 {
00620   switch(lWinError)
00621   {
00622     case WSAHOST_NOT_FOUND:
00623       /* h_errno is defined as WSAGetLastError */
00624       WSASetLastError(HOST_NOT_FOUND);
00625       break;
00626 
00627     case WSATRY_AGAIN:
00628       WSASetLastError(TRY_AGAIN);
00629       break;
00630 
00631     case WSANO_RECOVERY:
00632       WSASetLastError(NO_RECOVERY);
00633       break;
00634 
00635     case WSANO_DATA:
00636       WSASetLastError(NO_DATA);
00637       break;
00638   }
00639 }
00640 
00641 /* end of errno.c */

Generated on Sun Sep 4 11:16:46 2005 for PlibC by  doxygen 1.4.2