Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / dos / flush.c
blobed738433b0c19e567d33e76b683eb35980be0233
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include <dos/dosextens.h>
6 #include <proto/dos.h>
7 #include "dos_intern.h"
9 #define DEBUG 1
10 #include <aros/debug.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
50 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
52 /* Get pointer to filehandle. */
53 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
55 /* The file must be in write mode. */
56 if( fh->fh_Flags & FHF_WRITE )
58 /* Handle append mode. */
59 if( fh->fh_Flags & FHF_APPEND )
61 InternalSeek( fh, 0, OFFSET_END, DOSBase );
64 return InternalFlush( fh, DOSBase );
66 else if( fh->fh_Pos < fh->fh_End )
68 int offset = fh->fh_Pos - fh->fh_End;
70 fh->fh_Pos = fh->fh_End = fh->fh_Buf;
72 /* Read mode. Try to seek back to the current position. */
73 if( InternalSeek( file, offset, OFFSET_CURRENT, DOSBase ) < 0 )
75 return FALSE;
79 return TRUE;
81 AROS_LIBFUNC_EXIT
82 } /* Flush */