4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.1 2008/02/12 22:36:46 james
14 * *** empty log message ***
16 * Revision 1.1 2008/02/09 15:47:28 james
17 * *** empty log message ***
19 * Revision 1.2 2008/02/07 11:11:14 staffcvs
20 * *** empty log message ***
22 * Revision 1.1 2008/02/07 01:02:52 james
23 * *** empty log message ***
25 * Revision 1.3 2008/02/06 17:53:28 james
26 * *** empty log message ***
28 * Revision 1.2 2008/02/04 02:05:06 james
29 * *** empty log message ***
31 * Revision 1.1 2008/02/04 01:32:39 james
32 * *** empty log message ***
39 typedef struct TERMINAL_struct
42 struct termios orig_termios;
43 struct TERMINAL_struct *next;
47 static TERMINAL terminal_list=NULL;
51 terminal_close (TTY * _t)
53 TERMINAL *t = (TERMINAL *) _t;
54 TERMINAL **ptr=&terminal_list;
59 /* Take out of cleanup list */
60 while (*ptr && (*ptr != t)) ptr=&((*ptr)->next);
65 tcsetattr(t->wfd,TCSANOW,&t->orig_termios);
76 terminal_read (TTY * _t, void *buf, int len)
78 TERMINAL *t = (TERMINAL *) _t;
84 red = wrap_read (t->fd, buf, len);
102 terminal_write (TTY * _t, void *buf, int len)
105 TERMINAL *t = (TERMINAL *) _t;
110 writ = wrap_write (t->fd, buf, len);
127 terminal_open (int rfd,int wfd)
132 struct termios termios;
134 t = (TERMINAL *) malloc (sizeof (TERMINAL));
139 tcgetattr(wfd,&t->orig_termios);
141 t->next=terminal_list;
144 tcgetattr(tfd,&termios);
146 set_nonblocking (rfd);
147 set_nonblocking (wfd);
150 raw_termios (&termios);
152 tcsetattr(wfd,TCSANOW,&termios);
154 t->read = terminal_read;
155 t->write = terminal_write;
156 t->close = terminal_close;
163 terminal_getsize (TTY *_t,CRT_POS *pos)
165 TERMINAL *t=(TTY *) _t;
166 struct winsize sz = { 0 };
168 if ((!t) || (!pos)) return;
170 if (ioctl (a->wfd, TIOCGWINSZ, &sz))
183 void terminal_atexit(void)
185 while (terminal_list)
186 terminal_close(terminal_list);