Fixed typo in structure name.
[AROS.git] / compiler / autoinit / libraries.c
blob105d45a6b1fe1bba0416f6a3eb3f5fd7574a4748
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: autoinit library - automatic library opening/closing handling
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include <dos/dos.h>
12 #include <aros/symbolsets.h>
13 #include <aros/autoinit.h>
14 #include <intuition/intuition.h>
15 #include <dos/dosextens.h>
16 #include <proto/intuition.h>
17 #include <proto/dos.h>
18 #include <stdlib.h>
20 DEFINESET(LIBS);
22 AROS_MAKE_ASM_SYM(int, dummy, __includelibrarieshandling, 0);
23 AROS_EXPORT_ASM_SYM(__includelibrarieshandling);
25 int _set_open_libraries_list(const void * const list[], struct ExecBase *SysBase)
27 int pos;
28 struct libraryset *set;
30 D(bug("[Autoinit] Opening libraries...\n"));
32 ForeachElementInSet(list, 1, pos, set)
34 LONG version = *set->versionptr;
35 BOOL do_not_fail = 0;
37 if (version < 0)
39 version = -(version + 1);
40 do_not_fail = 1;
43 D(bug("[Autoinit] %s version %d... ", set->name, version));
44 *set->baseptr = OpenLibrary(set->name, version);
45 D(bug("0x%p\n", *set->baseptr));
47 if (!do_not_fail && *set->baseptr == NULL)
49 const IPTR args[] = {version, (IPTR)set->name};
50 __showerror
52 "Could not open version %ld or higher of library \"%s\".",
53 args
56 return 0;
60 D(bug("[Autoinit] Done\n"));
61 return 1;
64 void _set_close_libraries_list(const void * const list[], struct ExecBase *SysBase)
66 int pos;
67 struct libraryset *set;
69 ForeachElementInSet(list, 1, pos, set)
71 if (*set->baseptr)
73 CloseLibrary(*set->baseptr);
74 *set->baseptr = NULL;
79 DEFINESET(RELLIBS);
81 AROS_MAKE_ASM_SYM(int, dummyrel, __includerellibrarieshandling, 0);
82 AROS_EXPORT_ASM_SYM(__includerellibrarieshandling);
84 int _set_open_rellibraries_list(APTR base, const void * const list[], struct ExecBase *SysBase)
86 int pos;
87 struct rellibraryset *set;
89 D(bug("[Autoinit] Opening relative libraries for %s @ 0x%p...\n", ((struct Node *)base)->ln_Name, base));
91 ForeachElementInSet(list, 1, pos, set)
93 LONG version = *set->versionptr;
94 BOOL do_not_fail = 0;
95 void **baseptr = (void **)((char *)base + *set->baseoffsetptr);
97 if (version < 0)
99 version = -(version + 1);
100 do_not_fail = 1;
103 D(bug("[Autoinit] Offset %d, %s version %d... ", *set->baseoffsetptr, set->name, version));
104 *baseptr = OpenLibrary(set->name, version);
105 D(bug("0x%p\n", *baseptr));
107 if (!do_not_fail && *baseptr == NULL)
109 const IPTR args[]= {version, (IPTR)set->name};
110 __showerror
112 "Could not open version %ld or higher of library \"%s\".",
113 args
116 return 0;
120 D(bug("[Autoinit] %s Done\n", ((struct Node *)base)->ln_Name));
121 return 1;
124 void _set_close_rellibraries_list(APTR base, const void * const list[], struct ExecBase *SysBase)
126 int pos;
127 struct rellibraryset *set;
128 struct Library **baseptr;
130 ForeachElementInSet(list, 1, pos, set)
132 baseptr = (struct Library **)((char *)base + *set->baseoffsetptr);
134 if (*baseptr)
136 CloseLibrary(*baseptr);
137 *baseptr = NULL;