[phobos] phobos commit, revision 1877

Steve Schveighoffer schveiguy at yahoo.com
Tue Aug 17 06:41:03 PDT 2010





----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> 
> Steve Schveighoffer wrote:
> > Second, you cannot do a tell on the file handle, because you  need to take 
>into account the buffer.
> 
> My understanding is that calling  fflush() before lseek should be fine. See my 
>upcoming  commit.

I'll take a look.  But I think you cannot do a relative seek or a tell (which is 
a relative seek of 0) without taking into account the buffer.

Here is the issue:

1. you open a file.
2. you read 4 bytes.  The FILE object reads 4096 because it wants to fill up its 
buffer.
3. you do a tell, expecting 4.  If the function does an lseek64 on the file 
handle, it gets 4096.

another instance:

1. you open a file
2. read first 4 bytes, same deal with FILE.  The first 4 bytes lets say are an 
identifier and a length of the data.
3. you don't care about the data, so you seek ahead N bytes to skip it.
4. if the seek command doesn 't take the buffer into account, you seek N + 4092 
bytes ahead!

Note also that according to my linux man page, fflush is for the output buffer 
only, and will not work on input buffers.

-Steve



      


More information about the phobos mailing list