Added kernel module for starting the usb stack at boot time. It's not activated thoug...
[cake.git] / rom / dos / close.c
blob0c821273e1a7fc9c93b094c7be6c8336235e960e
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"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH1(BOOL, Close,
21 /* SYNOPSIS */
22 AROS_LHA(BPTR, file, D1),
24 /* LOCATION */
25 struct DosLibrary *, DOSBase, 6, Dos)
27 /* FUNCTION
28 Close a filehandle opened with Open(). If the file was used
29 with buffered I/O the final write may fail and thus Close()
30 return an error. The file is closed in any case.
32 INPUTS
33 file -- filehandle
35 RESULT
36 0 if there was an error. != 0 on success.
38 NOTES
39 This function is identical to UnLock().
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 *****************************************************************************/
51 /*****************************************************************************
53 NAME
54 #include <clib/dos_protos.h>
56 AROS_LH1(BOOL, UnLock,
58 SYNOPSIS
59 AROS_LHA(BPTR, lock, D1),
61 LOCATION
62 struct DosLibrary *, DOSBase, 15, Dos)
64 FUNCTION
65 Free a lock created with Lock().
67 INPUTS
68 lock -- The lock to free
70 RESULT
72 NOTES
73 This function is identical to Close() - see there.
75 EXAMPLE
77 BUGS
79 SEE ALSO
81 INTERNALS
83 *****************************************************************************/
84 /*AROS alias UnLock Close */
86 AROS_LIBFUNC_INIT
88 /* Get pointer to filehandle */
89 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
91 /* Get space for I/O request. Use stack for now. */
92 struct IOFileSys iofs;
94 /* The returncode defaults to OK. */
95 BOOL ret = 1;
97 /* 0 handles are OK */
98 if(file == NULL)
99 return ret;
101 /* If the filehandle has a pending write on it Flush() the buffer. */
102 if(fh->fh_Flags & FHF_WRITE)
103 ret = Flush(file);
105 /* Prepare I/O request. */
106 InitIOFS(&iofs, FSA_CLOSE, DOSBase);
108 iofs.IOFS.io_Device = fh->fh_Device;
109 iofs.IOFS.io_Unit = fh->fh_Unit;
111 /* Send the request. No errors possible. */
112 DosDoIO(&iofs.IOFS);
114 /* Free the filehandle which was allocated in Open(), CreateDir()
115 and such. */
116 FreeDosObject(DOS_FILEHANDLE, fh);
118 return ret;
120 AROS_LIBFUNC_EXIT
121 } /* Close */