Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!cs.utexas.edu!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!amdcad!sun!snafu!lm From: lm@snafu.Sun.COM (Larry McVoy) Newsgroups: comp.unix.wizards Subject: Re: question on lseek behavior Keywords: weirdo Unix system call behavior Message-ID: <138435@sun.Eng.Sun.COM> Date: 5 Jul 90 23:22:30 GMT References: <1416@software.software.org> Sender: news@sun.Eng.Sun.COM Reply-To: lm@sun.UUCP (Larry McVoy) Distribution: usa Organization: Sun Microsystems, Mountain View Lines: 24 In article <1416@software.software.org> marshall@software.org (Eric Marshall) writes: > > I was trying to use lseek to rewind to the beginning >of input (a file), but I ran into difficulties. When I run >the program below, it outputs the file missing the first 3 characters, >as if the lseek didn't do anything, then it outputs the entire >file. Could someone please explain why this occurs. I eventually >found the rewind(3S) call, and it works fine. I am running >on SunOS 4.1. You are using stdio routines which buffer. You bypassed those routines when you issued the lseek() call; rewind is built on top of lseek and looks something like: rewind(f) FILE *f; { lseek(f->_fd, 0, 0); f->_chars_in_buf = 0; } This is a common problem; many test suites make the same mistake. --- Larry McVoy, Sun Microsystems (415) 336-7627 ...!sun!lm or lm@sun.com