public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* Why fseeko always ends up calling _llseek?
@ 2004-09-02 4:52 Chakravarthy Nelluri
0 siblings, 0 replies; only message in thread
From: Chakravarthy Nelluri @ 2004-09-02 4:52 UTC (permalink / raw)
To: glibc-bugs
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
=====
chakri
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-09-02 4:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-02 4:52 Why fseeko always ends up calling _llseek? Chakravarthy Nelluri
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).