Return to BSD News archive
Received: by minnie.vk1xwt.ampr.org with NNTP id AA7334 ; Mon, 18 Jan 93 10:52:09 EST Xref: sserve comp.unix.bsd:10229 comp.lang.c:38174 Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!noc.near.net!news.centerline.com!jimf From: jimf@centerline.com (Jim Frost) Newsgroups: comp.unix.bsd,comp.lang.c Subject: Re: a unix terminal question Date: 20 Jan 1993 18:01:45 GMT Organization: CenterLine Software, Inc. Lines: 39 Message-ID: <1jk429INN2io@armory.centerline.com> References: <uonuhjc@zola.esd.sgi.com> <4@wa4cyb.UUCP> NNTP-Posting-Host: 140.239.3.202 jmd@wa4cyb.UUCP (John Dashner) writes: >Some systems support a reasonable ``cbreak'' mode that in effect returns >control to a process as each character is typed. Depending on the needs >as speculated on by Terry that you have in mind, this mode may be all >that you need. Your 'man' pages should have a discussion about the >kinds of serial support you have. All reasonably current UNIX systems support cbreak mode or a fair fascimile. In AT&T UNIX or POSIX it's done using termio/termios. The POSIX technique follows, which is essentially the same as the SysV termio technique. I suggest using the POSIX technique unless your system supports only the BSD technique; in my experience it's far more portable. Note that to do this right under SysV/POSIX you have to save VMIN and VTIME to restore canonical mode. I'll never understand why they did that as long as I live. jim frost jimf@centerline.com -- cut here -- void set_cbreak_mode(int fd) { struct termios mode; if (tcgetattr(fd, &mode) < 0) { fprintf(stderr, "set_cbreak_mode: tcgetattr failed, errno %d\n", errno); return; } /* turn off canonical line processing, character echoing, and signal * generation. */ mode.c_lflag &= ~(ICANON | ECHO | ISIG); mode.c_cc[VMIN] = 1; /* get only one character per read(). */ mode.c_cc[VTIME] = 0; /* wait indefinitely for tty input. */ if (tcsetattr(fd, &mode) < 0) fprintf("stderr, "set_cbreak_mode: tcsetattr failed, errno %d\n", errno); }