Rollup merge of #126194 - ChrisDenton:winerror, r=Mark-Simulacrum · model-checking/verify-rust-std@c5da756 (original) (raw)
`@@ -18,7 +18,8 @@ use crate::sys::{c, cvt, Align8};
`
18
18
`use crate::sys_common::{AsInner, FromInner, IntoInner};
`
19
19
`use crate::thread;
`
20
20
``
21
``
`-
use super::{api, to_u16s, IoResult};
`
``
21
`+
use super::api::{self, WinError};
`
``
22
`+
use super::{to_u16s, IoResult};
`
22
23
`use crate::sys::path::maybe_verbatim;
`
23
24
``
24
25
`pub struct File {
`
`@@ -130,10 +131,11 @@ impl Iterator for ReadDir {
`
130
131
`let mut wfd = mem::zeroed();
`
131
132
`loop {
`
132
133
`if c::FindNextFileW(self.handle.0, &mut wfd) == 0 {
`
133
``
`-
if api::get_last_error().code == c::ERROR_NO_MORE_FILES {
`
134
``
`-
return None;
`
135
``
`-
} else {
`
136
``
`-
return Some(Err(Error::last_os_error()));
`
``
134
`+
match api::get_last_error() {
`
``
135
`+
WinError::NO_MORE_FILES => return None,
`
``
136
`+
WinError { code } => {
`
``
137
`+
return Some(Err(Error::from_raw_os_error(code as i32)));
`
``
138
`+
}
`
137
139
`}
`
138
140
`}
`
139
141
`if let Some(e) = DirEntry::new(&self.root, &wfd) {
`
`@@ -244,8 +246,6 @@ impl OpenOptions {
`
244
246
`}
`
245
247
``
246
248
`fn get_access_mode(&self) -> io::Result<c::DWORD> {
`
247
``
`-
const ERROR_INVALID_PARAMETER: i32 = 87;
`
248
``
-
249
249
`match (self.read, self.write, self.append, self.access_mode) {
`
250
250
`(.., Some(mode)) => Ok(mode),
`
251
251
`(true, false, false, None) => Ok(c::GENERIC_READ),
`
`@@ -255,23 +255,23 @@ impl OpenOptions {
`
255
255
`(true, _, true, None) => {
`
256
256
`Ok(c::GENERIC_READ | (c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA))
`
257
257
`}
`
258
``
`-
(false, false, false, None) => Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER)),
`
``
258
`+
(false, false, false, None) => {
`
``
259
`+
Err(Error::from_raw_os_error(c::ERROR_INVALID_PARAMETER as i32))
`
``
260
`+
}
`
259
261
`}
`
260
262
`}
`
261
263
``
262
264
`fn get_creation_mode(&self) -> io::Result<c::DWORD> {
`
263
``
`-
const ERROR_INVALID_PARAMETER: i32 = 87;
`
264
``
-
265
265
`match (self.write, self.append) {
`
266
266
`(true, false) => {}
`
267
267
`(false, false) => {
`
268
268
`if self.truncate || self.create || self.create_new {
`
269
``
`-
return Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER));
`
``
269
`+
return Err(Error::from_raw_os_error(c::ERROR_INVALID_PARAMETER as i32));
`
270
270
`}
`
271
271
`}
`
272
272
`(_, true) => {
`
273
273
`if self.truncate && !self.create_new {
`
274
``
`-
return Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER));
`
``
274
`+
return Err(Error::from_raw_os_error(c::ERROR_INVALID_PARAMETER as i32));
`
275
275
`}
`
276
276
`}
`
277
277
`}
`
`@@ -315,7 +315,7 @@ impl File {
`
315
315
`// Manual truncation. See #115745.
`
316
316
`if opts.truncate
`
317
317
` && creation == c::OPEN_ALWAYS
`
318
``
`-
&& unsafe { c::GetLastError() } == c::ERROR_ALREADY_EXISTS
`
``
318
`+
&& api::get_last_error() == WinError::ALREADY_EXISTS
`
319
319
`{
`
320
320
`unsafe {
`
321
321
`` // This originally used FileAllocationInfo
instead of
``
`@@ -845,7 +845,7 @@ fn open_link_no_reparse(parent: &File, name: &[u16], access: u32) -> io::Result<
`
845
845
`` // We make a special exception for STATUS_DELETE_PENDING
because
``
846
846
`` // otherwise this will be mapped to ERROR_ACCESS_DENIED
which is
``
847
847
`// very unhelpful.
`
848
``
`-
Err(io::Error::from_raw_os_error(c::ERROR_DELETE_PENDING as _))
`
``
848
`+
Err(io::Error::from_raw_os_error(c::ERROR_DELETE_PENDING as i32))
`
849
849
`} else if status == c::STATUS_INVALID_PARAMETER
`
850
850
` && ATTRIBUTES.load(Ordering::Relaxed) == c::OBJ_DONT_REPARSE
`
851
851
`{
`
`@@ -1097,7 +1097,7 @@ pub fn readdir(p: &Path) -> io::Result {
`
1097
1097
`//
`
1098
1098
`// See issue #120040: https://github.com/rust-lang/rust/issues/120040.
`
1099
1099
`let last_error = api::get_last_error();
`
1100
``
`-
if last_error.code == c::ERROR_FILE_NOT_FOUND {
`
``
1100
`+
if last_error == WinError::FILE_NOT_FOUND {
`
1101
1101
`return Ok(ReadDir {
`
1102
1102
`handle: FindNextFileHandle(find_handle),
`
1103
1103
`root: Arc::new(root),
`