replace value with speed definition
[AROS.git] / test / makelib.c
blob567cfb439af24c1627371bb710f7df6a7467cfa1
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_LHA(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_LHA(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 = LIB_expunge(DummyBase);
99 return ret;
101 AROS_USERFUNC_EXIT
104 /********/
106 int LIB_reserved(void)
108 return 0;
111 static struct Library *dummylib;
113 static void *function_array[] =
115 Dummy_LIB_open,
116 LIB_close,
117 LIB_expunge,
118 LIB_reserved,
119 (void*)~0,
122 /* Must use the global sysbase */
123 #undef SysBase
125 static struct Library *dummy = NULL;
127 int AddDummy(void)
129 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
131 dummylib = MakeLibrary(function_array,NULL,
132 (ULONG (* const )())LIB_init,
133 sizeof(struct DummyBase),NULL);
135 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
136 if (dummylib)
138 AddLibrary(dummylib);
139 #if DUMMY_OPEN_BUG
140 D(bug("%s: before OpenLibrary\n", __FUNCTION__));
141 dummy = OpenLibrary("dummy.library", 0); /* segfaults */
142 D(bug("%s: after OpenLibrary\n", __FUNCTION__));
143 if (!dummy)
144 return 0;
145 #endif
146 return 1;
148 return 0;
151 int RemoveDummy(void)
153 if (dummy)
154 CloseLibrary(dummy);
155 if (dummylib)
157 RemLibrary(dummylib);
159 return 1;
162 int __nocommandline = 1;
164 int main (void)
166 AddDummy();
167 #if REMOVE_DUMMY
168 RemoveDummy();
169 #endif
171 return 0;