2 * msvcrt.dll errno functions
4 * Copyright 2000 Jon Griffiths
12 #include "msvcrt/conio.h"
15 DEFAULT_DEBUG_CHANNEL(msvcrt);
18 /* INTERNAL: Set the crt and dos errno's from the OS error given. */
19 void MSVCRT__set_errno(int err)
21 int *errno = GET_THREAD_VAR_PTR(errno);
22 int *doserrno = GET_THREAD_VAR_PTR(doserrno);
28 #define ERR_CASE(oserr) case oserr:
29 #define ERR_MAPS(oserr,crterr) case oserr:*errno = crterr;break;
30 ERR_CASE(ERROR_ACCESS_DENIED)
31 ERR_CASE(ERROR_NETWORK_ACCESS_DENIED)
32 ERR_CASE(ERROR_CANNOT_MAKE)
33 ERR_CASE(ERROR_SEEK_ON_DEVICE)
34 ERR_CASE(ERROR_LOCK_FAILED)
35 ERR_CASE(ERROR_FAIL_I24)
36 ERR_CASE(ERROR_CURRENT_DIRECTORY)
37 ERR_CASE(ERROR_DRIVE_LOCKED)
38 ERR_CASE(ERROR_NOT_LOCKED)
39 ERR_CASE(ERROR_INVALID_ACCESS)
40 ERR_MAPS(ERROR_LOCK_VIOLATION, MSVCRT_EACCES);
41 ERR_CASE(ERROR_FILE_NOT_FOUND)
42 ERR_CASE(ERROR_NO_MORE_FILES)
43 ERR_CASE(ERROR_BAD_PATHNAME)
44 ERR_CASE(ERROR_BAD_NETPATH)
45 ERR_CASE(ERROR_INVALID_DRIVE)
46 ERR_CASE(ERROR_BAD_NET_NAME)
47 ERR_CASE(ERROR_FILENAME_EXCED_RANGE)
48 ERR_MAPS(ERROR_PATH_NOT_FOUND, MSVCRT_ENOENT);
49 ERR_MAPS(ERROR_IO_DEVICE, MSVCRT_EIO);
50 ERR_MAPS(ERROR_BAD_FORMAT, MSVCRT_ENOEXEC);
51 ERR_MAPS(ERROR_INVALID_HANDLE, MSVCRT_EBADF);
52 ERR_CASE(ERROR_OUTOFMEMORY)
53 ERR_CASE(ERROR_INVALID_BLOCK)
54 ERR_CASE(ERROR_NOT_ENOUGH_QUOTA);
55 ERR_MAPS(ERROR_ARENA_TRASHED, MSVCRT_ENOMEM);
56 ERR_MAPS(ERROR_BUSY, MSVCRT_EBUSY);
57 ERR_CASE(ERROR_ALREADY_EXISTS)
58 ERR_MAPS(ERROR_FILE_EXISTS, MSVCRT_EEXIST);
59 ERR_MAPS(ERROR_BAD_DEVICE, MSVCRT_ENODEV);
60 ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES, MSVCRT_EMFILE);
61 ERR_MAPS(ERROR_DISK_FULL, MSVCRT_ENOSPC);
62 ERR_MAPS(ERROR_BROKEN_PIPE, MSVCRT_EPIPE);
63 ERR_MAPS(ERROR_POSSIBLE_DEADLOCK, MSVCRT_EDEADLK);
64 ERR_MAPS(ERROR_DIR_NOT_EMPTY, MSVCRT_ENOTEMPTY);
65 ERR_MAPS(ERROR_BAD_ENVIRONMENT, MSVCRT_E2BIG);
66 ERR_CASE(ERROR_WAIT_NO_CHILDREN)
67 ERR_MAPS(ERROR_CHILD_NOT_COMPLETE, MSVCRT_ECHILD);
68 ERR_CASE(ERROR_NO_PROC_SLOTS)
69 ERR_CASE(ERROR_MAX_THRDS_REACHED)
70 ERR_MAPS(ERROR_NESTING_NOT_ALLOWED, MSVCRT_EAGAIN);
72 /* Remaining cases map to EINVAL */
73 /* FIXME: may be missing some errors above */
74 *errno = MSVCRT_EINVAL;
78 /*********************************************************************
81 int* MSVCRT__errno(void)
83 return GET_THREAD_VAR_PTR(errno);
86 /*********************************************************************
87 * __doserrno (MSVCRT.@)
91 return GET_THREAD_VAR_PTR(doserrno);
94 /*********************************************************************
97 char* MSVCRT_strerror(int err)
99 return strerror(err); /* FIXME */
102 /**********************************************************************
103 * _strerror (MSVCRT.@)
105 const char* _strerror(const char* err)
107 static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
108 sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(GET_THREAD_VAR(errno)));
112 /*********************************************************************
115 void MSVCRT_perror(const char* str)
117 _cprintf("%s: %s\n",str,MSVCRT_strerror(GET_THREAD_VAR(errno)));