home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff353.lzh / AztecArp / _exit.c next >
C/C++ Source or Header  |  1990-06-02  |  2KB  |  74 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
  19. _exit(int code)
  20. {
  21.     long ret = code;
  22.     register int fd;
  23.  
  24.     if (_devtab) {
  25.         for (fd = 0 ; fd < _numdev ; fd++)
  26.             close(fd);
  27.     }
  28.     if (_cln)               /* needed to block loading 2 instances of _exit() if c.lib/malloc() gets loaded instead */
  29.         (*_cln)();
  30. #if 0        /* is now Tracked */
  31.     if (_detach_curdir)                             /* for DETACHed programs */
  32.         UnLock((BPTR)_detach_curdir);
  33. #endif
  34.     if (_trapaddr)                                  /* clean up signal handling */
  35.         *_trapaddr = _oldtrap;
  36.     if (MathTransBase)
  37.         CloseLibrary((struct Library *)MathTransBase);
  38.     if (MathBase)
  39.         CloseLibrary((struct Library *)MathBase);
  40.     if (MathIeeeDoubBasBase)
  41.         CloseLibrary((struct Library *)MathIeeeDoubBasBase);
  42.     if (MathIeeeDoubTransBase)
  43.         CloseLibrary((struct Library *)MathIeeeDoubTransBase);
  44.     if (__sloppy__ && DOSBase)
  45.         CloseLibrary((struct Library *)DOSBase);
  46.  
  47.     {
  48. #asm
  49.     mc68881
  50.     move.l    4,a6        ;get ExecBase
  51.     btst.b    #4,$129(a6)     ;check for 68881 flag in AttnFlags
  52.     beq    1$        ;skip if not
  53.     move.l    a5,-(sp)
  54.     lea    2$,a5
  55.     jsr    -30(a6)         ;do it in supervisor mode
  56.     move.l    (sp)+,a5
  57.     bra    1$
  58. 2$
  59.     clr.l    -(sp)
  60.     frestore (sp)+          ;reset the ffp stuff
  61.     rte            ;and return
  62. 1$
  63. #endasm
  64.     }
  65.  
  66.     if (WBenchMsg)
  67.     {
  68.         Forbid();
  69.         ReplyMsg((struct Message *)WBenchMsg);
  70.     }
  71.  
  72.     ArpExit( ret , 0L);     /* Exit, and free memory */
  73. }
  74.