Minor fixes to comments.
[AROS.git] / rom / exec / closedevice.c
blob6bc490a1e31472fe50efbea24afb536b1c0bd4a6
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Close a device.
6 Lang: english
7 */
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <exec/io.h>
11 #include <exec/devices.h>
12 #include <dos/dos.h>
13 #include <aros/libcall.h>
14 #include <proto/exec.h>
16 #include "exec_debug.h"
17 #ifndef DEBUG_CloseDevice
18 # define DEBUG_CloseDevice 0
19 #endif
20 #undef DEBUG
21 #if DEBUG_CloseDevice
22 # define DEBUG 1
23 #endif
24 #include <aros/debug.h>
25 #undef kprintf
27 /*****************************************************************************
29 NAME */
31 AROS_LH1(void, CloseDevice,
33 /* SYNOPSIS */
34 AROS_LHA(struct IORequest *, iORequest, A1),
36 /* LOCATION */
37 struct ExecBase *, SysBase, 75, Exec)
39 /* FUNCTION
40 Closes a previously opened device. Any outstanding I/O requests must
41 be finished. It is safe to call CloseDevice with a cleared iorequest
42 structure or one that failed to open.
44 INPUTS
45 iORequest - Pointer to iorequest structure.
47 RESULT
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 OpenDevice()
58 INTERNALS
60 ******************************************************************************/
62 AROS_LIBFUNC_INIT
63 BPTR dc_ret;
65 D(bug("CloseDevice $%lx $%lx (\"%s\") by \"%s\"\n", iORequest, iORequest->io_Device,
66 iORequest->io_Device ? iORequest->io_Device->dd_Library.lib_Node.ln_Name : "(null)",
67 SysBase->ThisTask->tc_Node.ln_Name));
69 /* Single-thread the close routine. */
70 Forbid();
72 /* Something to do? */
73 if(iORequest->io_Device!=NULL)
75 dc_ret = AROS_LVO_CALL1(BPTR,
76 AROS_LCA(struct IORequest *,iORequest, A1),
77 struct Device *,iORequest->io_Device,2,
80 Normally you'd expect the device to be expunged if this returns
81 non-zero, but this is only exec which doesn't know anything about
82 seglists - therefore dos.library has to SetFunction() into this
83 vector for the additional functionality.
86 /* Trash device field */
87 iORequest->io_Device=(struct Device *)-1;
89 else
91 /* local vars not guaranteed to be initialised to 0 */
92 dc_ret = 0;
95 /* All done. */
96 Permit();
98 AROS_COMPAT_SETD0(dc_ret);
99 AROS_LIBFUNC_EXIT
100 } /* CloseDevice */