| 175 | } |
| 176 | |
| 177 | CharacterDevice *console_init(BOOL allow_ctrlc) |
| 178 | { |
| 179 | CharacterDevice *dev; |
| 180 | STDIODevice *s; |
| 181 | struct sigaction sig; |
| 182 | |
| 183 | term_init(allow_ctrlc); |
| 184 | |
| 185 | dev = mallocz(sizeof(*dev)); |
| 186 | s = mallocz(sizeof(*s)); |
| 187 | s->stdin_fd = 0; |
| 188 | /* Note: the glibc does not properly tests the return value of |
| 189 | write() in printf, so some messages on stdout may be lost */ |
| 190 | fcntl(s->stdin_fd, F_SETFL, O_NONBLOCK); |
| 191 | |
| 192 | s->resize_pending = TRUE; |
| 193 | global_stdio_device = s; |
| 194 | |
| 195 | /* use a signal to get the host terminal resize events */ |
| 196 | sig.sa_handler = term_resize_handler; |
| 197 | sigemptyset(&sig.sa_mask); |
| 198 | sig.sa_flags = 0; |
| 199 | sigaction(SIGWINCH, &sig, NULL); |
| 200 | |
| 201 | dev->opaque = s; |
| 202 | dev->write_data = console_write; |
| 203 | dev->read_data = console_read; |
| 204 | return dev; |
| 205 | } |
| 206 | |
| 207 | #endif /* !_WIN32 */ |
| 208 | |