ttyread.c
来自「TCP-IP红宝书源代码」· C语言 代码 · 共 43 行
C
43 行
/* ttyread.c - ttyread */
#include <conf.h>
#include <kernel.h>
#include <tty.h>
/*------------------------------------------------------------------------
* ttyread - read characters from a tty
*------------------------------------------------------------------------
*/
int
ttyread(struct devsw *pdev, char *buf, unsigned len)
{
STATWORD ps;
struct tty *ptty = (struct tty *)pdev->dvioblk;
unsigned count;
if (ptty->tty_state != TTYS_ALLOC)
return SYSERR;
if ((ptty->tty_iflags & TIF_EOF) && ptty->tty_icount == 0) {
ptty->tty_iflags &= ~TIF_EOF;
return EOF;
}
if (ptty->tty_iflags & TIF_NOBLOCK)
if (scount(ptty->tty_isema) <= 0)
return SYSERR;
disable(ps);
wait(ptty->tty_isema);
count = 0;
while (count < len && ptty->tty_icount) {
*buf++ = ptty->tty_in[ptty->tty_istart];
count++;
ptty->tty_icount--;
ptty->tty_istart++;
if (ptty->tty_istart >= IBLEN)
ptty->tty_istart = 0;
}
/* wakeup other readers here */
restore(ps);
gettime(&ptty->tty_ctime);
return count;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?