2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Change the current read/write position in a file.
8 #include <proto/exec.h>
9 #include <dos/filesystem.h>
10 #include "dos_intern.h"
12 /*****************************************************************************
15 #include <proto/dos.h>
20 AROS_LHA(BPTR
, file
, D1
),
21 AROS_LHA(LONG
, position
, D2
),
22 AROS_LHA(LONG
, mode
, D3
),
25 struct DosLibrary
*, DOSBase
, 11, Dos
)
28 Changes the current read/write position in a file and/or
29 reads the current position, e.g to get the current position
30 do a Seek(file,0,OFFSET_CURRENT).
32 This function may fail (obviously) on certain devices such
33 as pipes or console handlers.
37 position - relative offset in bytes (positive, negative or 0).
38 mode - Where to count from. Either OFFSET_BEGINNING,
39 OFFSET_CURRENT or OFFSET_END.
42 Absolute position in bytes before the Seek(), -1 if an error
43 happened. IoErr() will give additional information in that case.
55 *****************************************************************************/
59 /* Get pointer to filehandle. */
60 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
63 /* If the file is in append mode, seeking is not allowed. */
64 if( fh
->fh_Flags
& FHF_APPEND
)
66 return InternalSeek( fh
, 0, OFFSET_CURRENT
, DOSBase
);
69 /* If the file is in write mode flush it. */
70 if( fh
->fh_Flags
& FHF_WRITE
)
72 InternalFlush( fh
, DOSBase
);
76 /* Read mode. Adjust the offset so that buffering is
77 taken into account. */
78 if (fh
->fh_Pos
< fh
->fh_End
&& mode
== OFFSET_CURRENT
)
79 offset
= (LONG
)(fh
->fh_Pos
- fh
->fh_End
);
82 /* Read mode. Just reinit the buffers. We can't call
83 Flush() in this case as that would end up in
85 fh
->fh_Pos
= fh
->fh_End
= 0;
88 ret
= InternalSeek( fh
, position
+ offset
, mode
, DOSBase
);
89 return (ret
== -1) ? -1 : (ret
+ offset
);