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)
Changing Seek() deprecated
- thomasrapp
- Posts: 310
- Joined: Sat Jun 18, 2011 11:22 pm
Re: Changing Seek() deprecated
RTFM ?javierdlr wrote:TIA. What am I missing?
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.
- javierdlr
- Beta Tester
- Posts: 389
- Joined: Sun Jun 19, 2011 10:13 pm
- Location: Donostia (GUIPUZCOA) - Spain
- Contact:
Re: Changing Seek() deprecated
oups, you're right will try to read more carefully next time THX mate!!!
- colinw
- AmigaOS Core Developer
- Posts: 207
- Joined: Mon Aug 15, 2011 9:20 am
- Location: Brisbane, QLD. Australia.
Re: Changing Seek() deprecated
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);
}
{
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.
- javierdlr
- Beta Tester
- Posts: 389
- Joined: Sun Jun 19, 2011 10:13 pm
- Location: Donostia (GUIPUZCOA) - Spain
- Contact:
Re: Changing Seek() deprecated
THX all, just chnged to Seek64 and think updated all to int64 values, will do some checks/test and see what happens. TIA
- colinw
- AmigaOS Core Developer
- Posts: 207
- Joined: Mon Aug 15, 2011 9:20 am
- Location: Brisbane, QLD. Australia.
Re: Changing Seek() deprecated
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.
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.