mariadb/bdb/os_win32/os_errno.c

146 lines
2.5 KiB
C
Raw Normal View History

2001-03-05 01:42:05 +01:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 12:57:05 +01:00
* Copyright (c) 1999-2002
2001-03-05 01:42:05 +01:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 12:57:05 +01:00
static const char revid[] = "$Id: os_errno.c,v 11.10 2002/07/12 04:05:00 mjc Exp $";
2001-03-05 01:42:05 +01:00
#endif /* not lint */
#include "db_int.h"
/*
* __os_get_errno --
* Return the value of errno.
*/
int
__os_get_errno()
{
/* This routine must be able to return the same value repeatedly. */
return (errno);
}
/*
* __os_set_errno --
* Set the value of errno.
*/
void
__os_set_errno(evalue)
int evalue;
{
errno = evalue;
}
/*
* __os_win32_errno --
* Return the last Windows error as an errno.
* We give generic error returns:
*
* EFAULT means Win* call failed,
* and GetLastError provided no extra info.
*
* EIO means error on Win* call.
* and we were unable to provide a meaningful errno for this Windows
* error. More information is only available by setting a breakpoint
* here.
*
* PUBLIC: #if defined(DB_WIN32)
* PUBLIC: int __os_win32_errno __P((void));
* PUBLIC: #endif
*/
int
__os_win32_errno(void)
{
DWORD last_error;
int ret;
2002-10-30 12:57:05 +01:00
/* Ignore errno - we used to check it here. */
2001-03-05 01:42:05 +01:00
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;
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 12:57:05 +01:00
case ERROR_ALREADY_EXISTS:
2001-03-05 01:42:05 +01:00
ret = EEXIST;
break;
case ERROR_NOT_SAME_DEVICE:
ret = EXDEV;
break;
case ERROR_WRITE_PROTECT:
ret = EACCES;
break;
case ERROR_NOT_READY:
ret = EBUSY;
break;
case ERROR_LOCK_VIOLATION:
case ERROR_SHARING_VIOLATION:
ret = EBUSY;
break;
2002-10-30 12:57:05 +01:00
case ERROR_RETRY:
ret = EINTR;
break;
2001-03-05 01:42:05 +01:00
case 0:
ret = EFAULT;
break;
default:
ret = EIO; /* Generic error. */
break;
}
return (ret);
}