Changing Seek() deprecated

Have a question about our Software Developer Kit? Ask them here.
Post Reply
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Changing Seek() deprecated

Post 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)
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Changing Seek() deprecated

Post 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.
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: Changing Seek() deprecated

Post by javierdlr »

oups, you're right :-P will try to read more carefully next time THX mate!!!
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: Changing Seek() deprecated

Post 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);
}
Last edited by colinw on Thu May 23, 2013 1:29 am, edited 1 time in total.
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: Changing Seek() deprecated

Post 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
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: Changing Seek() deprecated

Post 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.
Post Reply