This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Why fseeko always calls _llseek.?
- From: Chakravarthy Nelluri <chakri_in5 at yahoo dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 31 Aug 2004 23:26:36 -0700 (PDT)
- Subject: Why fseeko always calls _llseek.?
Hi,
Why fseeko always ends up calling _llseek on linux(
not sure how it behaves in other OS'es)?
Why can't it just return setting the file position
indicator for the stream.
I have a small test program.
#include <stdio.h>
#include <errno.h>
#define BUF_SIZE 1024*256 //256kb
int main(int argc, char *argv[])
{
unsigned char buf[BUF_SIZE];
unsigned char setbuf[BUF_SIZE];
FILE *fp=NULL;
if( 2!= argc) {
printf("Invalid usage. Usage <fseektest>
<filename>.\n");
exit(1);
}
fp = fopen(argv[1],"rb");
if(NULL==fp) {
printf("Error: filename: %s, error:
%s.\n",argv[1],strerror(errno));
exit(1);
}
if( 0 != setvbuf(fp,setbuf,_IOFBF,BUF_SIZE)) {
printf("Error setting buff, error:
%s.\n",strerror(errno));
exit(2);
}
while( fread(buf,1,256,fp) ) {
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
fseeko(fp,10L,SEEK_CUR);
}
exit(0);
}
In the above program the call to setvbuf makes sure
that 1024*256 bytes are read when fread is called for
the first time, with 256 bytes. I could see that it
always results in only read calls with 1024*256 bytes.
But when I do fseek, just after my first fread, it
results in a _llseek call. Why cannot the libc just
position itself in the already read 1024*256 bytes
buffer and return? Calling _llseek results in a very
high overhead, where there are large number of seeks.
=====
chakri
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush