public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Chakravarthy Nelluri <chakri_in5@yahoo.com>
To: glibc-bugs@sources.redhat.com
Subject: Why fseeko always ends up calling _llseek?
Date: Thu, 02 Sep 2004 04:52:00 -0000	[thread overview]
Message-ID: <20040902045235.1396.qmail@web12704.mail.yahoo.com> (raw)

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 


                 reply	other threads:[~2004-09-02  4:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040902045235.1396.qmail@web12704.mail.yahoo.com \
    --to=chakri_in5@yahoo.com \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).