XINU
ttyread.c
Go to the documentation of this file.
1 /* ttyread.c - ttyread */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * ttyread - Read character(s) from a tty device (interrupts disabled)
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr, /* Entry in device switch table */
11  char *buff, /* Buffer of characters */
12  int32 count /* Count of character to read */
13  )
14 {
15  struct ttycblk *typtr; /* Pointer to tty control block */
16  int32 avail; /* Characters available in buff.*/
17  int32 nread; /* Number of characters read */
18  int32 firstch; /* First input character on line*/
19  char ch; /* Next input character */
20 
21  if (count < 0) {
22  return SYSERR;
23  }
24  typtr= &ttytab[devptr->dvminor];
25 
26  if (typtr->tyimode != TY_IMCOOKED) {
27 
28  /* For count of zero, return all available characters */
29 
30  if (count == 0) {
31  avail = semcount(typtr->tyisem);
32  if (avail == 0) {
33  return 0;
34  } else {
35  count = avail;
36  }
37  }
38  for (nread = 0; nread < count; nread++) {
39  *buff++ = (char) ttygetc(devptr);
40  }
41  return nread;
42  }
43 
44  /* Block until input arrives */
45 
46  firstch = ttygetc(devptr);
47 
48  /* Check for End-Of-File */
49 
50  if (firstch == EOF) {
51  return EOF;
52  }
53 
54  /* Read up to a line */
55 
56  ch = (char) firstch;
57  *buff++ = ch;
58  nread = 1;
59  while ( (nread < count) && (ch != TY_NEWLINE) &&
60  (ch != TY_RETURN) ) {
61  ch = ttygetc(devptr);
62  *buff++ = ch;
63  nread++;
64  }
65  return nread;
66 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
int32 dvminor
Definition: conf.h:8
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
devcall ttyread(struct dentry *devptr, char *buff, int32 count)
Definition: ttyread.c:9
Definition: conf.h:6
Definition: tty.h:26
devcall ttygetc(struct dentry *)
Definition: ttygetc.c:9
#define TY_RETURN
Definition: tty.h:69
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct ttycblk ttytab[]
Definition: ttyinit.c:11
char tyimode
Definition: tty.h:38
#define TY_IMCOOKED
Definition: tty.h:22
#define TY_NEWLINE
Definition: tty.h:68
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
sid32 tyisem
Definition: tty.h:30