question on lseek behavior
Eric Marshall
marshall at software.org
Thu Jul 5 22:34:35 AEST 1990
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.
Thanks in advance.
seek_test.c:
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
main()
{
int c;
FILE *infile = fopen( "seek_test.c", "r" );
c = getc( infile );
c = getc( infile );
c = getc( infile );
lseek( fileno( infile ), 0L, L_SET );
while ( ( c = getc( infile ) ) != EOF ) putchar( c );
}
Eric Marshall
Software Productivity Consortium
SPC Building
2214 Rock Hill Road
Herndon, VA 22070
(703) 742-7153
UUCP: ...!uunet!software!marshall
ARPANET: marshall%software.org at relay.cs.net
More information about the Comp.unix.wizards
mailing list