4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / edit.c
index e91006c..6f5889c 100644 (file)
@@ -1,16 +1,17 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edit.c     5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)edit.c     8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
-#include <sys/stat.h>
+#include <fcntl.h>
+#include "extern.h"
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -21,7 +22,7 @@ static char sccsid[] = "@(#)edit.c    5.14 (Berkeley) %G%";
 /*
  * Edit a message list.
  */
 /*
  * Edit a message list.
  */
-
+int
 editor(msgvec)
        int *msgvec;
 {
 editor(msgvec)
        int *msgvec;
 {
@@ -32,7 +33,7 @@ editor(msgvec)
 /*
  * Invoke the visual editor on a message list.
  */
 /*
  * Invoke the visual editor on a message list.
  */
-
+int
 visual(msgvec)
        int *msgvec;
 {
 visual(msgvec)
        int *msgvec;
 {
@@ -45,9 +46,10 @@ visual(msgvec)
  * (which should not exist) and forking an editor on it.
  * We get the editor from the stuff above.
  */
  * (which should not exist) and forking an editor on it.
  * We get the editor from the stuff above.
  */
+int
 edit1(msgvec, type)
        int *msgvec;
 edit1(msgvec, type)
        int *msgvec;
-       char type;
+       int type;
 {
        register int c;
        int i;
 {
        register int c;
        int i;
@@ -80,7 +82,7 @@ edit1(msgvec, type)
                sigint = signal(SIGINT, SIG_IGN);
                fp = run_editor(setinput(mp), mp->m_size, type, readonly);
                if (fp != NULL) {
                sigint = signal(SIGINT, SIG_IGN);
                fp = run_editor(setinput(mp), mp->m_size, type, readonly);
                if (fp != NULL) {
-                       (void) fseek(otf, (long) 0, 2);
+                       (void) fseek(otf, 0L, 2);
                        size = ftell(otf);
                        mp->m_block = blockof(size);
                        mp->m_offset = offsetof(size);
                        size = ftell(otf);
                        mp->m_block = blockof(size);
                        mp->m_offset = offsetof(size);
@@ -96,7 +98,7 @@ edit1(msgvec, type)
                        }
                        if (ferror(otf))
                                perror("/tmp");
                        }
                        if (ferror(otf))
                                perror("/tmp");
-                       (void) fclose(fp);
+                       (void) Fclose(fp);
                }
                (void) signal(SIGINT, sigint);
        }
                }
                (void) signal(SIGINT, sigint);
        }
@@ -113,7 +115,7 @@ FILE *
 run_editor(fp, size, type, readonly)
        register FILE *fp;
        off_t size;
 run_editor(fp, size, type, readonly)
        register FILE *fp;
        off_t size;
-       char type;
+       int type, readonly;
 {
        register FILE *nf = NULL;
        register int t;
 {
        register FILE *nf = NULL;
        register int t;
@@ -126,7 +128,7 @@ run_editor(fp, size, type, readonly)
                perror(tempEdit);
                goto out;
        }
                perror(tempEdit);
                goto out;
        }
-       if ((nf = fdopen(t, "w")) == NULL) {
+       if ((nf = Fdopen(t, "w")) == NULL) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
@@ -142,7 +144,14 @@ run_editor(fp, size, type, readonly)
                modtime = 0;
        else
                modtime = statb.st_mtime;
                modtime = 0;
        else
                modtime = statb.st_mtime;
-       if (ferror(nf) || fclose(nf) < 0) {
+       if (ferror(nf)) {
+               (void) Fclose(nf);
+               perror(tempEdit);
+               (void) unlink(tempEdit);
+               nf = NULL;
+               goto out;
+       }
+       if (Fclose(nf) < 0) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                nf = NULL;
                perror(tempEdit);
                (void) unlink(tempEdit);
                nf = NULL;
@@ -151,7 +160,7 @@ run_editor(fp, size, type, readonly)
        nf = NULL;
        if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NOSTR)
                edit = type == 'e' ? _PATH_EX : _PATH_VI;
        nf = NULL;
        if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NOSTR)
                edit = type == 'e' ? _PATH_EX : _PATH_VI;
-       if (run_command(edit, 0, -1, -1, tempEdit, NOSTR) < 0) {
+       if (run_command(edit, 0, -1, -1, tempEdit, NOSTR, NOSTR) < 0) {
                (void) unlink(tempEdit);
                goto out;
        }
                (void) unlink(tempEdit);
                goto out;
        }
@@ -174,7 +183,7 @@ run_editor(fp, size, type, readonly)
        /*
         * Now switch to new file.
         */
        /*
         * Now switch to new file.
         */
-       if ((nf = fopen(tempEdit, "a+")) == NULL) {
+       if ((nf = Fopen(tempEdit, "a+")) == NULL) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;