8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mail / mkdead.c
blob7b9d1d9df415a9a14898f55dea3268691a7b3f6a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */
28 #include "mail.h"
30 Routine creates dead.letter
32 void mkdead()
34 static char pn[] = "mkdead";
35 int aret;
36 char *dotdead = &dead[1];
37 gid_t egid = getegid();
38 struct stat st;
40 malf = (FILE *)NULL;
43 Make certain that there's something to copy.
45 if (!tmpf)
46 return;
49 Try to create dead letter in current directory
50 or in home directory
52 umask(umsave);
53 setgid(getgid());
54 if ((aret = legal(dotdead)) && stat(dotdead, &st) == 0)
55 malf = fopen(dotdead, "a");
56 if ((malf == NULL) || (aret == 0)) {
58 try to create in $HOME
60 if((hmdead = malloc(strlen(home) + strlen(dead) + 1)) == NULL) {
61 fprintf(stderr, "%s: Can't malloc\n",program);
62 Dout(pn, 0, "Cannot malloc.\n");
63 goto out;
65 cat(hmdead, home, dead);
66 if ((aret=legal(hmdead)) && !(stat(hmdead, &st) < 0 &&
67 errno == EOVERFLOW))
68 malf = fopen(hmdead, "a");
69 if ((malf == NULL) || (aret == 0)) {
70 fprintf(stderr,
71 "%s: Cannot create %s\n",
72 program,dotdead);
73 Dout(pn, 0, "Cannot create %s\n", dotdead);
74 out:
75 fclose(tmpf);
76 error = E_FILE;
77 Dout(pn, 0, "error set to %d\n", error);
78 umask(7);
79 setegid(egid);
80 return;
81 } else {
82 chmod(hmdead, DEADPERM);
83 fprintf(stderr,"%s: Mail saved in %s\n",program,hmdead);
85 } else {
86 chmod(dotdead, DEADPERM);
87 fprintf(stderr,"%s: Mail saved in %s\n",program,dotdead);
91 Copy letter into dead letter box
93 umask(7);
94 aret = fseek(tmpf,0L,0);
95 if (aret)
96 errmsg(E_DEAD,"");
97 if (!copystream(tmpf, malf))
98 errmsg(E_DEAD,"");
99 fclose(malf);
100 setegid(egid);
103 void savdead()
105 static char pn[] = "savdead";
106 setsig(SIGINT, saveint);
107 dflag = 2; /* do not send back letter on interrupt */
108 Dout(pn, 0, "dflag set to 2\n");
109 if (!error) {
110 error = E_REMOTE;
111 Dout(pn, 0, "error set to %d\n", error);
113 maxerr = error;
114 Dout(pn, 0, "maxerr set to %d\n", maxerr);