Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * msvcrt.dll errno functions |
| 3 | * |
| 4 | * Copyright 2000 Jon Griffiths |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "msvcrt.h" |
Martin Wilck | 94638aa | 2002-09-17 18:32:53 +0000 | [diff] [blame] | 22 | #include "msvcrt/errno.h" |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 23 | |
Francois Gouget | e7f75c5 | 2001-04-10 23:25:25 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <string.h> |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 26 | |
Francois Gouget | e7f75c5 | 2001-04-10 23:25:25 +0000 | [diff] [blame] | 27 | #include "msvcrt/conio.h" |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 28 | #include "msvcrt/stdlib.h" |
| 29 | #include "msvcrt/string.h" |
Francois Gouget | e7f75c5 | 2001-04-10 23:25:25 +0000 | [diff] [blame] | 30 | |
| 31 | |
Alexandre Julliard | bd1689e | 2002-01-22 00:57:16 +0000 | [diff] [blame] | 32 | #include "wine/debug.h" |
| 33 | |
| 34 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* INTERNAL: Set the crt and dos errno's from the OS error given. */ |
| 38 | void MSVCRT__set_errno(int err) |
| 39 | { |
Alexandre Julliard | 44b4235 | 2002-07-19 03:24:50 +0000 | [diff] [blame] | 40 | int *errno = MSVCRT__errno(); |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 41 | unsigned long *doserrno = MSVCRT___doserrno(); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 42 | |
| 43 | *doserrno = err; |
| 44 | |
| 45 | switch(err) |
| 46 | { |
| 47 | #define ERR_CASE(oserr) case oserr: |
| 48 | #define ERR_MAPS(oserr,crterr) case oserr:*errno = crterr;break; |
| 49 | ERR_CASE(ERROR_ACCESS_DENIED) |
| 50 | ERR_CASE(ERROR_NETWORK_ACCESS_DENIED) |
| 51 | ERR_CASE(ERROR_CANNOT_MAKE) |
| 52 | ERR_CASE(ERROR_SEEK_ON_DEVICE) |
| 53 | ERR_CASE(ERROR_LOCK_FAILED) |
| 54 | ERR_CASE(ERROR_FAIL_I24) |
| 55 | ERR_CASE(ERROR_CURRENT_DIRECTORY) |
| 56 | ERR_CASE(ERROR_DRIVE_LOCKED) |
| 57 | ERR_CASE(ERROR_NOT_LOCKED) |
| 58 | ERR_CASE(ERROR_INVALID_ACCESS) |
| 59 | ERR_MAPS(ERROR_LOCK_VIOLATION, MSVCRT_EACCES); |
| 60 | ERR_CASE(ERROR_FILE_NOT_FOUND) |
| 61 | ERR_CASE(ERROR_NO_MORE_FILES) |
| 62 | ERR_CASE(ERROR_BAD_PATHNAME) |
| 63 | ERR_CASE(ERROR_BAD_NETPATH) |
| 64 | ERR_CASE(ERROR_INVALID_DRIVE) |
| 65 | ERR_CASE(ERROR_BAD_NET_NAME) |
| 66 | ERR_CASE(ERROR_FILENAME_EXCED_RANGE) |
| 67 | ERR_MAPS(ERROR_PATH_NOT_FOUND, MSVCRT_ENOENT); |
| 68 | ERR_MAPS(ERROR_IO_DEVICE, MSVCRT_EIO); |
| 69 | ERR_MAPS(ERROR_BAD_FORMAT, MSVCRT_ENOEXEC); |
| 70 | ERR_MAPS(ERROR_INVALID_HANDLE, MSVCRT_EBADF); |
| 71 | ERR_CASE(ERROR_OUTOFMEMORY) |
| 72 | ERR_CASE(ERROR_INVALID_BLOCK) |
| 73 | ERR_CASE(ERROR_NOT_ENOUGH_QUOTA); |
| 74 | ERR_MAPS(ERROR_ARENA_TRASHED, MSVCRT_ENOMEM); |
| 75 | ERR_MAPS(ERROR_BUSY, MSVCRT_EBUSY); |
| 76 | ERR_CASE(ERROR_ALREADY_EXISTS) |
| 77 | ERR_MAPS(ERROR_FILE_EXISTS, MSVCRT_EEXIST); |
| 78 | ERR_MAPS(ERROR_BAD_DEVICE, MSVCRT_ENODEV); |
| 79 | ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES, MSVCRT_EMFILE); |
| 80 | ERR_MAPS(ERROR_DISK_FULL, MSVCRT_ENOSPC); |
| 81 | ERR_MAPS(ERROR_BROKEN_PIPE, MSVCRT_EPIPE); |
| 82 | ERR_MAPS(ERROR_POSSIBLE_DEADLOCK, MSVCRT_EDEADLK); |
| 83 | ERR_MAPS(ERROR_DIR_NOT_EMPTY, MSVCRT_ENOTEMPTY); |
| 84 | ERR_MAPS(ERROR_BAD_ENVIRONMENT, MSVCRT_E2BIG); |
| 85 | ERR_CASE(ERROR_WAIT_NO_CHILDREN) |
| 86 | ERR_MAPS(ERROR_CHILD_NOT_COMPLETE, MSVCRT_ECHILD); |
| 87 | ERR_CASE(ERROR_NO_PROC_SLOTS) |
| 88 | ERR_CASE(ERROR_MAX_THRDS_REACHED) |
| 89 | ERR_MAPS(ERROR_NESTING_NOT_ALLOWED, MSVCRT_EAGAIN); |
| 90 | default: |
| 91 | /* Remaining cases map to EINVAL */ |
| 92 | /* FIXME: may be missing some errors above */ |
| 93 | *errno = MSVCRT_EINVAL; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /********************************************************************* |
| 98 | * _errno (MSVCRT.@) |
| 99 | */ |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 100 | int* MSVCRT__errno(void) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 101 | { |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 102 | return &msvcrt_get_thread_data()->thread_errno; |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /********************************************************************* |
| 106 | * __doserrno (MSVCRT.@) |
| 107 | */ |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 108 | unsigned long* MSVCRT___doserrno(void) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 109 | { |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 110 | return &msvcrt_get_thread_data()->thread_doserrno; |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 113 | /********************************************************************* |
| 114 | * strerror (MSVCRT.@) |
| 115 | */ |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 116 | char* MSVCRT_strerror(int err) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 117 | { |
| 118 | return strerror(err); /* FIXME */ |
| 119 | } |
| 120 | |
| 121 | /********************************************************************** |
| 122 | * _strerror (MSVCRT.@) |
| 123 | */ |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 124 | char* _strerror(const char* err) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 125 | { |
| 126 | static char strerrbuff[256]; /* FIXME: Per thread, nprintf */ |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 127 | sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno)); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 128 | return strerrbuff; |
| 129 | } |
| 130 | |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 131 | /********************************************************************* |
| 132 | * perror (MSVCRT.@) |
| 133 | */ |
Francois Gouget | e7f75c5 | 2001-04-10 23:25:25 +0000 | [diff] [blame] | 134 | void MSVCRT_perror(const char* str) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 135 | { |
Hans Leidekker | 821f477 | 2004-03-16 19:17:11 +0000 | [diff] [blame] | 136 | _cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno)); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 137 | } |
André Johansen | 70d1136 | 2003-07-28 19:04:47 +0000 | [diff] [blame] | 138 | |
| 139 | /****************************************************************************** |
| 140 | * _set_error_mode (MSVCRT.@) |
| 141 | * |
| 142 | * Set the error mode, which describes where the C run-time writes error |
| 143 | * messages. |
| 144 | * |
| 145 | * PARAMS |
| 146 | * mode - the new error mode |
| 147 | * |
| 148 | * RETURNS |
| 149 | * The old error mode. |
| 150 | * |
| 151 | * TODO |
| 152 | * This function does not have a proper implementation; the error mode is |
| 153 | * never used. |
| 154 | */ |
| 155 | int _set_error_mode(int mode) |
| 156 | { |
| 157 | static int current_mode = _OUT_TO_DEFAULT; |
| 158 | |
| 159 | const int old = current_mode; |
| 160 | if ( _REPORT_ERRMODE != mode ) { |
| 161 | current_mode = mode; |
| 162 | FIXME("dummy implementation (old mode: %d, new mode: %d)\n", |
| 163 | old, mode); |
| 164 | } |
| 165 | return old; |
| 166 | } |
Alexandre Julliard | dec198a | 2004-01-13 05:45:05 +0000 | [diff] [blame] | 167 | |
| 168 | /****************************************************************************** |
| 169 | * _seterrormode (MSVCRT.@) |
| 170 | */ |
| 171 | void _seterrormode(int mode) |
| 172 | { |
| 173 | SetErrorMode( mode ); |
| 174 | } |