home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / l / l920413.zip / BASE.C next >
C/C++ Source or Header  |  1992-04-13  |  830b  |  44 lines

  1. /* call this with the following defines (for example):
  2.    
  3.    LIBRARY_NAME        "intuition.library"
  4.    LIBRARY_BASE     IntuitionBase
  5.    LIBRARY_VERS     __auto_intui_vers
  6.  
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <inline/exec.h>
  11.  
  12. #include <unistd.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16.  
  17. struct Library * LIBRARY_BASE = 0;
  18. extern int LIBRARY_VERS;
  19.  
  20. #define STRING(a) a, sizeof (a) - 1
  21.  
  22. static void
  23. constructor ()
  24. {
  25.   if (!(LIBRARY_BASE = OpenLibrary (LIBRARY_NAME, LIBRARY_VERS)))
  26.     {
  27.       write (2, STRING("Can't open " LIBRARY_NAME "!\n"));
  28.       abort ();
  29.     }
  30. }
  31.  
  32. static void
  33. destructor ()
  34. {
  35.   if (LIBRARY_BASE)
  36.     {
  37.       CloseLibrary (LIBRARY_BASE);
  38.       LIBRARY_BASE = 0;
  39.     }
  40. }
  41.  
  42. asm ("    .text;     .stabs \"___CTOR_LIST__\",22,0,0,_constructor");
  43. asm ("    .text;     .stabs \"___DTOR_LIST__\",22,0,0,_destructor");
  44.