Merge from vendor branch NTPD:
[dragonfly.git] / contrib / nvi / vi / v_zexit.c
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *      The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *      Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9
10 #include "config.h"
11
12 #ifndef lint
13 static const char sccsid[] = "@(#)v_zexit.c     10.6 (Berkeley) 4/27/96";
14 #endif /* not lint */
15
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
19
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "../common/common.h"
26 #include "vi.h"
27
28 /*
29  * v_zexit -- ZZ
30  *      Save the file and exit.
31  *
32  * PUBLIC: int v_zexit __P((SCR *, VICMD *));
33  */
34 int
35 v_zexit(sp, vp)
36         SCR *sp;
37         VICMD *vp;
38 {
39         /* Write back any modifications. */
40         if (F_ISSET(sp->ep, F_MODIFIED) &&
41             file_write(sp, NULL, NULL, NULL, FS_ALL))
42                 return (1);
43
44         /* Check to make sure it's not a temporary file. */
45         if (file_m3(sp, 0))
46                 return (1);
47
48         /* Check for more files to edit. */
49         if (ex_ncheck(sp, 0))
50                 return (1);
51
52         F_SET(sp, SC_EXIT);
53         return (0);
54 }