MCPcopy Index your code
hub / github.com/RustPython/RustPython / winerror_to_errno

Function winerror_to_errno

crates/common/src/os.rs:182–288  ·  view source on GitHub ↗
(winerror: i32)

Source from the content-addressed store, hash-verified

180// errno: https://learn.microsoft.com/cpp/c-runtime-library/errno-constants?view=msvc-170
181#[cfg(windows)]
182pub fn winerror_to_errno(winerror: i32) -> i32 {
183 use libc::*;
184 use windows_sys::Win32::{
185 Foundation::*,
186 Networking::WinSock::{
187 WSAEACCES, WSAEBADF, WSAECONNABORTED, WSAECONNREFUSED, WSAECONNRESET, WSAEFAULT,
188 WSAEINTR, WSAEINVAL, WSAEMFILE,
189 },
190 };
191 // Unwrap FACILITY_WIN32 HRESULT errors.
192 // if ((winerror & 0xFFFF0000) == 0x80070000) {
193 // winerror &= 0x0000FFFF;
194 // }
195
196 // Winsock error codes (10000-11999) are errno values.
197 if (10000..12000).contains(&winerror) {
198 match winerror {
199 WSAEINTR | WSAEBADF | WSAEACCES | WSAEFAULT | WSAEINVAL | WSAEMFILE => {
200 // Winsock definitions of errno values. See WinSock2.h
201 return winerror - 10000;
202 }
203 _ => return winerror as _,
204 }
205 }
206
207 #[allow(non_upper_case_globals)]
208 match winerror as u32 {
209 ERROR_FILE_NOT_FOUND
210 | ERROR_PATH_NOT_FOUND
211 | ERROR_INVALID_DRIVE
212 | ERROR_NO_MORE_FILES
213 | ERROR_BAD_NETPATH
214 | ERROR_BAD_NET_NAME
215 | ERROR_BAD_PATHNAME
216 | ERROR_FILENAME_EXCED_RANGE => ENOENT,
217 ERROR_BAD_ENVIRONMENT => E2BIG,
218 ERROR_BAD_FORMAT
219 | ERROR_INVALID_STARTING_CODESEG
220 | ERROR_INVALID_STACKSEG
221 | ERROR_INVALID_MODULETYPE
222 | ERROR_INVALID_EXE_SIGNATURE
223 | ERROR_EXE_MARKED_INVALID
224 | ERROR_BAD_EXE_FORMAT
225 | ERROR_ITERATED_DATA_EXCEEDS_64k
226 | ERROR_INVALID_MINALLOCSIZE
227 | ERROR_DYNLINK_FROM_INVALID_RING
228 | ERROR_IOPL_NOT_ENABLED
229 | ERROR_INVALID_SEGDPL
230 | ERROR_AUTODATASEG_EXCEEDS_64k
231 | ERROR_RING2SEG_MUST_BE_MOVABLE
232 | ERROR_RELOC_CHAIN_XEEDS_SEGLIM
233 | ERROR_INFLOOP_IN_RELOC_CHAIN => ENOEXEC,
234 ERROR_INVALID_HANDLE | ERROR_INVALID_TARGET_HANDLE | ERROR_DIRECT_ACCESS_HANDLE => EBADF,
235 ERROR_WAIT_NO_CHILDREN | ERROR_CHILD_NOT_COMPLETE => ECHILD,
236 ERROR_NO_PROC_SLOTS | ERROR_MAX_THRDS_REACHED | ERROR_NESTING_NOT_ALLOWED => EAGAIN,
237 ERROR_ARENA_TRASHED
238 | ERROR_NOT_ENOUGH_MEMORY
239 | ERROR_INVALID_BLOCK

Callers 2

set_from_windows_errFunction · 0.85
posix_errnoMethod · 0.85

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected