Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_errno.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_errno.c,v 12.2 2005/06/16 20:23:28 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #include "db_int.h"
00013 
00014 /*
00015  * __os_get_errno_ret_zero --
00016  *      Return the value of errno, even if it's zero.
00017  */
00018 int
00019 __os_get_errno_ret_zero()
00020 {
00021         /* This routine must be able to return the same value repeatedly. */
00022         return (errno);
00023 }
00024 
00025 /*
00026  * __os_get_errno --
00027  *      Return the last Windows error as an errno.
00028  *      We give generic error returns:
00029  *
00030  *      EFAULT means Win* call failed,
00031  *        and GetLastError provided no extra info.
00032  *
00033  *      EIO means error on Win* call,
00034  *        and we were unable to provide a meaningful errno for this Windows
00035  *        error.  More information is only available by setting a breakpoint
00036  *        here.
00037  */
00038 int
00039 __os_get_errno()
00040 {
00041         DWORD last_error;
00042         int ret;
00043 
00044         last_error = GetLastError();
00045 
00046         /*
00047          * Take our best guess at translating some of the Windows error
00048          * codes.  We really care about only a few of these.
00049          */
00050         switch (last_error) {
00051         case ERROR_FILE_NOT_FOUND:
00052         case ERROR_INVALID_DRIVE:
00053         case ERROR_PATH_NOT_FOUND:
00054                 ret = ENOENT;
00055                 break;
00056 
00057         case ERROR_NO_MORE_FILES:
00058         case ERROR_TOO_MANY_OPEN_FILES:
00059                 ret = EMFILE;
00060                 break;
00061 
00062         case ERROR_ACCESS_DENIED:
00063                 ret = EPERM;
00064                 break;
00065 
00066         case ERROR_INVALID_HANDLE:
00067                 ret = EBADF;
00068                 break;
00069 
00070         case ERROR_NOT_ENOUGH_MEMORY:
00071                 ret = ENOMEM;
00072                 break;
00073 
00074         case ERROR_DISK_FULL:
00075                 ret = ENOSPC;
00076                 break;
00077 
00078         case ERROR_ARENA_TRASHED:
00079         case ERROR_BAD_COMMAND:
00080         case ERROR_BAD_ENVIRONMENT:
00081         case ERROR_BAD_FORMAT:
00082         case ERROR_GEN_FAILURE:
00083         case ERROR_INVALID_ACCESS:
00084         case ERROR_INVALID_BLOCK:
00085         case ERROR_INVALID_DATA:
00086         case ERROR_READ_FAULT:
00087         case ERROR_WRITE_FAULT:
00088                 ret = EFAULT;
00089                 break;
00090 
00091         case ERROR_FILE_EXISTS:
00092         case ERROR_ALREADY_EXISTS:
00093                 ret = EEXIST;
00094                 break;
00095 
00096         case ERROR_NOT_SAME_DEVICE:
00097                 ret = EXDEV;
00098                 break;
00099 
00100         case ERROR_WRITE_PROTECT:
00101                 ret = EACCES;
00102                 break;
00103 
00104         case ERROR_LOCK_FAILED:
00105         case ERROR_NOT_READY:
00106         case ERROR_LOCK_VIOLATION:
00107         case ERROR_SHARING_VIOLATION:
00108                 ret = EBUSY;
00109                 break;
00110 
00111         case ERROR_RETRY:
00112                 ret = EINTR;
00113                 break;
00114 
00115         case 0:
00116                 ret = EFAULT;
00117                 break;
00118 
00119         default:
00120                 ret = EIO;                      /* Generic error. */
00121                 break;
00122         }
00123 
00124         return (ret);
00125 }
00126 
00127 /*
00128  * __os_set_errno --
00129  *      Set the value of errno.
00130  */
00131 void
00132 __os_set_errno(evalue)
00133         int evalue;
00134 {
00135         errno = evalue;
00136 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2