Detabbed
[AROS.git] / rom / dos / internalflush.c
blob39d5a72019d9a1c325425f42197208335af4d34a
1 /*
2 Copyright © 2002-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <proto/dos.h>
8 #include <aros/debug.h>
10 #include "dos_intern.h"
12 LONG InternalFlush( struct FileHandle *fh, struct DosLibrary *DOSBase )
14 LONG position;
16 /* Make sure the input parameters are sane. */
17 ASSERT_VALID_PTR( fh );
18 ASSERT_VALID_PTR( BADDR(fh->fh_Buf) );
20 ASSERT(fh->fh_End > 0);
21 ASSERT(fh->fh_Pos >= 0);
22 ASSERT(fh->fh_Pos <= fh->fh_End );
24 /* Write the data, in many pieces if the first one isn't enough. */
25 position = 0;
27 while( position < fh->fh_Pos )
29 LONG size;
31 size = Write( MKBADDR(fh), BADDR(fh->fh_Buf) + position, fh->fh_Pos - position );
33 /* An error happened? No success. */
34 if( size < 0 )
36 fh->fh_Flags &= ~FHF_WRITE;
38 return FALSE;
41 position += size;
44 /* Reset the buffer. */
45 fh->fh_Pos = 0;
47 return TRUE;