home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / utility / utility_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  4.1 KB  |  168 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: utility_init.c,v 1.6 1996/10/24 15:49:28 aros Exp $
  4.     $Log: utility_init.c,v $
  5.     Revision 1.6  1996/10/24 15:49:28  aros
  6.     Use the new "AROS" macros
  7.  
  8.     Fixed severe bug: The size of the library was "struct UtilityBase" instead
  9.     of "struct IntUtilityBase" which caused a MemCorrupt-Alert.
  10.  
  11.     Use GetIntUtilityBase() to access the private fields.
  12.  
  13.     Revision 1.5  1996/09/11 16:54:31  digulla
  14.     Always use AROS_SLIB_ENTRY() to access shared external symbols, because
  15.     some systems name an external symbol "x" as "_x" and others as "x".
  16.     (The problem arises with assembler symbols which might differ)
  17.  
  18.     Revision 1.4  1996/09/11 14:03:56  digulla
  19.     Quick hack to make it work again.
  20.  
  21.     Revision 1.3  1996/08/13 14:11:54  digulla
  22.     Replaced AROS_LA by AROS_LHA
  23.  
  24.     Revision 1.2  1996/08/01 17:41:42  digulla
  25.     Added standard header for all files
  26.  
  27.     Desc:
  28.     Lang:
  29. */
  30. #include <exec/resident.h>
  31. #include <clib/exec_protos.h>
  32. #include <aros/libcall.h>
  33. #include <dos/dos.h>
  34. #include "utility_intern.h"
  35. /* #include <utility/utility.h> */
  36.  
  37. static const char name[];
  38. static const char version[];
  39. static const APTR inittabl[4];
  40. static void *const Utility_functable[];
  41. struct UtilityBase *AROS_SLIB_ENTRY(init,Utility) ();
  42. extern const char Utility_end;
  43.  
  44. int Utility_entry(void)
  45. {
  46.     /* If the library was executed by accident return error code. */
  47.     return -1;
  48. }
  49.  
  50. const struct Resident Utility_resident=
  51. {
  52.     RTC_MATCHWORD,
  53.     (struct Resident *)&Utility_resident,
  54.     (APTR)&Utility_end,
  55.     RTF_AUTOINIT,
  56.     39,
  57.     NT_LIBRARY,
  58.     0,
  59.     (char *)name,
  60.     (char *)&version[6],
  61.     (ULONG *)inittabl
  62. };
  63.  
  64. static const char name[]=UTILITYNAME;
  65.  
  66. static const char version[]="$VER: utility 39.0 (5.6.96)\n\015";
  67.  
  68. static const APTR inittabl[4]=
  69. {
  70.     (APTR)sizeof(struct IntUtilityBase),
  71.     (APTR)Utility_functable,
  72.     NULL,
  73.     &AROS_SLIB_ENTRY(init,Utility)
  74. };
  75.  
  76. #ifdef SysBase
  77. #undef SysBase
  78. #endif
  79. #define SysBase GetIntUtilityBase(UtilityBase)->ub_SysBase
  80.  
  81. AROS_LH2(struct UtilityBase *, init,
  82.  AROS_LHA(struct UtilityBase *, UtilityBase, D0),
  83.  AROS_LHA(BPTR,               segList,   A0),
  84.        struct ExecBase *, sysBase, 0, Utility)
  85. {
  86.     AROS_LIBFUNC_INIT
  87.  
  88.     /* Store arguments */
  89.     GetIntUtilityBase(UtilityBase)->ub_SysBase=sysBase;
  90.     GetIntUtilityBase(UtilityBase)->ub_SegList=segList;
  91.  
  92.     /* You would return NULL if the init failed */
  93.     return UtilityBase;
  94.     AROS_LIBFUNC_EXIT
  95. }
  96.  
  97. AROS_LH1(struct UtilityBase *, open,
  98.  AROS_LHA(ULONG, version, D0),
  99.        struct UtilityBase *, UtilityBase, 1, Utility)
  100. {
  101.     AROS_LIBFUNC_INIT
  102.  
  103.     /* Keep compiler happy */
  104.     version=0;
  105.  
  106.     /* I have one more opener. */
  107.     UtilityBase->ub_LibNode.lib_OpenCnt++;
  108.     UtilityBase->ub_LibNode.lib_Flags&=~LIBF_DELEXP;
  109.  
  110.     /* You would return NULL if the open failed. */
  111.     return UtilityBase;
  112.     AROS_LIBFUNC_EXIT
  113. }
  114.  
  115. AROS_LH0(BPTR, close,
  116.        struct UtilityBase *, UtilityBase, 2, Utility)
  117. {
  118.     AROS_LIBFUNC_INIT
  119.  
  120.     /* I have one fewer opener. */
  121.     if(!--UtilityBase->ub_LibNode.lib_OpenCnt)
  122.     {
  123.     /* Delayed expunge pending? */
  124.     if(UtilityBase->ub_LibNode.lib_Flags&LIBF_DELEXP)
  125.         /* Then expunge the library */
  126.         return expunge();
  127.     }
  128.     return 0;
  129.     AROS_LIBFUNC_EXIT
  130. }
  131.  
  132. AROS_LH0(BPTR, expunge,
  133.        struct UtilityBase *, UtilityBase, 3, Utility)
  134. {
  135.     AROS_LIBFUNC_INIT
  136.  
  137.     BPTR ret;
  138.  
  139.     /* Test for openers. */
  140.     if(UtilityBase->ub_LibNode.lib_OpenCnt)
  141.     {
  142.     /* Set the delayed expunge flag and return. */
  143.     UtilityBase->ub_LibNode.lib_Flags|=LIBF_DELEXP;
  144.     return 0;
  145.     }
  146.  
  147.     /* Get rid of the library. Remove it from the list. */
  148.     Remove(&UtilityBase->ub_LibNode.lib_Node);
  149.  
  150.     /* Get returncode here - FreeMem() will destroy the field. */
  151.     ret=GetIntUtilityBase(UtilityBase)->ub_SegList;
  152.  
  153.     /* Free the memory. */
  154.     FreeMem((char *)UtilityBase-UtilityBase->ub_LibNode.lib_NegSize,
  155.         UtilityBase->ub_LibNode.lib_NegSize+UtilityBase->ub_LibNode.lib_PosSize);
  156.  
  157.     return ret;
  158.     AROS_LIBFUNC_EXIT
  159. }
  160.  
  161. AROS_LH0I(int, null,
  162.         struct UtilityBase *, UtilityBase, 4, Utility)
  163. {
  164.     AROS_LIBFUNC_INIT
  165.     return 0;
  166.     AROS_LIBFUNC_EXIT
  167. }
  168.