move f77_abort() and no_lg.c here from libF77
[unix-history] / usr / src / usr.bin / f77 / libI77 / f77_abort.c
CommitLineData
93e618b0
JB
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
5d6567db 6 * @(#)f77_abort.c 5.1 %G%
93e618b0
JB
7 *
8 * all f77 aborts eventually call f77_abort.
9 * f77_abort cleans up open files and terminates with a dump if needed,
10 * with a message otherwise.
11 *
12 */
13
14#include <signal.h>
15#include "fio.h"
16
17char *getenv();
18extern int errno;
19extern int _dbsubc; /* dbsubc is non-zero if -lg was specified to ld */
20
21f77_abort( err_val, act_core )
22{
23 char first_char, *env_var;
24 int core_dump;
25
26 env_var = getenv("f77_dump_flag");
27 first_char = (env_var == NULL) ? 0 : *env_var;
28
29 signal(SIGILL, SIG_DFL);
30 sigsetmask(0); /* don't block */
31
32 /* see if we want a core dump:
33 first line checks for signals like hangup - don't dump then.
34 second line checks if -lg specified to ld (e.g. by saying
35 -g to f77) and checks the f77_dump_flag var. */
36 core_dump = ((nargs() != 2) || act_core) &&
37 ( (_dbsubc && (first_char != 'n')) || first_char == 'y');
38
39 if( !core_dump )
40 fprintf(units[STDERR].ufd,"*** Execution terminated\n");
41
42 f_exit();
43 _cleanup();
44 if( nargs() ) errno = err_val;
45 else errno = -2; /* prior value will be meaningless,
46 so set it to undefined value */
47
48 if( core_dump ) abort();
49 else exit( errno );
50}