Include <X11/Xlib.h> even if USE_VIDMODE is
[tangerine.git] / rom / exec / closedevice.c
blob203a337f2d9acfb569c227e0ae2dd8ce5afeeb3c
1 /*
2 Copyright © 1995-2001, 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 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
28 # define NATIVE(x) x
29 #else
30 # define NATIVE(x) /* eps */
31 #endif
33 /*****************************************************************************
35 NAME */
37 AROS_LH1(void, CloseDevice,
39 /* SYNOPSIS */
40 AROS_LHA(struct IORequest *, iORequest, A1),
42 /* LOCATION */
43 struct ExecBase *, SysBase, 75, Exec)
45 /* FUNCTION
46 Closes a previously opened device. Any outstanding I/O requests must
47 be finished. It is safe to call CloseDevice with a cleared iorequest
48 structure or one that failed to open.
50 INPUTS
51 iORequest - Pointer to iorequest structure.
53 RESULT
55 NOTES
57 EXAMPLE
59 BUGS
61 SEE ALSO
62 OpenDevice().
64 INTERNALS
66 ******************************************************************************/
68 AROS_LIBFUNC_INIT
69 NATIVE(BPTR dc_ret;)
71 D(bug("CloseDevice $%lx $%lx (\"%s\") by \"%s\"\n", iORequest, iORequest->io_Device,
72 iORequest->io_Device ? iORequest->io_Device->dd_Library.lib_Node.ln_Name : "(null)",
73 SysBase->ThisTask->tc_Node.ln_Name));
75 /* Single-thread the close routine. */
76 Forbid();
78 /* Something to do? */
79 if(iORequest->io_Device!=NULL)
81 NATIVE(dc_ret =) AROS_LVO_CALL1(BPTR,
82 AROS_LCA(struct IORequest *,iORequest, A1),
83 struct Device *,iORequest->io_Device,2,
86 Normally you'd expect the device to be expunged if this returns
87 non-zero, but this is only exec which doesn't know anything about
88 seglists - therefore dos.library has to SetFunction() into this
89 vector for the additional functionality.
92 /* Trash device field */
93 iORequest->io_Device=(struct Device *)-1;
95 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
96 else
98 /* local vars not guaranteed to be initialised to 0 */
99 dc_ret = 0;
101 #endif
103 /* All done. */
104 Permit();
106 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
108 Kludge to force the seglist to register d0. Ramlib patches this
109 vector for seglist expunge capability and expects the seglist in
110 d0 after it has called the original (this) function.
111 Also see CloseLibrary().
114 /* Put the library base in register d0 */
115 register BPTR ret __asm("d0") = dc_ret;
117 /* Make sure the above assignment isn't optimized away */
118 asm volatile("": : "r" (ret));
120 #endif
122 AROS_LIBFUNC_EXIT
123 } /* CloseDevice */