Path: utzoo!attcan!uunet!husc6!cmcl2!phri!marob!daveh From: daveh@marob.MASA.COM (Dave Hammond) Newsgroups: comp.unix.questions Subject: Re: Querying tty input with ioctl Message-ID: <340@marob.MASA.COM> Date: 25 Jul 88 12:43:18 GMT References: <11527@steinmetz.ge.com> <5740024@hpfcdc.HP.COM> Reply-To: daveh@marob.UUCP (Dave Hammond) Organization: 18th Street Construction Co NY NY Lines: 37 In article <5740024@hpfcdc.HP.COM> rml@hpfcdc.HP.COM (Bob Lenk) writes: >> int fcntl_flags = fcntl(0, F_GETFL, 0); /* get fcntl flags */ > ^^^^^^^ > O_GETFL >> fcntl(0, F_SETFL, fcntl_flags | O_NDELAY); /* set "no delay" */ > ^^^^^^^ > O_SETFL >> if (read(0, &ch, 1) > 0) /* there's a char queued */ >> do_something(); >> fcntl(0, F_SETFL, fcntl_flags); /* unset "no delay" */ > ^^^^^^^ > O_GETFL From the XENIX man page for fcntl: F_GETFL Gets file status flags: O_RDONLY, O_WRONLY, O_RDWR, O_NDELAY, or O_APPEND. F_SETFL Sets file status flags to arg. Only certain flags can be set. While I'll agree that XENIX is not virgin SysV, it is a certified SysV port. I can't recall programs written non-XENIX systems having to be modified (relative to the above F_GETFL/O_GETFL question) to compile under XENIX, or vice-versa. >> Read in O_NDELAY mode will return -1 of the read would block (i.e. there > ^^ > 0 I stand corrected. Indeed, read() returns 0 if O_NDELAY is set and a dry read() occurs. The above code fragment likely works because it tests for a success rather than failure return value. Dave Hammond UUCP: !{uunet|rutgers|spl1|...}!hombre!{marob|dsix2}!daveh ---------------------------------------------------------------