mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 23:46:48 +00:00
修复读取stdin时,无法正常读取的问题。 (#264)
This commit is contained in:
parent
7285c927d9
commit
bfafc10279
@ -1,3 +1,5 @@
|
||||
use core::intrinsics::unlikely;
|
||||
|
||||
use alloc::string::String;
|
||||
|
||||
use thingbuf::mpsc::{
|
||||
@ -168,13 +170,23 @@ impl TtyCore {
|
||||
_ => return Err(TtyError::Unknown(format!("{err:?}"))),
|
||||
}
|
||||
} else {
|
||||
buf[cnt] = *val.unwrap();
|
||||
let x = *val.unwrap();
|
||||
buf[cnt] = x;
|
||||
cnt += 1;
|
||||
|
||||
if unlikely(self.stdin_should_return(x)) {
|
||||
return Ok(cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(cnt);
|
||||
}
|
||||
|
||||
fn stdin_should_return(&self, c: u8) -> bool {
|
||||
// 如果是换行符或者是ctrl+d,那么就应该返回
|
||||
return c == b'\n' || c == 4;
|
||||
}
|
||||
|
||||
/// @brief 向stdin缓冲区内写入数据
|
||||
///
|
||||
/// @param buf 输入缓冲区
|
||||
|
@ -12,7 +12,7 @@ use crate::{
|
||||
include::bindings::bindings::{textui_putchar, BLACK, WHITE},
|
||||
kerror,
|
||||
libs::rwlock::RwLock,
|
||||
syscall::SystemError,
|
||||
syscall::SystemError, kdebug, arch::asm::current::current_pcb,
|
||||
};
|
||||
|
||||
use super::{TtyCore, TtyError, TtyFileFlag, TtyFilePrivateData};
|
||||
@ -263,6 +263,7 @@ impl IndexNode for TtyDevice {
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl TtyDevicePrivateData {
|
||||
|
@ -173,9 +173,14 @@ impl File {
|
||||
///
|
||||
/// @param origin 调整的起始位置
|
||||
pub fn lseek(&mut self, origin: SeekFrom) -> Result<usize, SystemError> {
|
||||
if self.inode.metadata().unwrap().file_type == FileType::Pipe {
|
||||
return Err(SystemError::ESPIPE);
|
||||
let file_type = self.inode.metadata().unwrap().file_type;
|
||||
match file_type {
|
||||
FileType::Pipe | FileType::CharDevice => {
|
||||
return Err(SystemError::ESPIPE);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let pos: i64;
|
||||
match origin {
|
||||
SeekFrom::SeekSet(offset) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user