修复读取stdin时,无法正常读取的问题。 (#264)

This commit is contained in:
login 2023-05-11 17:41:42 +08:00 committed by GitHub
parent 7285c927d9
commit bfafc10279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -1,3 +1,5 @@
use core::intrinsics::unlikely;
use alloc::string::String; use alloc::string::String;
use thingbuf::mpsc::{ use thingbuf::mpsc::{
@ -168,13 +170,23 @@ impl TtyCore {
_ => return Err(TtyError::Unknown(format!("{err:?}"))), _ => return Err(TtyError::Unknown(format!("{err:?}"))),
} }
} else { } else {
buf[cnt] = *val.unwrap(); let x = *val.unwrap();
buf[cnt] = x;
cnt += 1; cnt += 1;
if unlikely(self.stdin_should_return(x)) {
return Ok(cnt);
}
} }
} }
return Ok(cnt); return Ok(cnt);
} }
fn stdin_should_return(&self, c: u8) -> bool {
// 如果是换行符或者是ctrl+d那么就应该返回
return c == b'\n' || c == 4;
}
/// @brief 向stdin缓冲区内写入数据 /// @brief 向stdin缓冲区内写入数据
/// ///
/// @param buf 输入缓冲区 /// @param buf 输入缓冲区

View File

@ -12,7 +12,7 @@ use crate::{
include::bindings::bindings::{textui_putchar, BLACK, WHITE}, include::bindings::bindings::{textui_putchar, BLACK, WHITE},
kerror, kerror,
libs::rwlock::RwLock, libs::rwlock::RwLock,
syscall::SystemError, syscall::SystemError, kdebug, arch::asm::current::current_pcb,
}; };
use super::{TtyCore, TtyError, TtyFileFlag, TtyFilePrivateData}; use super::{TtyCore, TtyError, TtyFileFlag, TtyFilePrivateData};
@ -263,6 +263,7 @@ impl IndexNode for TtyDevice {
} }
return Ok(()); return Ok(());
} }
} }
impl TtyDevicePrivateData { impl TtyDevicePrivateData {

View File

@ -173,9 +173,14 @@ impl File {
/// ///
/// @param origin 调整的起始位置 /// @param origin 调整的起始位置
pub fn lseek(&mut self, origin: SeekFrom) -> Result<usize, SystemError> { pub fn lseek(&mut self, origin: SeekFrom) -> Result<usize, SystemError> {
if self.inode.metadata().unwrap().file_type == FileType::Pipe { let file_type = self.inode.metadata().unwrap().file_type;
return Err(SystemError::ESPIPE); match file_type {
FileType::Pipe | FileType::CharDevice => {
return Err(SystemError::ESPIPE);
}
_ => {}
} }
let pos: i64; let pos: i64;
match origin { match origin {
SeekFrom::SeekSet(offset) => { SeekFrom::SeekSet(offset) => {