August 17, 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




August 17, 2010
Steve Schveighoffer wrote:
> 
> 
> 
> ----- 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.

I confirm this is the behavior. I finally found the way to do it on OSX - import core.sys.posix.stdio and then use fseeko and ftello. See my latest checkin.


Andrei
1 2
Next ›   Last »