Page 1 of 1
Changing Seek() deprecated
Posted: Sun May 19, 2013 1:07 pm
by javierdlr
Hi trying to change deprecated Seek() with ChangeFilePosition(), but can't make it to work.
kkfu=ChangeFilePosition(infh, 0, OFFSET_BEGINNING)
gives me always -1
kkfu=Seek(infh, 0, OFFSET_BEGINNING)
gives me (is a loop):
kkfu=0
kkfu=29428
..
TIA. What am I missing?
BTW
BPTR infh; int32 kkfu;
infh = Open(args.from, MODE_OLDFILE)
Re: Changing Seek() deprecated
Posted: Sun May 19, 2013 1:18 pm
by thomasrapp
javierdlr wrote:TIA. What am I missing?
RTFM ?
Seek returns the current Read/Write position before the seek is executed.
ChangeFilePosition returns success (-1 a.k.a. DOSTRUE) or failure (0).
You need to replace Seek by GetFilePostiion in appropiate places.
Sometimes Seek is used to get the file size:
Seek (file,0,OFFSET_END); /* move position to the end of the file */
size = Seek (file,0,OFFSET_BEGINNING); /* move position back to the beginning of the file and return previous position */
This can be replaced by GetFileSize in most cases.
Note that kkfu needs to be changed to an int64 to support >2GB files.
Re: Changing Seek() deprecated
Posted: Sun May 19, 2013 2:16 pm
by javierdlr
oups, you're right
will try to read more carefully next time THX mate!!!
Re: Changing Seek() deprecated
Posted: Sun May 19, 2013 11:37 pm
by colinw
int64 Seek64(BPTR scb, int64 pos, int32 mode)
{
int64 result64 = -1LL; /* default failure code */
int64 oldpos64 = IDOS->GetFilePosition(scb);
if( IDOS->ChangeFilePosition(scb, pos, mode))
{
result64 = oldpos64; /* old Seek() returns previous pos. */
}
return(result64);
}
Re: Changing Seek() deprecated
Posted: Wed May 22, 2013 10:13 pm
by javierdlr
THX all, just chnged to Seek64 and think updated all to int64 values, will do some checks/test and see what happens. TIA
Re: Changing Seek() deprecated
Posted: Thu May 23, 2013 7:25 am
by colinw
Just take note of what Thomas said above.
If the Seek() function is being (ab)used to find a file size, you would be far better off just calling IDOS->GetFileSize()
rather than that double-seek ickyness, it's also amazingly slow too, just incase you were wondering.