Build fix.
[AROS.git] / rom / dos / close.c
blob7763404d862fcbcb6f59327f38dd9327578abd58
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
8 #include <proto/exec.h>
9 #include <dos/dosextens.h>
10 #include <dos/filesystem.h>
11 #include <proto/dos.h>
12 #include "dos_intern.h"
13 #include <aros/debug.h>
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH1(BOOL, Close,
22 /* SYNOPSIS */
23 AROS_LHA(BPTR, file, D1),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 6, Dos)
28 /* FUNCTION
29 Close a filehandle opened with Open(). If the file was used
30 with buffered I/O the final write may fail and thus Close()
31 return an error. The file is closed in any case.
33 INPUTS
34 file -- filehandle
36 RESULT
37 0 if there was an error. != 0 on success.
39 NOTES
40 This function is identical to UnLock().
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 *****************************************************************************/
52 /*****************************************************************************
54 NAME
55 #include <clib/dos_protos.h>
57 AROS_LH1(BOOL, UnLock,
59 SYNOPSIS
60 AROS_LHA(BPTR, lock, D1),
62 LOCATION
63 struct DosLibrary *, DOSBase, 15, Dos)
65 FUNCTION
66 Free a lock created with Lock().
68 INPUTS
69 lock -- The lock to free
71 RESULT
73 NOTES
74 This function is identical to Close() - see there.
76 EXAMPLE
78 BUGS
80 SEE ALSO
82 INTERNALS
84 *****************************************************************************/
85 /*AROS alias UnLock Close */
87 AROS_LIBFUNC_INIT
89 /* Get pointer to filehandle */
90 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
92 /* Get space for I/O request. Use stack for now. */
93 struct IOFileSys iofs;
95 /* The returncode defaults to OK. */
96 BOOL ret = 1;
98 ASSERT_VALID_PTR_OR_NULL(fh);
100 /* 0 handles are OK */
101 if(file == BNULL)
102 return ret;
104 /* If the filehandle has a pending write on it Flush() the buffer. */
105 if(fh->fh_Flags & FHF_WRITE)
106 ret = Flush(file);
108 /* Prepare I/O request. */
109 InitIOFS(&iofs, FSA_CLOSE, DOSBase);
111 iofs.IOFS.io_Device = fh->fh_Device;
112 iofs.IOFS.io_Unit = fh->fh_Unit;
114 /* Send the request. No errors possible. */
115 DosDoIO(&iofs.IOFS);
117 /* Free the filehandle which was allocated in Open(), CreateDir()
118 and such. */
119 FreeDosObject(DOS_FILEHANDLE, fh);
121 return ret;
123 AROS_LIBFUNC_EXIT
124 } /* Close */