2 * msvcrt.dll errno functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
30 /* INTERNAL: Set the crt and dos errno's from the OS error given. */
31 void msvcrt_set_errno(int err)
33 int *errno = MSVCRT__errno();
34 unsigned long *doserrno = MSVCRT___doserrno();
40 #define ERR_CASE(oserr) case oserr:
41 #define ERR_MAPS(oserr,crterr) case oserr:*errno = crterr;break;
42 ERR_CASE(ERROR_ACCESS_DENIED)
43 ERR_CASE(ERROR_NETWORK_ACCESS_DENIED)
44 ERR_CASE(ERROR_CANNOT_MAKE)
45 ERR_CASE(ERROR_SEEK_ON_DEVICE)
46 ERR_CASE(ERROR_LOCK_FAILED)
47 ERR_CASE(ERROR_FAIL_I24)
48 ERR_CASE(ERROR_CURRENT_DIRECTORY)
49 ERR_CASE(ERROR_DRIVE_LOCKED)
50 ERR_CASE(ERROR_NOT_LOCKED)
51 ERR_CASE(ERROR_INVALID_ACCESS)
52 ERR_MAPS(ERROR_LOCK_VIOLATION, MSVCRT_EACCES);
53 ERR_CASE(ERROR_FILE_NOT_FOUND)
54 ERR_CASE(ERROR_NO_MORE_FILES)
55 ERR_CASE(ERROR_BAD_PATHNAME)
56 ERR_CASE(ERROR_BAD_NETPATH)
57 ERR_CASE(ERROR_INVALID_DRIVE)
58 ERR_CASE(ERROR_BAD_NET_NAME)
59 ERR_CASE(ERROR_FILENAME_EXCED_RANGE)
60 ERR_MAPS(ERROR_PATH_NOT_FOUND, MSVCRT_ENOENT);
61 ERR_MAPS(ERROR_IO_DEVICE, MSVCRT_EIO);
62 ERR_MAPS(ERROR_BAD_FORMAT, MSVCRT_ENOEXEC);
63 ERR_MAPS(ERROR_INVALID_HANDLE, MSVCRT_EBADF);
64 ERR_CASE(ERROR_OUTOFMEMORY)
65 ERR_CASE(ERROR_INVALID_BLOCK)
66 ERR_CASE(ERROR_NOT_ENOUGH_QUOTA);
67 ERR_MAPS(ERROR_ARENA_TRASHED, MSVCRT_ENOMEM);
68 ERR_MAPS(ERROR_BUSY, MSVCRT_EBUSY);
69 ERR_CASE(ERROR_ALREADY_EXISTS)
70 ERR_MAPS(ERROR_FILE_EXISTS, MSVCRT_EEXIST);
71 ERR_MAPS(ERROR_BAD_DEVICE, MSVCRT_ENODEV);
72 ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES, MSVCRT_EMFILE);
73 ERR_MAPS(ERROR_DISK_FULL, MSVCRT_ENOSPC);
74 ERR_MAPS(ERROR_BROKEN_PIPE, MSVCRT_EPIPE);
75 ERR_MAPS(ERROR_POSSIBLE_DEADLOCK, MSVCRT_EDEADLK);
76 ERR_MAPS(ERROR_DIR_NOT_EMPTY, MSVCRT_ENOTEMPTY);
77 ERR_MAPS(ERROR_BAD_ENVIRONMENT, MSVCRT_E2BIG);
78 ERR_CASE(ERROR_WAIT_NO_CHILDREN)
79 ERR_MAPS(ERROR_CHILD_NOT_COMPLETE, MSVCRT_ECHILD);
80 ERR_CASE(ERROR_NO_PROC_SLOTS)
81 ERR_CASE(ERROR_MAX_THRDS_REACHED)
82 ERR_MAPS(ERROR_NESTING_NOT_ALLOWED, MSVCRT_EAGAIN);
84 /* Remaining cases map to EINVAL */
85 /* FIXME: may be missing some errors above */
86 *errno = MSVCRT_EINVAL;
90 /*********************************************************************
93 int* MSVCRT__errno(void)
95 return &msvcrt_get_thread_data()->thread_errno;
98 /*********************************************************************
99 * __doserrno (MSVCRT.@)
101 unsigned long* MSVCRT___doserrno(void)
103 return &msvcrt_get_thread_data()->thread_doserrno;
106 /*********************************************************************
107 * strerror (MSVCRT.@)
109 char* MSVCRT_strerror(int err)
111 return strerror(err); /* FIXME */
114 /**********************************************************************
115 * _strerror (MSVCRT.@)
117 char* _strerror(const char* err)
119 static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
120 sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
124 /*********************************************************************
127 void MSVCRT_perror(const char* str)
129 _cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
132 /******************************************************************************
133 * _set_error_mode (MSVCRT.@)
135 * Set the error mode, which describes where the C run-time writes error
139 * mode - the new error mode
142 * The old error mode.
145 * This function does not have a proper implementation; the error mode is
148 int _set_error_mode(int mode)
150 static int current_mode = MSVCRT__OUT_TO_DEFAULT;
152 const int old = current_mode;
153 if ( MSVCRT__REPORT_ERRMODE != mode ) {
155 FIXME("dummy implementation (old mode: %d, new mode: %d)\n",
161 /******************************************************************************
162 * _seterrormode (MSVCRT.@)
164 void _seterrormode(int mode)
166 SetErrorMode( mode );