Skip to content

Commit 3c544b3

Browse files
committed
Fixes from PR
- is_ebadf always returns false Signed-off-by: Ayush Singh <[email protected]>
1 parent a9a5ef9 commit 3c544b3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

library/std/src/sys/uefi/stdio.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ impl io::Read for Stdin {
3333
}
3434

3535
// Try reading any pending data
36-
let inp = read(stdin)?;
36+
let inp = simple_text_input_read(stdin)?;
3737

3838
// Check if the key is printiable character
3939
if inp == 0x00 {
4040
return Err(io::const_io_error!(io::ErrorKind::Interrupted, "Special Key Press"));
4141
}
4242

43-
// The option unwrap is safe since iterator will have 1 element.
44-
let ch: char = char::decode_utf16([inp])
45-
.next()
46-
.unwrap()
47-
.map_err(|_| io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Input"))?;
43+
let Some(Ok(ch)) = char::decode_utf16([inp]).next() else {
44+
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Input"));
45+
};
46+
4847
if ch.len_utf8() > buf.len() {
4948
self.pending = Some(ch);
5049
return Ok(0);
@@ -97,8 +96,8 @@ impl io::Write for Stderr {
9796
// UCS-2 character should occupy 3 bytes at most in UTF-8
9897
pub const STDIN_BUF_SIZE: usize = 3;
9998

100-
pub fn is_ebadf(err: &io::Error) -> bool {
101-
err.raw_os_error() == Some(r_efi::efi::Status::UNSUPPORTED.as_usize())
99+
pub fn is_ebadf(_err: &io::Error) -> bool {
100+
false
102101
}
103102

104103
pub fn panic_output() -> Option<impl io::Write> {
@@ -116,6 +115,7 @@ fn write(
116115
};
117116

118117
let mut utf16: Vec<u16> = utf8.encode_utf16().collect();
118+
// NULL terminate the string
119119
utf16.push(0);
120120

121121
unsafe { simple_text_output(protocol, &mut utf16) }?;
@@ -131,7 +131,9 @@ unsafe fn simple_text_output(
131131
if res.is_error() { Err(io::Error::from_raw_os_error(res.as_usize())) } else { Ok(()) }
132132
}
133133

134-
fn read(stdin: *mut r_efi::protocols::simple_text_input::Protocol) -> io::Result<u16> {
134+
fn simple_text_input_read(
135+
stdin: *mut r_efi::protocols::simple_text_input::Protocol,
136+
) -> io::Result<u16> {
135137
loop {
136138
match read_key_stroke(stdin) {
137139
Ok(x) => return Ok(x.unicode_char),

0 commit comments

Comments
 (0)