Indentation fix, cleanup.
[AROS.git] / rom / dos / flush.c
blob9d08e50f54f34ca0a69eba23c893d9ef5cc386dc
1 /*
2 Copyright © 1995-2013, 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
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.
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
57 /* Get pointer to filehandle. */
58 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
60 if (!fh)
61 return DOSTRUE;
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 )
83 return FALSE;
87 return TRUE;
89 AROS_LIBFUNC_EXIT
90 } /* Flush */