Use more appropriate types for pt_regs struct, e.g. 16-bit types for 16-bit
[cake.git] / rom / dos / flush.c
blob74b0aaa8fe25f316dbd5c0bf9acd9ae6fef2707e
1 /*
2 Copyright © 1995-2007, 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
51 /* Get pointer to filehandle. */
52 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
54 /* The file must be in write mode. */
55 if( fh->fh_Flags & FHF_WRITE )
57 /* Handle append mode. */
58 if( fh->fh_Flags & FHF_APPEND )
60 InternalSeek( fh, 0, OFFSET_END, DOSBase );
63 return InternalFlush( fh, DOSBase );
65 else if( fh->fh_Pos < fh->fh_End )
67 int offset = fh->fh_Pos - fh->fh_End;
69 fh->fh_Pos = fh->fh_End = fh->fh_Buf;
71 /* Read mode. Try to seek back to the current position. */
72 if( InternalSeek( fh, offset, OFFSET_CURRENT, DOSBase ) < 0 )
74 return FALSE;
78 return TRUE;
80 AROS_LIBFUNC_EXIT
81 } /* Flush */