2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll errno functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2004-06-25 03:19:15 +02:00
|
|
|
#include "msvcrt.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* INTERNAL: Set the crt and dos errno's from the OS error given. */
|
2004-06-25 03:19:15 +02:00
|
|
|
void msvcrt_set_errno(int err)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
int *errno = MSVCRT__errno();
|
2004-03-16 20:17:11 +01:00
|
|
|
unsigned long *doserrno = MSVCRT___doserrno();
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
*doserrno = err;
|
|
|
|
|
|
|
|
switch(err)
|
|
|
|
{
|
|
|
|
#define ERR_CASE(oserr) case oserr:
|
|
|
|
#define ERR_MAPS(oserr,crterr) case oserr:*errno = crterr;break;
|
|
|
|
ERR_CASE(ERROR_ACCESS_DENIED)
|
|
|
|
ERR_CASE(ERROR_NETWORK_ACCESS_DENIED)
|
|
|
|
ERR_CASE(ERROR_CANNOT_MAKE)
|
|
|
|
ERR_CASE(ERROR_SEEK_ON_DEVICE)
|
|
|
|
ERR_CASE(ERROR_LOCK_FAILED)
|
|
|
|
ERR_CASE(ERROR_FAIL_I24)
|
|
|
|
ERR_CASE(ERROR_CURRENT_DIRECTORY)
|
|
|
|
ERR_CASE(ERROR_DRIVE_LOCKED)
|
|
|
|
ERR_CASE(ERROR_NOT_LOCKED)
|
|
|
|
ERR_CASE(ERROR_INVALID_ACCESS)
|
|
|
|
ERR_MAPS(ERROR_LOCK_VIOLATION, MSVCRT_EACCES);
|
|
|
|
ERR_CASE(ERROR_FILE_NOT_FOUND)
|
|
|
|
ERR_CASE(ERROR_NO_MORE_FILES)
|
|
|
|
ERR_CASE(ERROR_BAD_PATHNAME)
|
|
|
|
ERR_CASE(ERROR_BAD_NETPATH)
|
|
|
|
ERR_CASE(ERROR_INVALID_DRIVE)
|
|
|
|
ERR_CASE(ERROR_BAD_NET_NAME)
|
|
|
|
ERR_CASE(ERROR_FILENAME_EXCED_RANGE)
|
|
|
|
ERR_MAPS(ERROR_PATH_NOT_FOUND, MSVCRT_ENOENT);
|
|
|
|
ERR_MAPS(ERROR_IO_DEVICE, MSVCRT_EIO);
|
|
|
|
ERR_MAPS(ERROR_BAD_FORMAT, MSVCRT_ENOEXEC);
|
|
|
|
ERR_MAPS(ERROR_INVALID_HANDLE, MSVCRT_EBADF);
|
|
|
|
ERR_CASE(ERROR_OUTOFMEMORY)
|
|
|
|
ERR_CASE(ERROR_INVALID_BLOCK)
|
|
|
|
ERR_CASE(ERROR_NOT_ENOUGH_QUOTA);
|
|
|
|
ERR_MAPS(ERROR_ARENA_TRASHED, MSVCRT_ENOMEM);
|
|
|
|
ERR_MAPS(ERROR_BUSY, MSVCRT_EBUSY);
|
|
|
|
ERR_CASE(ERROR_ALREADY_EXISTS)
|
|
|
|
ERR_MAPS(ERROR_FILE_EXISTS, MSVCRT_EEXIST);
|
|
|
|
ERR_MAPS(ERROR_BAD_DEVICE, MSVCRT_ENODEV);
|
|
|
|
ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES, MSVCRT_EMFILE);
|
|
|
|
ERR_MAPS(ERROR_DISK_FULL, MSVCRT_ENOSPC);
|
|
|
|
ERR_MAPS(ERROR_BROKEN_PIPE, MSVCRT_EPIPE);
|
|
|
|
ERR_MAPS(ERROR_POSSIBLE_DEADLOCK, MSVCRT_EDEADLK);
|
|
|
|
ERR_MAPS(ERROR_DIR_NOT_EMPTY, MSVCRT_ENOTEMPTY);
|
|
|
|
ERR_MAPS(ERROR_BAD_ENVIRONMENT, MSVCRT_E2BIG);
|
|
|
|
ERR_CASE(ERROR_WAIT_NO_CHILDREN)
|
|
|
|
ERR_MAPS(ERROR_CHILD_NOT_COMPLETE, MSVCRT_ECHILD);
|
|
|
|
ERR_CASE(ERROR_NO_PROC_SLOTS)
|
|
|
|
ERR_CASE(ERROR_MAX_THRDS_REACHED)
|
|
|
|
ERR_MAPS(ERROR_NESTING_NOT_ALLOWED, MSVCRT_EAGAIN);
|
|
|
|
default:
|
|
|
|
/* Remaining cases map to EINVAL */
|
|
|
|
/* FIXME: may be missing some errors above */
|
|
|
|
*errno = MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _errno (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int* MSVCRT__errno(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-16 20:17:11 +01:00
|
|
|
return &msvcrt_get_thread_data()->thread_errno;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __doserrno (MSVCRT.@)
|
|
|
|
*/
|
2004-03-16 20:17:11 +01:00
|
|
|
unsigned long* MSVCRT___doserrno(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-16 20:17:11 +01:00
|
|
|
return &msvcrt_get_thread_data()->thread_doserrno;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strerror (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* MSVCRT_strerror(int err)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return strerror(err); /* FIXME */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* _strerror (MSVCRT.@)
|
|
|
|
*/
|
2001-07-18 23:04:23 +02:00
|
|
|
char* _strerror(const char* err)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
|
2004-03-16 20:17:11 +01:00
|
|
|
sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
|
2001-01-11 00:59:25 +01:00
|
|
|
return strerrbuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* perror (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
void MSVCRT_perror(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-16 20:17:11 +01:00
|
|
|
_cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2003-07-28 21:04:47 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* _set_error_mode (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Set the error mode, which describes where the C run-time writes error
|
|
|
|
* messages.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* mode - the new error mode
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The old error mode.
|
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
* This function does not have a proper implementation; the error mode is
|
|
|
|
* never used.
|
|
|
|
*/
|
|
|
|
int _set_error_mode(int mode)
|
|
|
|
{
|
2004-06-25 03:19:15 +02:00
|
|
|
static int current_mode = MSVCRT__OUT_TO_DEFAULT;
|
2003-07-28 21:04:47 +02:00
|
|
|
|
|
|
|
const int old = current_mode;
|
2004-06-25 03:19:15 +02:00
|
|
|
if ( MSVCRT__REPORT_ERRMODE != mode ) {
|
2003-07-28 21:04:47 +02:00
|
|
|
current_mode = mode;
|
|
|
|
FIXME("dummy implementation (old mode: %d, new mode: %d)\n",
|
|
|
|
old, mode);
|
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
2004-01-13 06:45:05 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* _seterrormode (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void _seterrormode(int mode)
|
|
|
|
{
|
|
|
|
SetErrorMode( mode );
|
|
|
|
}
|