home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdlib / abort.c next >
Encoding:
C/C++ Source or Header  |  1996-10-05  |  924 b   |  52 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <io.h>
  5.  
  6. static char msg[] = "Abort!\r\n";
  7.  
  8. void
  9. abort()
  10. {
  11.   _write(STDERR_FILENO, msg, sizeof(msg)-1);
  12.   _exit(1);
  13. }
  14.  
  15. #ifdef TEST
  16.  
  17. #include <stdio.h>
  18. #include <errno.h>
  19. #include <string.h>
  20. #include <process.h>
  21. #include <sys/exceptn.h>
  22.  
  23. int main (int argc, char *argv[])
  24. {
  25.   int status = 0;
  26.  
  27.   errno = 0;
  28.   if (argc > 1)
  29.     {
  30.       if (strcmp (argv[1], "abort") == 0)
  31.     abort ();
  32.       else if (strcmp (argv[1], "toggle") == 0)
  33.     {
  34.       __djgpp_exception_toggle ();
  35.       abort ();
  36.     }
  37.     }
  38.   else
  39.     {
  40.       fprintf (stderr, "\tType `%s abort RET'\n"
  41.                "or\n"
  42.                "\t     `%s toggle RET'\n", argv[0], argv[0]);
  43.       status = system ("");
  44.     }
  45.  
  46.   fprintf (stderr, "Child returned %d\n", status);
  47.   if (errno)
  48.     perror ("spawn");
  49.   return 0;
  50. }
  51. #endif
  52.