question on lseek behavior
Larry McVoy
lm at snafu.Sun.COM
Fri Jul 6 09:22:30 AEST 1990
In article <1416 at software.software.org> marshall at 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 at sun.com
More information about the Comp.unix.wizards
mailing list