Porting AT&T ioctl()'s to BSD???

Chris Torek chris at mimsy.UUCP
Tue Jan 3 09:11:28 AEST 1989


In article <7300002 at fthood> egray at fthood.UUCP writes:
>I need the ability to flush the TTY input queue, output queue, or both
>similar to what AT&T does with ioctl(fd, TCFLSH, n).  I can't use
>BSD's icotl(fd, TCIOFLUSH, 0) since it always flushed both queues.

TIOCFLUSH actually does either or both, although I am unsure whether
it is documented properly:

	#include <sys/types.h>
	#include <sys/file.h>
	#include <sys/ioctl.h>

	foo() {
		int r = FREAD, w = FWRITE, rw = FREAD|FWRITE;

		... ioctl(fd, TIOCFLUSH, (caddr_t)&r) ...  /* flush input */
		... ioctl(fd, TIOCFLUSH, (caddr_t)&w) ...  /* flush output */
		... ioctl(fd, TIOCFLUSH, (caddr_t)&rw) ... /* flush both */

In fact,

	ioctl(fd, TIOCFLUSH, (caddr_t)0)

(with or without the cast to caddr_t or `char *') is illegal, and
merely `happens to work' on a Vax running stock 4BSD.  You should
always pass the address of an `int' that is set to some combination
of FREAD and FWRITE, or to 0 (which means the same as FREAD|FWRITE).

>Also, I'd like a way to emulate AT&T's ioctl(fd, TCSBRK, 1) that waits
>for the output of the queue to drain.  I suspect BSD's select() could
>be used?

Not directly: select tells you when an I/O operation would not block
(which is why select-for-read is true at EOF on pipes, for instance).

The easiest thing to do is to wait for the POSIX tty driver in 4.4BSD
(or whatever the next BSD will be called).  If you really need to wait
for the tty output queue to drain (which typically has no effect anyway
if, e.g., one is logged in across a network), TIOCSETP does this,
although it then also flushes pending input and sets the terminal
interpretation modes; or, you can use TIOCOUTQ and select() timeouts
together.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.questions mailing list