OSDN Git Service

upgrade to 3.6.2
[jnethack/source.git] / util / panic.c
1 /* NetHack 3.6  panic.c $NHDT-Date: 1448210012 2015/11/22 16:33:32 $  $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2015. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /*
7  *      This code was adapted from the code in end.c to run in a standalone
8  *      mode for the makedefs / drg code.
9  */
10
11 #define NEED_VARARGS
12 #include "config.h"
13
14 #ifdef AZTEC
15 #define abort() exit()
16 #endif
17 #ifdef VMS
18 extern void NDECL(vms_abort);
19 #endif
20
21 /*VARARGS1*/
22 boolean panicking;
23 void VDECL(panic, (const char *, ...));
24
25 void panic
26 VA_DECL(const char *, str)
27 {
28     VA_START(str);
29     VA_INIT(str, char *);
30     if (panicking++)
31 #ifdef SYSV
32         (void)
33 #endif
34             abort(); /* avoid loops - this should never happen*/
35
36     (void) fputs(" ERROR:  ", stderr);
37     Vfprintf(stderr, str, VA_ARGS);
38     (void) fflush(stderr);
39 #if defined(UNIX) || defined(VMS)
40 #ifdef SYSV
41     (void)
42 #endif
43         abort(); /* generate core dump */
44 #endif
45     VA_END();
46     exit(EXIT_FAILURE); /* redundant */
47 }
48
49 #ifdef ALLOCA_HACK
50 /*
51  * In case bison-generated foo_yacc.c tries to use alloca(); if we don't
52  * have it then just use malloc() instead.  This may not work on some
53  * systems, but they should either use yacc or get a real alloca routine.
54  */
55 long *
56 alloca(cnt)
57 unsigned cnt;
58 {
59     return cnt ? alloc(cnt) : (long *) 0;
60 }
61 #endif
62
63 /*panic.c*/