std.stdio.File.seek error

stunaep via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 13 22:24:48 PDT 2016


On Monday, 14 March 2016 at 03:07:05 UTC, Nicholas Wilson wrote:
> On Monday, 14 March 2016 at 00:12:46 UTC, stunaep wrote:
>> On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson 
>> wrote:
>>> [...]
>>
>> I'm on 64 bit but it needs to work on both. It works for 
>> anything between 0 and 2147483647.
>>
>>> [...]
>>
>> that throws an error before reaching f.tell()
>>
>>> [...]
>>
>> Also, seeking relative to the current position throws the same 
>> error as in the original post if it's over max signed int.
>>
>>> [...]
>
> Hmm. If you're getting an errno exception ( as opposed to a 
> conv) I really don't
> think that theres anything you can do about it, as its a 
> problem with the C standard
> lib. What OS/version are you running?
>
> what does the equivalent in C give you.
> i.e.
>
> FILE* f = fopen(...,"r");
> fseek(f,0,SEEK_END);
> printf("%ld",ftell(f));
> printf("%d",errno);

I'm currently on windows 7. The code you gave me prints 022. It's 
weird because it always tries to convert longs to ints and I 
think that is weird because the function uses a c_long.
> int fseek(FILE* stream, c_long offset, int whence)

It wont even compile if I try giving it a long
> Error: function core.stdc.stdio.fseek (shared(_iobuf)* stream, 
> int offset, int whence) is not callable using argument types 
> (shared(_iobuf)*, long, int)

I also tried giving it a c_long, but this line
>c_long test = 2147483649;
gives this error for some reason...
> Error: cannot implicitly convert expression (2147483649L) of 
> type long to int

It's like c_longs are not longs at all...


More information about the Digitalmars-d-learn mailing list