2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #include <dos/dosextens.h>
10 #include "dos_intern.h"
12 /*****************************************************************************
15 #include <proto/dos.h>
20 AROS_LHA(BPTR
, file
, D1
),
23 struct DosLibrary
*, DOSBase
, 60, Dos
)
26 Flushes any pending writes on the file. If the file was used
27 for input and there is still some data to read it tries to
28 seek back to the expected position.
34 != 0 on success, 0 on error. IoErr() gives additional information
38 On AROS calling Flush() from different tasks on the same file handle
39 is serialised. This means that most of the time it is possible to
40 do I/O in one task to a file handle where Flush() is being called
41 in another task on that file handle.
42 No multi-thread safety is guaranteed though and data may be lost if
43 I/O is done in parallel from different tasks on the same file handle.
53 *****************************************************************************/
57 /* Get pointer to filehandle. */
58 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
63 /* The file must be in write mode. */
64 if( fh
->fh_Flags
& FHF_WRITE
)
66 /* Handle append mode. */
67 if( fh
->fh_Flags
& FHF_APPEND
)
69 InternalSeek( fh
, 0, OFFSET_END
, DOSBase
);
72 return InternalFlush( fh
, DOSBase
);
74 else if( fh
->fh_Pos
< fh
->fh_End
)
76 int offset
= fh
->fh_Pos
- fh
->fh_End
;
78 fh
->fh_Pos
= fh
->fh_End
= 0;
80 /* Read mode. Try to seek back to the current position. */
81 if( InternalSeek( fh
, offset
, OFFSET_CURRENT
, DOSBase
) < 0 )