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_intern.h"
11 /*****************************************************************************
14 #include <proto/dos.h>
19 AROS_LHA(BPTR
, file
, D1
),
20 AROS_LHA(LONG
, position
, D2
),
21 AROS_LHA(LONG
, mode
, D3
),
24 struct DosLibrary
*, DOSBase
, 11, Dos
)
27 Changes the current read/write position in a file and/or
28 reads the current position, e.g to get the current position
29 do a Seek(file,0,OFFSET_CURRENT).
31 This function may fail (obviously) on certain devices such
32 as pipes or console handlers.
36 position - relative offset in bytes (positive, negative or 0).
37 mode - Where to count from. Either OFFSET_BEGINNING,
38 OFFSET_CURRENT or OFFSET_END.
41 Absolute position in bytes before the Seek(), -1 if an error
42 happened. IoErr() will give additional information in that case.
54 *****************************************************************************/
58 /* Get pointer to filehandle. */
59 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
63 SetIoErr(ERROR_INVALID_LOCK
);
67 /* If the file is in append mode, seeking is not allowed. */
68 if( fh
->fh_Flags
& FHF_APPEND
)
70 return InternalSeek( fh
, 0, OFFSET_CURRENT
, DOSBase
);
73 /* If the file is in write mode flush it. */
74 if( fh
->fh_Flags
& FHF_WRITE
)
76 InternalFlush( fh
, DOSBase
);
80 /* Read mode. Adjust the offset so that buffering is
81 taken into account. */
82 if (fh
->fh_Pos
< fh
->fh_End
&& mode
== OFFSET_CURRENT
)
83 offset
= (LONG
)(fh
->fh_Pos
- fh
->fh_End
);
86 /* Read mode. Just reinit the buffers. We can't call
87 Flush() in this case as that would end up in
89 fh
->fh_Pos
= fh
->fh_End
= 0;
92 ret
= InternalSeek( fh
, position
+ offset
, mode
, DOSBase
);
93 return (ret
== -1) ? -1 : (ret
+ offset
);