home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / programming / aztecarp_436 / src / source.lzh / _exit.c next >
C/C++ Source or Header  |  1990-12-05  |  2KB  |  85 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.  
  15. void (*_cln)();
  16.  
  17. void    _exit(int code);
  18. void    _arpexit(int code,ULONG fail);
  19.  
  20. void
  21. _exit(int code)
  22. {
  23.     _arpexit(code,0);
  24. }
  25.  
  26. void
  27. _arpexit(int code,ULONG fail)
  28. {
  29.     if(_devtab)
  30.     {
  31.         int fd;
  32.  
  33.         for(fd = 0 ; fd < _numdev ; fd++)
  34.             close(fd);
  35.     }
  36.  
  37.     if(_cln)            /* needed to block loading 2 instances of _exit() if c.lib/malloc() gets loaded instead */
  38.         (*_cln)();
  39.  
  40.     if(_trapaddr)            /* clean up signal handling */
  41.         *_trapaddr = _oldtrap;
  42.  
  43.     if(MathTransBase)
  44.         CloseLibrary((struct Library *)MathTransBase);
  45.  
  46.     if(MathBase)
  47.         CloseLibrary((struct Library *)MathBase);
  48.  
  49.     if(MathIeeeDoubBasBase)
  50.         CloseLibrary((struct Library *)MathIeeeDoubBasBase);
  51.  
  52.     if(MathIeeeDoubTransBase)
  53.         CloseLibrary((struct Library *)MathIeeeDoubTransBase);
  54.  
  55.     if(DOSBase)
  56.         CloseLibrary((struct Library *)DOSBase);
  57.  
  58.     {
  59. #asm
  60.     mc68881
  61.     move.l    (4).w,a6    ;get ExecBase
  62.     btst.b    #4,$129(a6)     ;check for 68881 flag in AttnFlags
  63.     beq    1$        ;skip if not
  64.     move.l    a5,-(sp)
  65.     lea    2$,a5
  66.     jsr    -30(a6)         ;do it in supervisor mode
  67.     move.l    (sp)+,a5
  68.     bra    1$
  69. 2$
  70.     clr.l    -(sp)
  71.     frestore (sp)+          ;reset the ffp stuff
  72.     rte            ;and return
  73. 1$
  74. #endasm
  75.     }
  76.  
  77.     if(WBenchMsg)
  78.     {
  79.         Forbid();
  80.         ReplyMsg((struct Message *)WBenchMsg);
  81.     }
  82.  
  83.     ArpExit((long)code,fail);
  84. }
  85.