From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13473 invoked by alias); 2 Sep 2004 04:52:37 -0000 Mailing-List: contact glibc-bugs-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sources.redhat.com Received: (qmail 13429 invoked from network); 2 Sep 2004 04:52:36 -0000 Message-ID: <20040902045235.1396.qmail@web12704.mail.yahoo.com> Date: Thu, 02 Sep 2004 04:52:00 -0000 From: Chakravarthy Nelluri Subject: Why fseeko always ends up calling _llseek? To: glibc-bugs@sources.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-09/txt/msg00004.txt.bz2 List-Id: 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 #include #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 .\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