arch/m68k-all/exec: Add Exec/Supervisor
[AROS.git] / test / makelib.c
blobb42422526030b9ee7be6273ea7c3135a05f506a8
1 /* Create a Library, add it to the system, and try to open it.
2 */
4 #define DUMMY_OPEN_BUG 1
5 #define INIT_DEBUG_BUG 0
6 #define REMOVE_DUMMY 1
8 #include <exec/types.h>
9 #include <exec/libraries.h>
10 #include <proto/exec.h>
12 #ifndef AROS_ASMCALL_H
13 # include <aros/asmcall.h>
14 #endif
16 struct DummyBase
18 struct Library library;
19 struct ExecBase *sysbase;
22 #undef SysBase
23 #define SysBase (DummyBase->sysbase)
25 #define DEBUG 1
26 #include <aros/debug.h>
28 /********/
30 AROS_UFH3(struct DummyBase *,LIB_init,
31 AROS_LHA(struct DummyBase *, DummyBase, D0),
32 AROS_LHA(ULONG, seglist, A0),
33 AROS_LHA(struct ExecBase *, sysbase, A6))
35 AROS_USERFUNC_INIT
37 #if INIT_DEBUG_BUG
38 D(bug("in LIB_init a\n")); /* segfaults */
39 #endif
40 DummyBase->sysbase = sysbase;
42 DummyBase->library.lib_Node.ln_Type = NT_LIBRARY;
43 DummyBase->library.lib_Node.ln_Name = "dummy.library";
44 DummyBase->library.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
45 DummyBase->library.lib_Version = 1;
46 DummyBase->library.lib_Revision = 0;
47 DummyBase->library.lib_IdString = "dummy.library";
49 D(bug("dummy.library: Init succesfull\n"));
50 return DummyBase;
52 AROS_USERFUNC_EXIT
55 /********/
57 AROS_LH1(struct DummyBase *, LIB_open,
58 AROS_LHA(ULONG, version, D0),
59 struct DummyBase *, DummyBase, 1, Dummy)
61 AROS_LIBFUNC_INIT
63 DummyBase->library.lib_OpenCnt++;
64 DummyBase->library.lib_Flags &= ~LIBF_DELEXP;
65 return DummyBase;
67 AROS_LIBFUNC_EXIT
70 /********/
72 AROS_UFH1(ULONG,LIB_expunge,
73 AROS_UFHA(struct DummyBase *, DummyBase, A6))
75 AROS_USERFUNC_INIT
77 if (DummyBase->library.lib_OpenCnt == 0)
78 Remove((struct Node *)DummyBase);
79 else
80 DummyBase->library.lib_Flags |= LIBF_DELEXP;
81 return 0;
83 AROS_USERFUNC_EXIT
86 /********/
88 AROS_UFH1(ULONG,LIB_close,
89 AROS_UFHA(struct DummyBase *, DummyBase, D0))
91 AROS_USERFUNC_INIT
93 ULONG ret = 0;
95 DummyBase->library.lib_OpenCnt--;
96 if (!DummyBase->library.lib_OpenCnt)
97 if (DummyBase->library.lib_Flags & LIBF_DELEXP)
98 ret = AROS_UFC1(ULONG,LIB_expunge,
99 AROS_UFCA(struct DummyBase *, DummyBase, A6));
100 return ret;
102 AROS_USERFUNC_EXIT
105 /********/
107 int LIB_reserved(void)
109 return 0;
112 static struct Library *dummylib;
114 static void *function_array[] =
116 Dummy_LIB_open,
117 LIB_close,
118 LIB_expunge,
119 LIB_reserved,
120 (void*)~0,
123 /* Must use the global sysbase */
124 #undef SysBase
126 static struct Library *dummy = NULL;
128 int AddDummy(void)
130 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
132 dummylib = MakeLibrary(function_array,NULL,
133 (ULONG (* const )())LIB_init,
134 sizeof(struct DummyBase),NULL);
136 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
137 if (dummylib)
139 AddLibrary(dummylib);
140 #if DUMMY_OPEN_BUG
141 D(bug("%s: before OpenLibrary\n", __FUNCTION__));
142 dummy = OpenLibrary("dummy.library", 0); /* segfaults */
143 D(bug("%s: after OpenLibrary\n", __FUNCTION__));
144 if (!dummy)
145 return 0;
146 #endif
147 return 1;
149 return 0;
152 int RemoveDummy(void)
154 if (dummy)
155 CloseLibrary(dummy);
156 if (dummylib)
158 RemLibrary(dummylib);
160 return 1;
163 int __nocommandline = 1;
165 int main (void)
167 AddDummy();
168 #if REMOVE_DUMMY
169 RemoveDummy();
170 #endif
172 return 0;