4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / names.c
index 037884a..60c5589 100644 (file)
@@ -1,22 +1,12 @@
 /*
 /*
- * 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.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)names.c    5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)names.c    8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -26,6 +16,8 @@ static char sccsid[] = "@(#)names.c   5.14 (Berkeley) %G%";
  */
 
 #include "rcv.h"
  */
 
 #include "rcv.h"
+#include <fcntl.h>
+#include "extern.h"
 
 /*
  * Allocate a single element of a name list,
 
 /*
  * Allocate a single element of a name list,
@@ -35,6 +27,7 @@ static char sccsid[] = "@(#)names.c   5.14 (Berkeley) %G%";
 struct name *
 nalloc(str, ntype)
        char str[];
 struct name *
 nalloc(str, ntype)
        char str[];
+       int ntype;
 {
        register struct name *np;
 
 {
        register struct name *np;
 
@@ -71,6 +64,7 @@ tailof(name)
 struct name *
 extract(line, ntype)
        char line[];
 struct name *
 extract(line, ntype)
        char line[];
+       int ntype;
 {
        register char *cp;
        register struct name *top, *np, *t;
 {
        register char *cp;
        register struct name *top, *np, *t;
@@ -99,6 +93,7 @@ extract(line, ntype)
 char *
 detract(np, ntype)
        register struct name *np;
 char *
 detract(np, ntype)
        register struct name *np;
+       int ntype;
 {
        register int s;
        register char *cp, *top;
 {
        register int s;
        register char *cp, *top;
@@ -225,7 +220,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;
@@ -235,20 +230,20 @@ 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);
-                       }
+                       (void) fcntl(image, F_SETFD, 1);
+                       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);
                }
 
                /*
                }
 
                /*
@@ -261,7 +256,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)|
@@ -273,15 +274,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;
                        }
@@ -290,8 +296,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:
                /*
@@ -314,6 +320,7 @@ cant:
  * If any of the network metacharacters precedes any slashes, it can't
  * be a filename.  We cheat with .'s to allow path names like ./...
  */
  * If any of the network metacharacters precedes any slashes, it can't
  * be a filename.  We cheat with .'s to allow path names like ./...
  */
+int
 isfileaddr(name)
        char *name;
 {
 isfileaddr(name)
        char *name;
 {
@@ -376,6 +383,7 @@ struct name *
 gexpand(nlist, gh, metoo, ntype)
        struct name *nlist;
        struct grouphead *gh;
 gexpand(nlist, gh, metoo, ntype)
        struct name *nlist;
        struct grouphead *gh;
+       int metoo, ntype;
 {
        struct group *gp;
        struct grouphead *ngh;
 {
        struct group *gp;
        struct grouphead *ngh;
@@ -597,6 +605,7 @@ put(list, node)
  * Determine the number of undeleted elements in
  * a name list and return it.
  */
  * Determine the number of undeleted elements in
  * a name list and return it.
  */
+int
 count(np)
        register struct name *np;
 {
 count(np)
        register struct name *np;
 {
@@ -643,6 +652,7 @@ delname(np, name)
  */
 
 /*
  */
 
 /*
+void
 prettyprint(name)
        struct name *name;
 {
 prettyprint(name)
        struct name *name;
 {