xref: /csrg-svn/contrib/ed/edhup.c (revision 57682)
1*57682Sbostic /*-
2*57682Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*57682Sbostic  * All rights reserved.
4*57682Sbostic  *
5*57682Sbostic  * This code is derived from software contributed to Berkeley by
6*57682Sbostic  * Rodney Ruddock of the University of Guelph.
7*57682Sbostic  *
8*57682Sbostic  * %sccs.include.redist.c%
9*57682Sbostic  */
10*57682Sbostic 
11*57682Sbostic #ifndef lint
12*57682Sbostic static char sccsid[] = "@(#)edhup.c	5.1 (Berkeley) 01/23/93";
13*57682Sbostic #endif /* not lint */
14*57682Sbostic 
15*57682Sbostic #include "ed.h"
16*57682Sbostic 
17*57682Sbostic /*
18*57682Sbostic  * If a SIGHUP is received then user contact is severed. Try, if
19*57682Sbostic  * possible, to save the buffer. But be nice and don't save over
20*57682Sbostic  * remembered filename (you can figure out why, can't you?).
21*57682Sbostic  * The buffer is saved in a file named "ed.hup" in the directory that
22*57682Sbostic  * ed was started-up in. If a write cannot be made to that directory (say
23*57682Sbostic  * because it is read-only) then try writting "ed.hup" in the user's $HOME
24*57682Sbostic  * direcory. Then exit.
25*57682Sbostic  */
26*57682Sbostic 
27*57682Sbostic do_hup()
28*57682Sbostic 
29*57682Sbostic {
30*57682Sbostic   char l_filename[FILENAME_LEN], *l_temp;
31*57682Sbostic   FILE *l_fp;
32*57682Sbostic 
33*57682Sbostic   if (change_flag == 0)
34*57682Sbostic     exit(1); /* no need to save buffer contents */
35*57682Sbostic   if ((l_fp = fopen("ed.hup", "w")) == NULL)
36*57682Sbostic     {
37*57682Sbostic       /* try writting ed.hup to the $HOME directory instead */
38*57682Sbostic       l_temp = getenv("HOME");
39*57682Sbostic       if ((l_temp == NULL) || ((strlen(l_temp)+7)>FILENAME_LEN))
40*57682Sbostic         exit(1);
41*57682Sbostic       strcpy(l_filename, l_temp);
42*57682Sbostic       strcat(l_filename, "/ed.hup");
43*57682Sbostic       if ((l_fp = fopen(l_filename, "w")) == NULL)
44*57682Sbostic         exit(1); /* we tried... */
45*57682Sbostic     }
46*57682Sbostic   edwrite(l_fp, top, bottom);
47*57682Sbostic   fclose(l_fp);
48*57682Sbostic #ifdef STDIO
49*57682Sbostic   fclose(fhtmp);
50*57682Sbostic   unlink(template);
51*57682Sbostic #endif
52*57682Sbostic #ifdef DBI
53*57682Sbostic   (dbhtmp->close)(dbhtmp);
54*57682Sbostic   unlink(template);
55*57682Sbostic #endif
56*57682Sbostic   exit(1); /* hangup */
57*57682Sbostic 
58*57682Sbostic } /* end-do_hup */
59