Changing Seek() deprecated

Have a question about our Software Developer Kit? Ask them here.

Changing Seek() deprecated

Postby javierdlr » Sun May 19, 2013 2:07 pm

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
javierdlr
Beta Tester
Beta Tester
 
Posts: 368
Joined: Sun Jun 19, 2011 11:13 pm
Location: Donostia (GUIPUZCOA) - Spain

Re: Changing Seek() deprecated

Postby thomasrapp » Sun May 19, 2013 2:18 pm

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
thomasrapp
 
Posts: 241
Joined: Sun Jun 19, 2011 12:22 am

Re: Changing Seek() deprecated

Postby javierdlr » Sun May 19, 2013 3:16 pm

oups, you're right :-P will try to read more carefully next time THX mate!!!
User avatar
javierdlr
Beta Tester
Beta Tester
 
Posts: 368
Joined: Sun Jun 19, 2011 11:13 pm
Location: Donostia (GUIPUZCOA) - Spain

Re: Changing Seek() deprecated

Postby colinw » Mon May 20, 2013 12:37 am

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 2:29 am, edited 1 time in total.
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 162
Joined: Mon Aug 15, 2011 10:20 am
Location: Brisbane, QLD. Australia.

Re: Changing Seek() deprecated

Postby javierdlr » Wed May 22, 2013 11:13 pm

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
javierdlr
Beta Tester
Beta Tester
 
Posts: 368
Joined: Sun Jun 19, 2011 11:13 pm
Location: Donostia (GUIPUZCOA) - Spain

Re: Changing Seek() deprecated

Postby colinw » Thu May 23, 2013 8:25 am

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


Return to SDK Support

Who is online

Users browsing this forum: No registered users and 1 guest