Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!ece-csc!ncrcae!ncr-sd!crash!ford From: ford@crash.CTS.COM (Michael Ditto) Newsgroups: comp.bugs.4bsd Subject: Re: read() from tty has fencepost error Message-ID: <1325@crash.CTS.COM> Date: Fri, 3-Jul-87 07:27:42 EDT Article-I.D.: crash.1325 Posted: Fri Jul 3 07:27:42 1987 Date-Received: Sat, 4-Jul-87 13:22:34 EDT References: <648@haddock.UUCP> <6040@brl-smoke.ARPA> <13048@topaz.rutgers.edu> Reply-To: ford@crash.CTS.COM (Michael Ditto) Organization: Crash TS, El Cajon, CA Lines: 47 In article <13048@topaz.rutgers.edu> ron@topaz.rutgers.edu (Ron Natalie) writes: >Excuse me System V breath, if you look on your own beloved operating system >you will see that EOT works the opposite way that it does on system V, that >is, the following code > > main() { > int count; > char buf[10]; > > do { > count = read(0, buf, 5); > printf("\ncount = %d\n", count); > } while(count); > } > > [...] > > % a.out > a > > count = 2 > abcde > count = 5 > >...at this point it waits for you to type more input... > >I guess System V is wrong for once :-) > No, this is the spec for EOF in termio(7) (SysV's equivalent to tty(4)): [When EOF is received] all the characters waiting to be read are immediately passed to the program, without waiting for a new-line, and the EOF is descarded. Thus, if there are no characters waiting, which is to say the EOF occurred at the beginning of a line, zero characters will be passed back [...] This is the way UNIX has always worked, except for Berkeley's versions, and AT&T still does it this way. (The above quote from termio(7) is copyright by AT&T, but you can see it on your SysV system with "man 7 termio". [Lame attempt at disclaimer]). -- Michael "Ford" Ditto -=] Ford [=- P.O. Box 1721 ford@crash.CTS.COM Bonita, CA 92002 ford%oz@prep.mit.ai.edu