std.stdio.File.seek error
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 13 20:07:05 PDT 2016
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:
>> On Sunday, 13 March 2016 at 10:32:41 UTC, stunaep wrote:
>>> I have a very large file I need to read data from at certain
>>> positions, but I have run into this error
>>>> [...]
>>> when seeking to 6346890680. Seeking to smaller values such as
>>> 3580720 work with no problem. The file is well over 8GB, so
>>> it must be able to read data at positions that high.
>>
>> are you on a 32 or 64 bit system?
>> You could try 2 or more consecutive relative seeks in place of
>> an absolute seek.
>> i.e.
>> File f = ... ;
>> f.seek(173445340 , SEEK_SET);
>> f.seek(173445340 , SEEK_REL);
>> also what does
>> f.seek(0,SEEK_END);
>> writeln(f.tell());
>> print?
>
> I'm on 64 bit but it needs to work on both. It works for
> anything between 0 and 2147483647.
>
>> f.seek(0,SEEK_END);
>> writeln(f.tell());
>
> that throws an error before reaching f.tell()
>
>> std.exception.ErrnoException at std\stdio.d(920): Could not seek
>> in file `./file.dat' (Invalid argument)
>> ----------------
>> 0x000000013FE67868 in @safe bool
>> std.exception.errnoEnforce!(bool, "std\stdio.d",
>> 920uL).errnoEnforce(bool, lazy immutable(char)[])
>> 0x000000013FE4E7D3 in @trusted void std.stdio.File.seek(long,
>> int)
>
> Also, seeking relative to the current position throws the same
> error as in the original post if it's over max signed int.
>
>> f.seek(2147483647, SEEK_SET);
>> writeln(f.tell()); // prints 2147483647
>> f.seek(4, SEEK_CUR); // throws error
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);
More information about the Digitalmars-d-learn
mailing list