Use an absolute path to the NUL device

While a bare "NUL" *should* be redirected to the NUL device, especially in this simple case, let's be explicit that we aren't opening a file called "NUL" and instead open it directly.

This will also set a good example for people copying std code.
This commit is contained in:
Chris Denton 2023-11-19 16:24:39 +00:00
parent 097261f241
commit 3a486c1feb
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE

View File

@ -597,7 +597,7 @@ impl Stdio {
opts.read(stdio_id == c::STD_INPUT_HANDLE);
opts.write(stdio_id != c::STD_INPUT_HANDLE);
opts.security_attributes(&mut sa);
File::open(Path::new("NUL"), &opts).map(|file| file.into_inner())
File::open(Path::new(r"\\.\NUL"), &opts).map(|file| file.into_inner())
}
}
}