mariadb/storage/bdb/os_win32/os_errno.c

137 lines
2.3 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2005-12-05 10:27:46 -08:00
* Copyright (c) 1999-2005
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
2005-07-20 15:48:22 -07:00
*
2005-12-05 10:27:46 -08:00
* $Id: os_errno.c,v 12.2 2005/06/16 20:23:28 bostic Exp $
2001-03-04 19:42:05 -05:00
*/
#include "db_config.h"
#include "db_int.h"
/*
2005-07-20 15:48:22 -07:00
* __os_get_errno_ret_zero --
* Return the value of errno, even if it's zero.
2001-03-04 19:42:05 -05:00
*/
int
2005-07-20 15:48:22 -07:00
__os_get_errno_ret_zero()
2001-03-04 19:42:05 -05:00
{
/* This routine must be able to return the same value repeatedly. */
return (errno);
}
/*
2005-07-20 15:48:22 -07:00
* __os_get_errno --
2001-03-04 19:42:05 -05:00
* Return the last Windows error as an errno.
* We give generic error returns:
*
* EFAULT means Win* call failed,
* and GetLastError provided no extra info.
*
2005-07-20 15:48:22 -07:00
* EIO means error on Win* call,
2001-03-04 19:42:05 -05:00
* and we were unable to provide a meaningful errno for this Windows
* error. More information is only available by setting a breakpoint
* here.
*/
int
2005-07-20 15:48:22 -07:00
__os_get_errno()
2001-03-04 19:42:05 -05:00
{
DWORD last_error;
int ret;
last_error = GetLastError();
/*
* Take our best guess at translating some of the Windows error
* codes. We really care about only a few of these.
*/
switch (last_error) {
case ERROR_FILE_NOT_FOUND:
case ERROR_INVALID_DRIVE:
case ERROR_PATH_NOT_FOUND:
ret = ENOENT;
break;
case ERROR_NO_MORE_FILES:
case ERROR_TOO_MANY_OPEN_FILES:
ret = EMFILE;
break;
case ERROR_ACCESS_DENIED:
ret = EPERM;
break;
case ERROR_INVALID_HANDLE:
ret = EBADF;
break;
case ERROR_NOT_ENOUGH_MEMORY:
ret = ENOMEM;
break;
case ERROR_DISK_FULL:
ret = ENOSPC;
2005-07-20 15:48:22 -07:00
break;
2001-03-04 19:42:05 -05:00
case ERROR_ARENA_TRASHED:
case ERROR_BAD_COMMAND:
case ERROR_BAD_ENVIRONMENT:
case ERROR_BAD_FORMAT:
case ERROR_GEN_FAILURE:
case ERROR_INVALID_ACCESS:
case ERROR_INVALID_BLOCK:
case ERROR_INVALID_DATA:
case ERROR_READ_FAULT:
case ERROR_WRITE_FAULT:
ret = EFAULT;
break;
case ERROR_FILE_EXISTS:
2002-10-30 15:57:05 +04:00
case ERROR_ALREADY_EXISTS:
2001-03-04 19:42:05 -05:00
ret = EEXIST;
break;
case ERROR_NOT_SAME_DEVICE:
ret = EXDEV;
break;
case ERROR_WRITE_PROTECT:
ret = EACCES;
break;
2005-12-05 10:27:46 -08:00
case ERROR_LOCK_FAILED:
2001-03-04 19:42:05 -05:00
case ERROR_NOT_READY:
case ERROR_LOCK_VIOLATION:
case ERROR_SHARING_VIOLATION:
ret = EBUSY;
break;
2002-10-30 15:57:05 +04:00
case ERROR_RETRY:
ret = EINTR;
break;
2001-03-04 19:42:05 -05:00
case 0:
ret = EFAULT;
break;
default:
ret = EIO; /* Generic error. */
break;
}
return (ret);
}
2005-07-20 15:48:22 -07:00
/*
* __os_set_errno --
* Set the value of errno.
*/
void
__os_set_errno(evalue)
int evalue;
{
errno = evalue;
}