home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff376.lzh / AztecArp / Sources.LZH / _exit.c next >
C/C++ Source or Header  |  1990-08-01  |  2KB  |  86 lines

  1. /* Created 11/08/87 by -=+SDB+=- from file provided by MANX */
  2. /* Copyright (C) 1987 by Scott Ballantyne */
  3. /* May be freely used by ARP supporters/users */
  4. /* If somebody were to modify the libraries to use ARP tracking, this would
  5.  * be even shorter (and so would the libraries)
  6.  */
  7.  
  8. extern int _argc;
  9. extern char **_argv;
  10. extern struct WBStartup *WBenchMsg;
  11. extern void *MathBase, *MathTransBase,*DOSBase;
  12. extern void *MathIeeeDoubBasBase, *MathIeeeDoubTransBase;
  13. extern void *_oldtrap, **_trapaddr;
  14. extern char __sloppy__;
  15.  
  16. void (*_cln)();
  17.  
  18. void    _exit(int code);
  19. void    _arpexit(int code,ULONG fail);
  20.  
  21. void
  22. _exit(int code)
  23. {
  24.     _arpexit(code,0);
  25. }
  26.  
  27. void
  28. _arpexit(int code,ULONG fail)
  29. {
  30.     if (_devtab)
  31.     {
  32.         int fd;
  33.  
  34.         for (fd = 0 ; fd < _numdev ; fd++)
  35.             close(fd);
  36.     }
  37.  
  38.     if (_cln)               /* needed to block loading 2 instances of _exit() if c.lib/malloc() gets loaded instead */
  39.         (*_cln)();
  40.  
  41.     if (_trapaddr)                                  /* clean up signal handling */
  42.         *_trapaddr = _oldtrap;
  43.  
  44.     if (MathTransBase)
  45.         CloseLibrary((struct Library *)MathTransBase);
  46.  
  47.     if (MathBase)
  48.         CloseLibrary((struct Library *)MathBase);
  49.  
  50.     if (MathIeeeDoubBasBase)
  51.         CloseLibrary((struct Library *)MathIeeeDoubBasBase);
  52.  
  53.     if (MathIeeeDoubTransBase)
  54.         CloseLibrary((struct Library *)MathIeeeDoubTransBase);
  55.  
  56.     if (__sloppy__ && DOSBase)
  57.         CloseLibrary((struct Library *)DOSBase);
  58.  
  59.     {
  60. #asm
  61.     mc68881
  62.     move.l    4,a6        ;get ExecBase
  63.     btst.b    #4,$129(a6)     ;check for 68881 flag in AttnFlags
  64.     beq    1$        ;skip if not
  65.     move.l    a5,-(sp)
  66.     lea    2$,a5
  67.     jsr    -30(a6)         ;do it in supervisor mode
  68.     move.l    (sp)+,a5
  69.     bra    1$
  70. 2$
  71.     clr.l    -(sp)
  72.     frestore (sp)+          ;reset the ffp stuff
  73.     rte            ;and return
  74. 1$
  75. #endasm
  76.     }
  77.  
  78.     if(WBenchMsg)
  79.     {
  80.         Forbid();
  81.         ReplyMsg((struct Message *)WBenchMsg);
  82.     }
  83.  
  84.     ArpExit(code,fail);     /* Exit, and free memory */
  85. }
  86.