Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Why can't stdin from a file be read by an overlay? Message-ID: <9632@mimsy.UUCP> Date: Sat, 5-Dec-87 00:04:54 EST Article-I.D.: mimsy.9632 Posted: Sat Dec 5 00:04:54 1987 Date-Received: Wed, 9-Dec-87 01:58:11 EST References: <2775@tut.cis.ohio-state.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 19 Keywords: Unix,stdio Xref: utgpu comp.lang.c:5416 comp.unix.questions:4655 In article <2775@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes: >Suppose a program reads stdin ... for some information, and then >execs (no fork) a process to [read] other information. There >isn't a problem when the input is from a tty, however, if the >input is redirected, say from a Bourne shell here document, the >second process sees an EOF immediately. The here document (or other input file) has no more than a `block' (BUFSIZ) of stuff. stdio is reading the entire block; then when the program exec()s, the part of that block that has not been used simply vanishes, because the seek offset for fd 0 is still at end-of-file. Solutions: avoid stdio; use unbuffered input; cheat and seek fd 0 to the right place, the latter with lseek(0, ftell(stdin), 0). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris