remove call of _fwalk
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 25 Jun 1990 15:02:01 +0000 (07:02 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 25 Jun 1990 15:02:01 +0000 (07:02 -0800)
SCCS-vsn: usr.bin/mail/lex.c 5.21
SCCS-vsn: usr.bin/mail/names.c 5.16
SCCS-vsn: usr.bin/mail/edit.c 5.15
SCCS-vsn: usr.bin/mail/collect.c 5.22
SCCS-vsn: usr.bin/mail/cmd2.c 5.14
SCCS-vsn: usr.bin/mail/quit.c 5.15
SCCS-vsn: usr.bin/mail/send.c 5.21
SCCS-vsn: usr.bin/mail/glob.h 5.20
SCCS-vsn: usr.bin/mail/cmd3.c 5.24
SCCS-vsn: usr.bin/mail/main.c 5.27
SCCS-vsn: usr.bin/mail/fio.c 5.23
SCCS-vsn: usr.bin/mail/cmd1.c 5.21
SCCS-vsn: usr.bin/mail/popen.c 5.15
SCCS-vsn: usr.bin/mail/def.h 5.22
SCCS-vsn: usr.bin/mail/aux.c 5.20

15 files changed:
usr/src/usr.bin/mail/aux.c
usr/src/usr.bin/mail/cmd1.c
usr/src/usr.bin/mail/cmd2.c
usr/src/usr.bin/mail/cmd3.c
usr/src/usr.bin/mail/collect.c
usr/src/usr.bin/mail/def.h
usr/src/usr.bin/mail/edit.c
usr/src/usr.bin/mail/fio.c
usr/src/usr.bin/mail/glob.h
usr/src/usr.bin/mail/lex.c
usr/src/usr.bin/mail/main.c
usr/src/usr.bin/mail/names.c
usr/src/usr.bin/mail/popen.c
usr/src/usr.bin/mail/quit.c
usr/src/usr.bin/mail/send.c

index 338ae2f..b488b16 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)aux.c      5.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)aux.c      5.20 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -45,7 +45,8 @@ panic(fmt, a, b)
        fprintf(stderr, "panic: ");
        fprintf(stderr, fmt, a, b);
        putc('\n', stderr);
        fprintf(stderr, "panic: ");
        fprintf(stderr, fmt, a, b);
        putc('\n', stderr);
-       exit(1);
+       fflush(stdout);
+       abort();
 }
 
 /*
 }
 
 /*
@@ -241,13 +242,13 @@ source(arglist)
 
        if ((cp = expand(*arglist)) == NOSTR)
                return(1);
 
        if ((cp = expand(*arglist)) == NOSTR)
                return(1);
-       if ((fi = fopen(cp, "r")) == NULL) {
+       if ((fi = Fopen(cp, "r")) == NULL) {
                perror(cp);
                return(1);
        }
        if (ssp >= NOFILE - 1) {
                printf("Too much \"sourcing\" going on.\n");
                perror(cp);
                return(1);
        }
        if (ssp >= NOFILE - 1) {
                printf("Too much \"sourcing\" going on.\n");
-               fclose(fi);
+               Fclose(fi);
                return(1);
        }
        sstack[ssp].s_file = input;
                return(1);
        }
        sstack[ssp].s_file = input;
@@ -272,7 +273,7 @@ unstack()
                sourcing = 0;
                return(1);
        }
                sourcing = 0;
                return(1);
        }
-       fclose(input);
+       Fclose(input);
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
        ssp--;
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
        ssp--;
index f7acf6c..ead5e8f 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd1.c     5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd1.c     5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -266,14 +266,8 @@ type1(msgvec, doign, page)
        FILE *obuf;
 
        obuf = stdout;
        FILE *obuf;
 
        obuf = stdout;
-       if (setjmp(pipestop)) {
-               if (obuf != stdout) {
-                       pipef = NULL;
-                       Pclose(obuf);
-               }
-               signal(SIGPIPE, SIG_DFL);
-               return(0);
-       }
+       if (setjmp(pipestop))
+               goto close_pipe;
        if (value("interactive") != NOSTR &&
            (page || (cp = value("crt")) != NOSTR)) {
                nlines = 0;
        if (value("interactive") != NOSTR &&
            (page || (cp = value("crt")) != NOSTR)) {
                nlines = 0;
@@ -289,10 +283,8 @@ type1(msgvec, doign, page)
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
-                       } else {
-                               pipef = obuf;
+                       } else
                                signal(SIGPIPE, brokpipe);
                                signal(SIGPIPE, brokpipe);
-                       }
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
@@ -303,17 +295,21 @@ type1(msgvec, doign, page)
                        fprintf(obuf, "Message %d:\n", *ip);
                (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
                        fprintf(obuf, "Message %d:\n", *ip);
                (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
+close_pipe:
        if (obuf != stdout) {
        if (obuf != stdout) {
-               pipef = NULL;
+               /*
+                * Ignore SIGPIPE so it can't cause a duplicate close.
+                */
+               signal(SIGPIPE, SIG_IGN);
                Pclose(obuf);
                Pclose(obuf);
+               signal(SIGPIPE, SIG_DFL);
        }
        }
-       signal(SIGPIPE, SIG_DFL);
        return(0);
 }
 
 /*
  * Respond to a broken pipe signal --
        return(0);
 }
 
 /*
  * Respond to a broken pipe signal --
- * probably caused by using quitting more.
+ * probably caused by quitting more.
  */
 
 brokpipe()
  */
 
 brokpipe()
index ccfb3d4..8daa794 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd2.c     5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd2.c     5.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -155,7 +155,7 @@ save1(str, mark, cmd, ignore)
                disp = "[Appended]";
        else
                disp = "[New file]";
                disp = "[Appended]";
        else
                disp = "[New file]";
-       if ((obuf = fopen(file, "a")) == NULL) {
+       if ((obuf = Fopen(file, "a")) == NULL) {
                perror(NOSTR);
                return(1);
        }
                perror(NOSTR);
                return(1);
        }
@@ -164,7 +164,7 @@ save1(str, mark, cmd, ignore)
                touch(mp);
                if (send(mp, obuf, ignore, NOSTR) < 0) {
                        perror(file);
                touch(mp);
                if (send(mp, obuf, ignore, NOSTR) < 0) {
                        perror(file);
-                       fclose(obuf);
+                       Fclose(obuf);
                        return(1);
                }
                if (mark)
                        return(1);
                }
                if (mark)
@@ -173,7 +173,7 @@ save1(str, mark, cmd, ignore)
        fflush(obuf);
        if (ferror(obuf))
                perror(file);
        fflush(obuf);
        if (ferror(obuf))
                perror(file);
-       fclose(obuf);
+       Fclose(obuf);
        printf("%s\n", disp);
        return(0);
 }
        printf("%s\n", disp);
        return(0);
 }
index be45d32..c890540 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd3.c     5.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd3.c     5.24 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -120,13 +120,13 @@ help()
        register c;
        register FILE *f;
 
        register c;
        register FILE *f;
 
-       if ((f = fopen(_PATH_HELP, "r")) == NULL) {
+       if ((f = Fopen(_PATH_HELP, "r")) == NULL) {
                perror(_PATH_HELP);
                return(1);
        }
        while ((c = getc(f)) != EOF)
                putchar(c);
                perror(_PATH_HELP);
                return(1);
        }
        while ((c = getc(f)) != EOF)
                putchar(c);
-       fclose(f);
+       Fclose(f);
        return(0);
 }
 
        return(0);
 }
 
index ade3e43..8a3bc95 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  5.22 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -75,7 +75,7 @@ collect(hp, printheaders)
        sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
 
        noreset++;
        sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
 
        noreset++;
-       if ((collf = fopen(tempMail, "w+")) == NULL) {
+       if ((collf = Fopen(tempMail, "w+")) == NULL) {
                perror(tempMail);
                goto err;
        }
                perror(tempMail);
                goto err;
        }
@@ -247,7 +247,7 @@ cont:
                                printf("%s: Directory\n", cp);
                                break;
                        }
                                printf("%s: Directory\n", cp);
                                break;
                        }
-                       if ((fbuf = fopen(cp, "r")) == NULL) {
+                       if ((fbuf = Fopen(cp, "r")) == NULL) {
                                perror(cp);
                                break;
                        }
                                perror(cp);
                                break;
                        }
@@ -258,12 +258,12 @@ cont:
                        while (readline(fbuf, linebuf, LINESIZE) >= 0) {
                                lc++;
                                if ((t = putline(collf, linebuf)) < 0) {
                        while (readline(fbuf, linebuf, LINESIZE) >= 0) {
                                lc++;
                                if ((t = putline(collf, linebuf)) < 0) {
-                                       fclose(fbuf);
+                                       Fclose(fbuf);
                                        goto err;
                                }
                                cc += t;
                        }
                                        goto err;
                                }
                                cc += t;
                        }
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        printf("%d/%d\n", lc, cc);
                        break;
                case 'w':
                        printf("%d/%d\n", lc, cc);
                        break;
                case 'w':
@@ -296,13 +296,13 @@ cont:
                                goto err;
                        goto cont;
                case '?':
                                goto err;
                        goto cont;
                case '?':
-                       if ((fbuf = fopen(_PATH_TILDE, "r")) == NULL) {
+                       if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
                                perror(_PATH_TILDE);
                                break;
                        }
                        while ((t = getc(fbuf)) != EOF)
                                (void) putchar(t);
                                perror(_PATH_TILDE);
                                break;
                        }
                        while ((t = getc(fbuf)) != EOF)
                                (void) putchar(t);
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        break;
                case 'p':
                        /*
                        break;
                case 'p':
                        /*
@@ -338,7 +338,7 @@ cont:
        goto out;
 err:
        if (collf != NULL) {
        goto out;
 err:
        if (collf != NULL) {
-               fclose(collf);
+               Fclose(collf);
                collf = NULL;
        }
 out:
                collf = NULL;
        }
 out:
@@ -379,7 +379,7 @@ exwrite(name, fp, f)
                fprintf(stderr, "File exists\n");
                return(-1);
        }
                fprintf(stderr, "File exists\n");
                return(-1);
        }
-       if ((of = fopen(name, "w")) == NULL) {
+       if ((of = Fopen(name, "w")) == NULL) {
                perror(NOSTR);
                return(-1);
        }
                perror(NOSTR);
                return(-1);
        }
@@ -392,11 +392,11 @@ exwrite(name, fp, f)
                (void) putc(c, of);
                if (ferror(of)) {
                        perror(name);
                (void) putc(c, of);
                if (ferror(of)) {
                        perror(name);
-                       fclose(of);
+                       Fclose(of);
                        return(-1);
                }
        }
                        return(-1);
                }
        }
-       fclose(of);
+       Fclose(of);
        printf("%d/%ld\n", lc, cc);
        fflush(stdout);
        return(0);
        printf("%d/%ld\n", lc, cc);
        fflush(stdout);
        return(0);
@@ -415,7 +415,7 @@ mesedit(fp, c)
        if (nf != NULL) {
                fseek(nf, (off_t)0, 2);
                collf = nf;
        if (nf != NULL) {
                fseek(nf, (off_t)0, 2);
                collf = nf;
-               fclose(fp);
+               Fclose(fp);
        }
        (void) signal(SIGINT, sigint);
 }
        }
        (void) signal(SIGINT, sigint);
 }
@@ -434,7 +434,7 @@ mespipe(fp, cmd)
        sig_t sigint = signal(SIGINT, SIG_IGN);
        extern char tempEdit[];
 
        sig_t sigint = signal(SIGINT, SIG_IGN);
        extern char tempEdit[];
 
-       if ((nf = fopen(tempEdit, "w+")) == NULL) {
+       if ((nf = Fopen(tempEdit, "w+")) == NULL) {
                perror(tempEdit);
                goto out;
        }
                perror(tempEdit);
                goto out;
        }
@@ -444,12 +444,12 @@ mespipe(fp, cmd)
         * stdout = new message.
         */
        if (run_command(cmd, 0, fileno(fp), fileno(nf), NOSTR) < 0) {
         * stdout = new message.
         */
        if (run_command(cmd, 0, fileno(fp), fileno(nf), NOSTR) < 0) {
-               (void) fclose(nf);
+               (void) Fclose(nf);
                goto out;
        }
        if (fsize(nf) == 0) {
                fprintf(stderr, "No bytes from \"%s\" !?\n", cmd);
                goto out;
        }
        if (fsize(nf) == 0) {
                fprintf(stderr, "No bytes from \"%s\" !?\n", cmd);
-               (void) fclose(nf);
+               (void) Fclose(nf);
                goto out;
        }
        /*
                goto out;
        }
        /*
@@ -457,7 +457,7 @@ mespipe(fp, cmd)
         */
        (void) fseek(nf, 0L, 2);
        collf = nf;
         */
        (void) fseek(nf, 0L, 2);
        collf = nf;
-       (void) fclose(fp);
+       (void) Fclose(fp);
 out:
        (void) signal(SIGINT, sigint);
 }
 out:
        (void) signal(SIGINT, sigint);
 }
@@ -580,12 +580,12 @@ savedeadletter(fp)
                return;
        cp = getdeadletter();
        c = umask(077);
                return;
        cp = getdeadletter();
        c = umask(077);
-       dbuf = fopen(cp, "a");
+       dbuf = Fopen(cp, "a");
        (void) umask(c);
        if (dbuf == NULL)
                return;
        while ((c = getc(fp)) != EOF)
                (void) putc(c, dbuf);
        (void) umask(c);
        if (dbuf == NULL)
                return;
        while ((c = getc(fp)) != EOF)
                (void) putc(c, dbuf);
-       fclose(dbuf);
+       Fclose(dbuf);
        rewind(fp);
 }
        rewind(fp);
 }
index ea966ee..0fc95eb 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)def.h       5.21 (Berkeley) %G%
+ *     @(#)def.h       5.22 (Berkeley) %G%
  */
 
 #include <sys/param.h>         /* includes <sys/types.h> */
  */
 
 #include <sys/param.h>         /* includes <sys/types.h> */
@@ -246,6 +246,7 @@ struct ignoretab {
  * Forward declarations of routine types to keep lint and cc happy.
  */
 
  * Forward declarations of routine types to keep lint and cc happy.
  */
 
+FILE   *Fopen();
 FILE   *Fdopen();
 FILE   *Popen();
 FILE   *collect();
 FILE   *Fdopen();
 FILE   *Popen();
 FILE   *collect();
index e91006c..36eae7e 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edit.c     5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)edit.c     5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -96,7 +96,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);
        }
@@ -126,7 +126,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 +142,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;
@@ -174,7 +181,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;
index 5dcfe7d..8f9e6c2 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)fio.c      5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)fio.c      5.23 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -40,7 +40,7 @@ setptr(ibuf)
 
        if ((c = opentemp(tempSet)) < 0)
                exit(1);
 
        if ((c = opentemp(tempSet)) < 0)
                exit(1);
-       if ((mestmp = fdopen(c, "r+")) == NULL)
+       if ((mestmp = Fdopen(c, "r+")) == NULL)
                panic("Can't open temporary");
        msgCount = 0;
        maybe = 1;
                panic("Can't open temporary");
        msgCount = 0;
        maybe = 1;
@@ -57,7 +57,6 @@ setptr(ibuf)
                                perror(tempSet);
                                exit(1);
                        }
                                perror(tempSet);
                                exit(1);
                        }
-                       fclose(ibuf);
                        makemessage(mestmp);
                        return;
                }
                        makemessage(mestmp);
                        return;
                }
@@ -186,7 +185,7 @@ makemessage(f)
                panic("Message temporary file corrupted");
        message[msgCount].m_size = 0;
        message[msgCount].m_lines = 0;
                panic("Message temporary file corrupted");
        message[msgCount].m_size = 0;
        message[msgCount].m_lines = 0;
-       fclose(f);
+       Fclose(f);
 }
 
 /*
 }
 
 /*
@@ -405,20 +404,3 @@ getdeadletter()
        }
        return cp;
 }
        }
        return cp;
 }
-
-/*
- * A nicer version of Fdopen, which allows us to fclose
- * without losing the open file.
- */
-FILE *
-Fdopen(fildes, mode)
-       char *mode;
-{
-       int f;
-
-       if ((f = dup(fildes)) < 0) {
-               perror("dup");
-               return (NULL);
-       }
-       return fdopen(f, mode);
-}
index 1af1e83..14712b2 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)glob.h      5.19 (Berkeley) %G%
+ *     @(#)glob.h      5.20 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -25,7 +25,6 @@ int   loading;                        /* Loading user definitions */
 int    cond;                           /* Current state of conditional exc. */
 FILE   *itf;                           /* Input temp file buffer */
 FILE   *otf;                           /* Output temp file buffer */
 int    cond;                           /* Current state of conditional exc. */
 FILE   *itf;                           /* Input temp file buffer */
 FILE   *otf;                           /* Output temp file buffer */
-FILE   *pipef;                         /* Pipe file we have opened */
 int    image;                          /* File descriptor for image of msg */
 FILE   *input;                         /* Current command input file */
 char   mailname[PATHSIZE];             /* Name of current file */
 int    image;                          /* File descriptor for image of msg */
 FILE   *input;                         /* Current command input file */
 char   mailname[PATHSIZE];             /* Name of current file */
index fab67f1..0552215 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lex.c      5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)lex.c      5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -42,7 +42,7 @@ setfile(name)
        if ((name = expand(name)) == NOSTR)
                return -1;
 
        if ((name = expand(name)) == NOSTR)
                return -1;
 
-       if ((ibuf = fopen(name, "r")) == NULL) {
+       if ((ibuf = Fopen(name, "r")) == NULL) {
                if (!isedit && errno == ENOENT)
                        goto nomail;
                perror(name);
                if (!isedit && errno == ENOENT)
                        goto nomail;
                perror(name);
@@ -51,13 +51,13 @@ setfile(name)
 
        if (fstat(fileno(ibuf), &stb) < 0) {
                perror("fstat");
 
        if (fstat(fileno(ibuf), &stb) < 0) {
                perror("fstat");
-               fclose(ibuf);
+               Fclose(ibuf);
                return (-1);
        }
 
        switch (stb.st_mode & S_IFMT) {
        case S_IFDIR:
                return (-1);
        }
 
        switch (stb.st_mode & S_IFMT) {
        case S_IFDIR:
-               fclose(ibuf);
+               Fclose(ibuf);
                errno = EISDIR;
                perror(name);
                return (-1);
                errno = EISDIR;
                perror(name);
                return (-1);
@@ -66,7 +66,7 @@ setfile(name)
                break;
 
        default:
                break;
 
        default:
-               fclose(ibuf);
+               Fclose(ibuf);
                errno = EINVAL;
                perror(name);
                return (-1);
                errno = EINVAL;
                perror(name);
                return (-1);
@@ -114,7 +114,7 @@ setfile(name)
        remove(tempMesg);
        setptr(ibuf);
        setmsize(msgCount);
        remove(tempMesg);
        setptr(ibuf);
        setmsize(msgCount);
-       fclose(ibuf);
+       Fclose(ibuf);
        relsesigs();
        sawcom = 0;
        if (!edit && msgCount == 0) {
        relsesigs();
        sawcom = 0;
        if (!edit && msgCount == 0) {
@@ -458,34 +458,6 @@ isprefix(as1, as2)
 
 int    inithdr;                        /* am printing startup headers */
 
 
 int    inithdr;                        /* am printing startup headers */
 
-#ifdef _NFILE
-static
-_fwalk(function)
-       register int (*function)();
-{
-       register FILE *iop;
-
-       for (iop = _iob; iop < _iob + _NFILE; iop++)
-               (*function)(iop);
-}
-#endif
-
-static
-xclose(iop)
-       register FILE *iop;
-{
-       if (iop == stdin || iop == stdout ||
-           iop == stderr || iop == itf || iop == otf)
-               return;
-
-       if (iop != pipef)
-               fclose(iop);
-       else {
-               Pclose(pipef);
-               pipef = NULL;
-       }
-}
-
 /*ARGSUSED*/
 intr(s)
 {
 /*ARGSUSED*/
 intr(s)
 {
@@ -497,10 +469,7 @@ intr(s)
        while (sourcing)
                unstack();
 
        while (sourcing)
                unstack();
 
-       /*
-        * Walk through all the open FILEs, applying xclose() to them
-        */
-       _fwalk(xclose);
+       close_all_files();
 
        if (image >= 0) {
                close(image);
 
        if (image >= 0) {
                close(image);
@@ -638,7 +607,7 @@ load(name)
 {
        register FILE *in, *oldin;
 
 {
        register FILE *in, *oldin;
 
-       if ((in = fopen(name, "r")) == NULL)
+       if ((in = Fopen(name, "r")) == NULL)
                return;
        oldin = input;
        input = in;
                return;
        oldin = input;
        input = in;
@@ -648,5 +617,5 @@ load(name)
        loading = 0;
        sourcing = 0;
        input = oldin;
        loading = 0;
        sourcing = 0;
        input = oldin;
-       fclose(in);
+       Fclose(in);
 }
 }
index ffa6922..23c1d84 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.27 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -184,7 +184,7 @@ Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\
                load(_PATH_MASTER_RC);
        /*
         * Expand returns a savestr, but load only uses the file name
                load(_PATH_MASTER_RC);
        /*
         * Expand returns a savestr, but load only uses the file name
-        * for fopen, so it's save to do this.
+        * for fopen, so it's safe to do this.
         */
        load(expand("~/.mailrc"));
        if (!rcvmode) {
         */
        load(expand("~/.mailrc"));
        if (!rcvmode) {
index 8101bf8..c98c025 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)names.c    5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)names.c    5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -215,7 +215,7 @@ outof(names, fo, hp)
                 */
 
                if (image < 0) {
                 */
 
                if (image < 0) {
-                       if ((fout = fopen(tempEdit, "a")) == NULL) {
+                       if ((fout = Fopen(tempEdit, "a")) == NULL) {
                                perror(tempEdit);
                                senderr++;
                                goto cant;
                                perror(tempEdit);
                                senderr++;
                                goto cant;
@@ -225,20 +225,19 @@ outof(names, fo, hp)
                        if (image < 0) {
                                perror(tempEdit);
                                senderr++;
                        if (image < 0) {
                                perror(tempEdit);
                                senderr++;
+                               (void) Fclose(fout);
                                goto cant;
                        }
                                goto cant;
                        }
-                       else {
-                               fprintf(fout, "From %s %s", myname, date);
-                               puthead(hp, fout, GTO|GSUBJECT|GCC|GNL);
-                               while ((c = getc(fo)) != EOF)
-                                       (void) putc(c, fout);
-                               rewind(fo);
-                               (void) putc('\n', fout);
-                               (void) fflush(fout);
-                               if (ferror(fout))
-                                       perror(tempEdit);
-                               (void) fclose(fout);
-                       }
+                       fprintf(fout, "From %s %s", myname, date);
+                       puthead(hp, fout, GTO|GSUBJECT|GCC|GNL);
+                       while ((c = getc(fo)) != EOF)
+                               (void) putc(c, fout);
+                       rewind(fo);
+                       (void) putc('\n', fout);
+                       (void) fflush(fout);
+                       if (ferror(fout))
+                               perror(tempEdit);
+                       (void) Fclose(fout);
                }
 
                /*
                }
 
                /*
@@ -251,7 +250,13 @@ outof(names, fo, hp)
                        int pid;
                        char *shell;
 
                        int pid;
                        char *shell;
 
-                       /* XXX, can't really reuse the same image file */
+                       /*
+                        * XXX
+                        * We can't really reuse the same image file,
+                        * because multiple piped recipients will
+                        * share the same lseek location and trample
+                        * on one another.
+                        */
                        if ((shell = value("SHELL")) == NOSTR)
                                shell = _PATH_CSHELL;
                        pid = start_command(shell, sigmask(SIGHUP)|
                        if ((shell = value("SHELL")) == NOSTR)
                                shell = _PATH_CSHELL;
                        pid = start_command(shell, sigmask(SIGHUP)|
@@ -263,15 +268,20 @@ outof(names, fo, hp)
                        }
                        free_child(pid);
                } else {
                        }
                        free_child(pid);
                } else {
-                       if ((fout = fopen(fname, "a")) == NULL) {
+                       int f;
+                       if ((fout = Fopen(fname, "a")) == NULL) {
                                perror(fname);
                                senderr++;
                                goto cant;
                        }
                                perror(fname);
                                senderr++;
                                goto cant;
                        }
-                       fin = Fdopen(image, "r");
+                       if ((f = dup(image)) < 0) {
+                               perror("dup");
+                               fin = NULL;
+                       } else
+                               fin = Fdopen(f, "r");
                        if (fin == NULL) {
                                fprintf(stderr, "Can't reopen image\n");
                        if (fin == NULL) {
                                fprintf(stderr, "Can't reopen image\n");
-                               (void) fclose(fout);
+                               (void) Fclose(fout);
                                senderr++;
                                goto cant;
                        }
                                senderr++;
                                goto cant;
                        }
@@ -280,8 +290,8 @@ outof(names, fo, hp)
                                (void) putc(c, fout);
                        if (ferror(fout))
                                senderr++, perror(fname);
                                (void) putc(c, fout);
                        if (ferror(fout))
                                senderr++, perror(fname);
-                       (void) fclose(fout);
-                       (void) fclose(fin);
+                       (void) Fclose(fout);
+                       (void) Fclose(fin);
                }
 cant:
                /*
                }
 cant:
                /*
index 33a0e8a..623801e 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)popen.c    5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)popen.c    5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -17,6 +17,42 @@ static char sccsid[] = "@(#)popen.c  5.14 (Berkeley) %G%";
 #define WRITE 1
 static int *pid;
 
 #define WRITE 1
 static int *pid;
 
+struct fp {
+       FILE *fp;
+       int pipe;
+       struct fp *link;
+};
+static struct fp *fp_head;
+
+FILE *
+Fopen(file, mode)
+       char *file, *mode;
+{
+       FILE *fp;
+
+       if ((fp = fopen(file, mode)) != NULL)
+               register_file(fp, 0);
+       return fp;
+}
+
+FILE *
+Fdopen(fd, mode)
+       char *mode;
+{
+       FILE *fp;
+
+       if ((fp = fdopen(fd, mode)) != NULL)
+               register_file(fp, 0);
+       return fp;
+}
+
+Fclose(fp)
+       FILE *fp;
+{
+       unregister_file(fp);
+       return fclose(fp);
+}
+
 FILE *
 Popen(cmd, mode)
        char *cmd;
 FILE *
 Popen(cmd, mode)
        char *cmd;
@@ -24,6 +60,7 @@ Popen(cmd, mode)
 {
        int p[2];
        int myside, hisside, fd0, fd1;
 {
        int p[2];
        int myside, hisside, fd0, fd1;
+       FILE *fp;
 
        if (pid == 0)
                pid = (int *) malloc((unsigned) sizeof (int) * getdtablesize());
 
        if (pid == 0)
                pid = (int *) malloc((unsigned) sizeof (int) * getdtablesize());
@@ -43,8 +80,10 @@ Popen(cmd, mode)
                close(p[WRITE]);
                return NULL;
        }
                close(p[WRITE]);
                return NULL;
        }
-       close(hisside);
-       return fdopen(myside, mode);
+       (void) close(hisside);
+       if ((fp = fdopen(myside, mode)) != NULL)
+               register_file(fp, 1);
+       return fp;
 }
 
 Pclose(ptr)
 }
 
 Pclose(ptr)
@@ -54,13 +93,55 @@ Pclose(ptr)
        int omask;
 
        i = fileno(ptr);
        int omask;
 
        i = fileno(ptr);
-       fclose(ptr);
+       unregister_file(ptr);
+       (void) fclose(ptr);
        omask = sigblock(sigmask(SIGINT)|sigmask(SIGHUP));
        i = wait_child(pid[i]);
        sigsetmask(omask);
        return i;
 }
 
        omask = sigblock(sigmask(SIGINT)|sigmask(SIGHUP));
        i = wait_child(pid[i]);
        sigsetmask(omask);
        return i;
 }
 
+close_all_files()
+{
+
+       while (fp_head)
+               if (fp_head->pipe)
+                       (void) Pclose(fp_head->fp);
+               else
+                       (void) Fclose(fp_head->fp);
+}
+
+register_file(fp, pipe)
+       FILE *fp;
+{
+       struct fp *fpp;
+
+       if ((fpp = (struct fp *) malloc(sizeof *fpp)) == NULL)
+               panic("Out of memory");
+       fpp->fp = fp;
+       fpp->pipe = pipe;
+       fpp->link = fp_head;
+       fp_head = fpp;
+}
+
+unregister_file(fp)
+       FILE *fp;
+{
+       struct fp **pp, *p;
+
+       for (pp = &fp_head; p = *pp; pp = &p->link)
+               if (p->fp == fp) {
+                       *pp = p->link;
+                       free((char *) p);
+                       return;
+               }
+       /* XXX
+        * Ignore this for now; there may still be uncaught
+        * duplicate closes.
+       panic("Invalid file pointer");
+       */
+}
+
 /*
  * Run a command without a shell, with optional arguments and splicing
  * of stdin and stdout.  The command name can be a sequence of words.
 /*
  * Run a command without a shell, with optional arguments and splicing
  * of stdin and stdout.  The command name can be a sequence of words.
index c0466f2..68d1312 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)quit.c     5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)quit.c     5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -74,14 +74,14 @@ quit()
         * a message.
         */
 
         * a message.
         */
 
-       fbuf = fopen(mailname, "r");
+       fbuf = Fopen(mailname, "r");
        if (fbuf == NULL)
                goto newmail;
        flock(fileno(fbuf), LOCK_EX);
        rbuf = NULL;
        if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
                printf("New mail has arrived.\n");
        if (fbuf == NULL)
                goto newmail;
        flock(fileno(fbuf), LOCK_EX);
        rbuf = NULL;
        if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
                printf("New mail has arrived.\n");
-               rbuf = fopen(tempResid, "w");
+               rbuf = Fopen(tempResid, "w");
                if (rbuf == NULL || fbuf == NULL)
                        goto newmail;
 #ifdef APPEND
                if (rbuf == NULL || fbuf == NULL)
                        goto newmail;
 #ifdef APPEND
@@ -97,8 +97,8 @@ quit()
                        (void) putc(c, rbuf);
                }
 #endif
                        (void) putc(c, rbuf);
                }
 #endif
-               fclose(rbuf);
-               if ((rbuf = fopen(tempResid, "r")) == NULL)
+               Fclose(rbuf);
+               if ((rbuf = Fopen(tempResid, "r")) == NULL)
                        goto newmail;
                remove(tempResid);
        }
                        goto newmail;
                remove(tempResid);
        }
@@ -127,7 +127,7 @@ quit()
        }
        modify = 0;
        if (Tflag != NOSTR) {
        }
        modify = 0;
        if (Tflag != NOSTR) {
-               if ((readstat = fopen(Tflag, "w")) == NULL)
+               if ((readstat = Fopen(Tflag, "w")) == NULL)
                        Tflag = NOSTR;
        }
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
                        Tflag = NOSTR;
        }
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
@@ -145,17 +145,17 @@ quit()
                }
        }
        if (Tflag != NOSTR)
                }
        }
        if (Tflag != NOSTR)
-               fclose(readstat);
+               Fclose(readstat);
        if (p == msgCount && !modify && !anystat) {
                printf("Held %d message%s in %s\n",
                        p, p == 1 ? "" : "s", mailname);
        if (p == msgCount && !modify && !anystat) {
                printf("Held %d message%s in %s\n",
                        p, p == 1 ? "" : "s", mailname);
-               fclose(fbuf);
+               Fclose(fbuf);
                return;
        }
        if (c == 0) {
                if (p != 0) {
                        writeback(rbuf);
                return;
        }
        if (c == 0) {
                if (p != 0) {
                        writeback(rbuf);
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        return;
                }
                goto cream;
                        return;
                }
                goto cream;
@@ -171,44 +171,44 @@ quit()
        mbox = expand("&");
        mcount = c;
        if (value("append") == NOSTR) {
        mbox = expand("&");
        mcount = c;
        if (value("append") == NOSTR) {
-               if ((obuf = fopen(tempQuit, "w")) == NULL) {
+               if ((obuf = Fopen(tempQuit, "w")) == NULL) {
                        perror(tempQuit);
                        perror(tempQuit);
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        return;
                }
                        return;
                }
-               if ((ibuf = fopen(tempQuit, "r")) == NULL) {
+               if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
                        perror(tempQuit);
                        remove(tempQuit);
                        perror(tempQuit);
                        remove(tempQuit);
-                       fclose(obuf);
-                       fclose(fbuf);
+                       Fclose(obuf);
+                       Fclose(fbuf);
                        return;
                }
                remove(tempQuit);
                        return;
                }
                remove(tempQuit);
-               if ((abuf = fopen(mbox, "r")) != NULL) {
+               if ((abuf = Fopen(mbox, "r")) != NULL) {
                        while ((c = getc(abuf)) != EOF)
                                (void) putc(c, obuf);
                        while ((c = getc(abuf)) != EOF)
                                (void) putc(c, obuf);
-                       fclose(abuf);
+                       Fclose(abuf);
                }
                if (ferror(obuf)) {
                        perror(tempQuit);
                }
                if (ferror(obuf)) {
                        perror(tempQuit);
-                       fclose(ibuf);
-                       fclose(obuf);
-                       fclose(fbuf);
+                       Fclose(ibuf);
+                       Fclose(obuf);
+                       Fclose(fbuf);
                        return;
                }
                        return;
                }
-               fclose(obuf);
+               Fclose(obuf);
                close(creat(mbox, 0600));
                close(creat(mbox, 0600));
-               if ((obuf = fopen(mbox, "r+")) == NULL) {
+               if ((obuf = Fopen(mbox, "r+")) == NULL) {
                        perror(mbox);
                        perror(mbox);
-                       fclose(ibuf);
-                       fclose(fbuf);
+                       Fclose(ibuf);
+                       Fclose(fbuf);
                        return;
                }
        }
        if (value("append") != NOSTR) {
                        return;
                }
        }
        if (value("append") != NOSTR) {
-               if ((obuf = fopen(mbox, "a")) == NULL) {
+               if ((obuf = Fopen(mbox, "a")) == NULL) {
                        perror(mbox);
                        perror(mbox);
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        return;
                }
                fchmod(fileno(obuf), 0600);
                        return;
                }
                fchmod(fileno(obuf), 0600);
@@ -217,9 +217,9 @@ quit()
                if (mp->m_flag & MBOX)
                        if (send(mp, obuf, saveignore, NOSTR) < 0) {
                                perror(mbox);
                if (mp->m_flag & MBOX)
                        if (send(mp, obuf, saveignore, NOSTR) < 0) {
                                perror(mbox);
-                               fclose(ibuf);
-                               fclose(obuf);
-                               fclose(fbuf);
+                               Fclose(ibuf);
+                               Fclose(obuf);
+                               Fclose(fbuf);
                                return;
                        }
 
                                return;
                        }
 
@@ -238,17 +238,17 @@ quit()
                                break;
                        c = getc(ibuf);
                }
                                break;
                        c = getc(ibuf);
                }
-               fclose(ibuf);
+               Fclose(ibuf);
                fflush(obuf);
        }
        trunc(obuf);
        if (ferror(obuf)) {
                perror(mbox);
                fflush(obuf);
        }
        trunc(obuf);
        if (ferror(obuf)) {
                perror(mbox);
-               fclose(obuf);
-               fclose(fbuf);
+               Fclose(obuf);
+               Fclose(fbuf);
                return;
        }
                return;
        }
-       fclose(obuf);
+       Fclose(obuf);
        if (mcount == 1)
                printf("Saved 1 message in mbox\n");
        else
        if (mcount == 1)
                printf("Saved 1 message in mbox\n");
        else
@@ -261,7 +261,7 @@ quit()
 
        if (p != 0) {
                writeback(rbuf);
 
        if (p != 0) {
                writeback(rbuf);
-               fclose(fbuf);
+               Fclose(fbuf);
                return;
        }
 
                return;
        }
 
@@ -272,26 +272,26 @@ quit()
 
 cream:
        if (rbuf != NULL) {
 
 cream:
        if (rbuf != NULL) {
-               abuf = fopen(mailname, "r+");
+               abuf = Fopen(mailname, "r+");
                if (abuf == NULL)
                        goto newmail;
                while ((c = getc(rbuf)) != EOF)
                        (void) putc(c, abuf);
                if (abuf == NULL)
                        goto newmail;
                while ((c = getc(rbuf)) != EOF)
                        (void) putc(c, abuf);
-               fclose(rbuf);
+               Fclose(rbuf);
                trunc(abuf);
                trunc(abuf);
-               fclose(abuf);
+               Fclose(abuf);
                alter(mailname);
                alter(mailname);
-               fclose(fbuf);
+               Fclose(fbuf);
                return;
        }
        demail();
                return;
        }
        demail();
-       fclose(fbuf);
+       Fclose(fbuf);
        return;
 
 newmail:
        printf("Thou hast new mail.\n");
        if (fbuf != NULL)
        return;
 
 newmail:
        printf("Thou hast new mail.\n");
        if (fbuf != NULL)
-               fclose(fbuf);
+               Fclose(fbuf);
 }
 
 /*
 }
 
 /*
@@ -308,7 +308,7 @@ writeback(res)
        FILE *obuf;
 
        p = 0;
        FILE *obuf;
 
        p = 0;
-       if ((obuf = fopen(mailname, "r+")) == NULL) {
+       if ((obuf = Fopen(mailname, "r+")) == NULL) {
                perror(mailname);
                return(-1);
        }
                perror(mailname);
                return(-1);
        }
@@ -322,7 +322,7 @@ writeback(res)
                        p++;
                        if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
                                perror(mailname);
                        p++;
                        if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
                                perror(mailname);
-                               fclose(obuf);
+                               Fclose(obuf);
                                return(-1);
                        }
                }
                                return(-1);
                        }
                }
@@ -335,12 +335,12 @@ writeback(res)
        trunc(obuf);
        if (ferror(obuf)) {
                perror(mailname);
        trunc(obuf);
        if (ferror(obuf)) {
                perror(mailname);
-               fclose(obuf);
+               Fclose(obuf);
                return(-1);
        }
        if (res != NULL)
                return(-1);
        }
        if (res != NULL)
-               fclose(res);
-       fclose(obuf);
+               Fclose(res);
+       Fclose(obuf);
        alter(mailname);
        if (p == 1)
                printf("Held 1 message in %s\n", mailname);
        alter(mailname);
        if (p == 1)
                printf("Held 1 message in %s\n", mailname);
@@ -366,7 +366,7 @@ edstop()
                return;
        holdsigs();
        if (Tflag != NOSTR) {
                return;
        holdsigs();
        if (Tflag != NOSTR) {
-               if ((readstat = fopen(Tflag, "w")) == NULL)
+               if ((readstat = Fopen(Tflag, "w")) == NULL)
                        Tflag = NOSTR;
        }
        for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
                        Tflag = NOSTR;
        }
        for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
@@ -384,7 +384,7 @@ edstop()
                }
        }
        if (Tflag != NOSTR)
                }
        }
        if (Tflag != NOSTR)
-               fclose(readstat);
+               Fclose(readstat);
        if (!gotcha || Tflag != NOSTR)
                goto done;
        ibuf = NULL;
        if (!gotcha || Tflag != NOSTR)
                goto done;
        ibuf = NULL;
@@ -392,14 +392,14 @@ edstop()
                strcpy(tempname, _PATH_TMP);
                strcat(tempname, "mboxXXXXXX");
                mktemp(tempname);
                strcpy(tempname, _PATH_TMP);
                strcat(tempname, "mboxXXXXXX");
                mktemp(tempname);
-               if ((obuf = fopen(tempname, "w")) == NULL) {
+               if ((obuf = Fopen(tempname, "w")) == NULL) {
                        perror(tempname);
                        relsesigs();
                        reset(0);
                }
                        perror(tempname);
                        relsesigs();
                        reset(0);
                }
-               if ((ibuf = fopen(mailname, "r")) == NULL) {
+               if ((ibuf = Fopen(mailname, "r")) == NULL) {
                        perror(mailname);
                        perror(mailname);
-                       fclose(obuf);
+                       Fclose(obuf);
                        remove(tempname);
                        relsesigs();
                        reset(0);
                        remove(tempname);
                        relsesigs();
                        reset(0);
@@ -407,9 +407,9 @@ edstop()
                fseek(ibuf, mailsize, 0);
                while ((c = getc(ibuf)) != EOF)
                        (void) putc(c, obuf);
                fseek(ibuf, mailsize, 0);
                while ((c = getc(ibuf)) != EOF)
                        (void) putc(c, obuf);
-               fclose(ibuf);
-               fclose(obuf);
-               if ((ibuf = fopen(tempname, "r")) == NULL) {
+               Fclose(ibuf);
+               Fclose(obuf);
+               if ((ibuf = Fopen(tempname, "r")) == NULL) {
                        perror(tempname);
                        remove(tempname);
                        relsesigs();
                        perror(tempname);
                        remove(tempname);
                        relsesigs();
@@ -419,7 +419,7 @@ edstop()
        }
        printf("\"%s\" ", mailname);
        fflush(stdout);
        }
        printf("\"%s\" ", mailname);
        fflush(stdout);
-       if ((obuf = fopen(mailname, "r+")) == NULL) {
+       if ((obuf = Fopen(mailname, "r+")) == NULL) {
                perror(mailname);
                relsesigs();
                reset(0);
                perror(mailname);
                relsesigs();
                reset(0);
@@ -440,7 +440,7 @@ edstop()
        if (ibuf != NULL) {
                while ((c = getc(ibuf)) != EOF)
                        (void) putc(c, obuf);
        if (ibuf != NULL) {
                while ((c = getc(ibuf)) != EOF)
                        (void) putc(c, obuf);
-               fclose(ibuf);
+               Fclose(ibuf);
        }
        fflush(obuf);
        if (ferror(obuf)) {
        }
        fflush(obuf);
        if (ferror(obuf)) {
@@ -448,7 +448,7 @@ edstop()
                relsesigs();
                reset(0);
        }
                relsesigs();
                reset(0);
        }
-       fclose(obuf);
+       Fclose(obuf);
        if (gotcha) {
                remove(mailname);
                printf("removed\n");
        if (gotcha) {
                remove(mailname);
                printf("removed\n");
index 99ace8e..4cc4299 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)send.c     5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)send.c     5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -337,10 +337,10 @@ mail1(hp, printheaders)
                if (access(_PATH_MAIL_LOG, 0) == 0) {
                        FILE *postage;
 
                if (access(_PATH_MAIL_LOG, 0) == 0) {
                        FILE *postage;
 
-                       if ((postage = fopen(_PATH_MAIL_LOG, "a")) != NULL) {
+                       if ((postage = Fopen(_PATH_MAIL_LOG, "a")) != NULL) {
                                fprintf(postage, "%s %d %ld\n", myname,
                                    count(to), fsize(mtf));
                                fprintf(postage, "%s %d %ld\n", myname,
                                    count(to), fsize(mtf));
-                               (void) fclose(postage);
+                               (void) Fclose(postage);
                        }
                }
                prepare_child(sigmask(SIGHUP)|sigmask(SIGINT)|sigmask(SIGQUIT)|
                        }
                }
                prepare_child(sigmask(SIGHUP)|sigmask(SIGINT)|sigmask(SIGQUIT)|
@@ -359,7 +359,7 @@ mail1(hp, printheaders)
        else
                free_child(pid);
 out:
        else
                free_child(pid);
 out:
-       (void) fclose(mtf);
+       (void) Fclose(mtf);
 }
 
 /*
 }
 
 /*
@@ -400,13 +400,13 @@ infix(hp, fi)
        register FILE *nfo, *nfi;
        register int c;
 
        register FILE *nfo, *nfi;
        register int c;
 
-       if ((nfo = fopen(tempMail, "w")) == NULL) {
+       if ((nfo = Fopen(tempMail, "w")) == NULL) {
                perror(tempMail);
                return(fi);
        }
                perror(tempMail);
                return(fi);
        }
-       if ((nfi = fopen(tempMail, "r")) == NULL) {
+       if ((nfi = Fopen(tempMail, "r")) == NULL) {
                perror(tempMail);
                perror(tempMail);
-               (void) fclose(nfo);
+               (void) Fclose(nfo);
                return(fi);
        }
        (void) remove(tempMail);
                return(fi);
        }
        (void) remove(tempMail);
@@ -424,13 +424,13 @@ infix(hp, fi)
        (void) fflush(nfo);
        if (ferror(nfo)) {
                perror(tempMail);
        (void) fflush(nfo);
        if (ferror(nfo)) {
                perror(tempMail);
-               (void) fclose(nfo);
-               (void) fclose(nfi);
+               (void) Fclose(nfo);
+               (void) Fclose(nfi);
                rewind(fi);
                return(fi);
        }
                rewind(fi);
                return(fi);
        }
-       (void) fclose(nfo);
-       (void) fclose(fi);
+       (void) Fclose(nfo);
+       (void) Fclose(fi);
        rewind(nfi);
        return(nfi);
 }
        rewind(nfi);
        return(nfi);
 }
@@ -507,7 +507,7 @@ savemail(name, fi)
        time_t now, time();
        char *ctime();
 
        time_t now, time();
        char *ctime();
 
-       if ((fo = fopen(name, "a")) == NULL) {
+       if ((fo = Fopen(name, "a")) == NULL) {
                perror(name);
                return (-1);
        }
                perror(name);
                return (-1);
        }
@@ -519,7 +519,7 @@ savemail(name, fi)
        (void) fflush(fo);
        if (ferror(fo))
                perror(name);
        (void) fflush(fo);
        if (ferror(fo))
                perror(name);
-       (void) fclose(fo);
+       (void) Fclose(fo);
        rewind(fi);
        return (0);
 }
        rewind(fi);
        return (0);
 }