home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / gnulib3.c < prev    next >
C/C++ Source or Header  |  1992-03-22  |  2KB  |  128 lines

  1. /*
  2.  * very important: for the atari keep  this file 16/32 bit int clean
  3.  *    ++jrb
  4.  */
  5.  
  6. #ifndef NO_GNULIB3  /* skip entire file if NO_GNULIB3 */
  7.  
  8. #ifdef atarist
  9. #include <stdlib.h>
  10. #endif
  11.  
  12. typedef struct set_vector
  13. {
  14.   long length;
  15.   long vector[1];
  16.   /* struct set_vector *next; */
  17. } set_vector;
  18.  
  19. extern set_vector __CTOR_LIST__;
  20. extern set_vector __DTOR_LIST__;
  21. set_vector *__dlp;
  22. long __dli;
  23.  
  24. extern  void exit (int);
  25. extern void __do_global_init ();
  26. extern void __do_global_cleanup ();
  27. extern  void on_exit(void*, void*);
  28. extern  void _cleanup();
  29. extern  void _exit(int);
  30.  
  31.  
  32. #if defined(i386) && !defined(sequent)
  33. #define COFF
  34. #endif
  35.  
  36. #ifdef COFF_ENCAPSULATE
  37. #undef COFF
  38. #endif
  39.  
  40. /* 
  41.   ON_EXIT macro commented out - dl 
  42.   Sun on_exit doesn't get linked in right!!!
  43. */
  44.  
  45. #if 0
  46. #if defined(sun)
  47. #define ON_EXIT(PROCP, ARG) \
  48.   do { extern void PROCP (); on_exit (PROCP, ARG); } while (0)
  49. #endif
  50. #endif
  51.  
  52. int
  53. __main ()
  54. {
  55.   /* Gross hack for GNU ld.  This is defined in `builtin.cc'
  56.      from libg++.  */
  57. #ifndef COFF
  58.   extern long __1xyzzy__;
  59. #endif
  60.  
  61. #ifdef ON_EXIT
  62.  
  63. #ifdef sun
  64.   ON_EXIT (_cleanup, 0);
  65. #endif
  66.  
  67.   ON_EXIT (__do_global_cleanup, 0);
  68. #endif
  69.  
  70. #ifdef atarist
  71.   atexit(__do_global_cleanup);
  72. #endif
  73.  
  74.   __dli = __DTOR_LIST__.length;
  75.   __dlp = &__DTOR_LIST__;
  76. #ifndef COFF
  77.   __do_global_init (&__1xyzzy__);
  78. #else
  79.   __do_global_init ();
  80. #endif
  81. }
  82.  
  83. #if !defined(ON_EXIT) && !defined(atarist)
  84.  
  85. void 
  86. exit (status)
  87.      int status;
  88. {
  89.   __do_global_cleanup ();
  90.   _cleanup ();
  91.   _exit (status);
  92. }
  93. #endif
  94.  
  95. void
  96. __do_global_init ()
  97. {
  98.   register long i, len;
  99.   register void (**ppf)() = (void (**)())__CTOR_LIST__.vector;
  100.  
  101.   len = __CTOR_LIST__.length;
  102.   for (i = 0; i < len; i++)
  103.     (*ppf[i])();
  104. }
  105.  
  106. void
  107. __do_global_cleanup ()
  108. {
  109. #ifdef atarist
  110.   if (__dlp)
  111. #else
  112.   while (__dlp)
  113. #endif
  114.     {
  115.       while (--__dli >= 0)
  116.     {
  117.       void (*pf)() = (void (*)())__dlp->vector[__dli];
  118.       (*pf)();
  119.     }
  120. #if !defined(atarist)
  121.       __dlp = (struct set_vector *)__dlp->vector[__dlp->length];
  122.       if (__dlp) __dli = __dlp->length;
  123. #endif
  124.     }
  125. }
  126.  
  127. #endif
  128.