Use dos.library/CreateNewProc() instead of alib/CreateNewProcTags()
[tangerine.git] / compiler / c_lib / source / lib_source / LibInit.c
blobf3806b1bde0e1a2a3cdb684abb0230467d45008c
1 /*
2 ** $VER: LibInit.c 37.14 (13.8.97)
3 **
4 ** Library initializers and functions to be called by StartUp.c
5 **
6 ** (C) Copyright 1996-97 Andreas R. Kleinert
7 ** All Rights Reserved.
8 */
10 #define __USE_SYSBASE // perhaps only recognized by SAS/C
12 #include <exec/types.h>
13 #include <exec/memory.h>
14 #include <exec/libraries.h>
15 #include <exec/execbase.h>
16 #include <exec/resident.h>
17 #include <exec/initializers.h>
18 #include <graphics/gfxbase.h>
20 #ifdef __MAXON__
21 #include <clib/exec_protos.h>
22 #else
23 #include <proto/exec.h>
24 #endif
25 #include <libcore/compiler.h>
26 #include "libdefs.h"
27 #include "intern.h"
29 struct ExecBase * SysBase = NULL;
30 struct IntuitionBase * IntuitionBase = NULL;
31 struct GfxBase * GfxBase = NULL;
33 #ifndef __AROS__
34 # define INTUITIONNAME "intuition.library" /* AROS defines this */
35 #else
36 # include <intuition/intuitionbase.h> /* INTUITIONNAME */
37 #endif
39 /* -----------------------------------------------------------------------
40 Libraries not shareable between Processes or libraries messing with
41 RamLib (deadlock and crash) may not be opened here - open/close these
42 later locally and or maybe close them fromout L_CloseLibs() when
43 expunging !
45 You may bypass this by opening such libs in L_OpenLib(), but then you
46 will have to a) protect it by a semaphore and b) make sure, that
47 libraries are opened only once (when using global library bases).
49 This function is called exactly once during the life cycle of the
50 library.
51 ----------------------------------------------------------------------- */
52 ULONG SAVEDS STDARGS L_InitLib (LIBBASETYPEPTR LIBBASE)
54 SysBase = LIBBASE->exb_LibHeader.lh_SysBase;
56 IntuitionBase = (struct IntuitionBase *) OpenLibrary (INTUITIONNAME, 37);
57 if (!IntuitionBase)
58 return (FALSE);
60 GfxBase = (struct GfxBase *) OpenLibrary (GRAPHICSNAME, 37);
61 if (!GfxBase)
62 return (FALSE);
64 LIBBASE->exb_IntuitionBase = IntuitionBase;
65 LIBBASE->exb_GfxBase = GfxBase;
67 return (TRUE);
70 #if 0
72 /* -----------------------------------------------------------------------
73 L_OpenLib:
75 This one is called by OpenLib every time someone opens the library.
76 We don't use this in our example, and therefore it's commented out.
77 ----------------------------------------------------------------------- */
78 ULONG SAVEDS STDARGS L_InitLib (LIBBASETYPEPTR LIBBASE)
80 return TRUE;
83 /* -----------------------------------------------------------------------
84 L_CloseLib:
86 This one is called by CloseLib every time someone closes the library.
87 We don't use this in our example, and therefore it's commented out.
89 The function is only called if the library has been opened at least
90 once.
91 ----------------------------------------------------------------------- */
92 void SAVEDS STDARGS L_CloseLib (LIBBASETYPEPTR exb)
95 #endif
97 /* -----------------------------------------------------------------------
98 L_ExpungeLib:
100 This one by default is called by ExpungeLib, which only can take place
101 once and thus per definition is single-threaded.
103 When calling this fromout LibClose instead, you will have to protect it
104 by a semaphore, since you don't know whether a given
105 CloseLibrary(foobase) may cause a Wait(). Additionally, there should be
106 protection, that a library won't be closed twice.
108 This function is also called if L_InitLib() fails, so you can cleanup
109 here.
110 ----------------------------------------------------------------------- */
111 void SAVEDS STDARGS L_ExpungeLib (LIBBASETYPEPTR exb)
113 if (GfxBase)
114 CloseLibrary ((struct Library *) GfxBase);
116 if (IntuitionBase)
117 CloseLibrary ((struct Library *) IntuitionBase);