BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / mail / names.c
index 8101bf8..a9f3dbb 100644 (file)
@@ -2,11 +2,23 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)names.c    5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)names.c    5.16 (Berkeley) 6/25/90";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -215,7 +227,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 +237,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 +262,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 +280,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 +302,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:
                /*