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