Skip to content

Commit

Permalink
Fixes from PR
Browse files Browse the repository at this point in the history
- is_ebadf always returns false

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed Oct 30, 2023
1 parent a9a5ef9 commit 3c544b3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions library/std/src/sys/uefi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ impl io::Read for Stdin {
}

// Try reading any pending data
let inp = read(stdin)?;
let inp = simple_text_input_read(stdin)?;

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

// The option unwrap is safe since iterator will have 1 element.
let ch: char = char::decode_utf16([inp])
.next()
.unwrap()
.map_err(|_| io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Input"))?;
let Some(Ok(ch)) = char::decode_utf16([inp]).next() else {
return Err(io::const_io_error!(io::ErrorKind::InvalidInput, "Invalid Input"));
};

if ch.len_utf8() > buf.len() {
self.pending = Some(ch);
return Ok(0);
Expand Down Expand Up @@ -97,8 +96,8 @@ impl io::Write for Stderr {
// UCS-2 character should occupy 3 bytes at most in UTF-8
pub const STDIN_BUF_SIZE: usize = 3;

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

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

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

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

fn read(stdin: *mut r_efi::protocols::simple_text_input::Protocol) -> io::Result<u16> {
fn simple_text_input_read(
stdin: *mut r_efi::protocols::simple_text_input::Protocol,
) -> io::Result<u16> {
loop {
match read_key_stroke(stdin) {
Ok(x) => return Ok(x.unicode_char),
Expand Down

0 comments on commit 3c544b3

Please sign in to comment.