Detabbed
[AROS.git] / rom / dos / flush.c
blob07cbc7bb40a72d179081f4ea825977deb092dff8
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <dos/dosextens.h>
9 #include <proto/dos.h>
10 #include "dos_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/dos.h>
17 AROS_LH1(LONG, Flush,
19 /* SYNOPSIS */
20 AROS_LHA(BPTR, file, D1),
22 /* LOCATION */
23 struct DosLibrary *, DOSBase, 60, Dos)
25 /* FUNCTION
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.
30 INPUTS
31 file - filehandle
33 RESULT
34 != 0 on success, 0 on error. IoErr() gives additional information
35 in that case.
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 /* Get pointer to filehandle. */
52 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
54 if (!fh)
55 return DOSTRUE;
57 /* The file must be in write mode. */
58 if( fh->fh_Flags & FHF_WRITE )
60 /* Handle append mode. */
61 if( fh->fh_Flags & FHF_APPEND )
63 InternalSeek( fh, 0, OFFSET_END, DOSBase );
66 return InternalFlush( fh, DOSBase );
68 else if( fh->fh_Pos < fh->fh_End )
70 int offset = fh->fh_Pos - fh->fh_End;
72 fh->fh_Pos = fh->fh_End = 0;
74 /* Read mode. Try to seek back to the current position. */
75 if( InternalSeek( fh, offset, OFFSET_CURRENT, DOSBase ) < 0 )
77 return FALSE;
81 return TRUE;
83 AROS_LIBFUNC_EXIT
84 } /* Flush */