2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <dos/dosextens.h>
12 #include <proto/dos.h>
13 #include "dos_intern.h"
14 #include <aros/debug.h>
16 /*****************************************************************************
19 #include <proto/dos.h>
24 AROS_LHA(BPTR
, file
, D1
),
27 struct DosLibrary
*, DOSBase
, 6, Dos
)
30 Close a filehandle opened with Open(). If the file was used
31 with buffered I/O, the final write may fail and thus Close()
32 may return an error. The file is closed in any case.
38 0 if there was an error. != 0 on success.
50 *****************************************************************************/
54 /* Get pointer to filehandle */
55 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
56 /* The returncode defaults to OK. */
59 D(bug("[Close] %p: fh = %p\n", file
, fh
));
60 ASSERT_VALID_PTR_OR_NULL(fh
);
62 /* 0 handles are OK */
66 /* Func3 == -1: file was already closed. */
67 if (fh
->fh_Func3
== -1)
68 Alert(AN_FileReclosed
);
70 /* If the filehandle has a pending write on it Flush() the buffer. */
71 if(fh
->fh_Flags
& FHF_WRITE
)
74 ret
= dopacket1(DOSBase
, NULL
, fh
->fh_Type
, ACTION_END
, fh
->fh_Arg1
);
76 /* Free the filehandle which was allocated in Open(), CreateDir()
79 FreeDosObject(DOS_FILEHANDLE
, fh
);