manual page distributed with 4.2BSD
[unix-history] / usr / src / usr.bin / mail / cc.local.c
CommitLineData
fd8223c6
KS
1#
2
3/*
4 * Mail -- a mail program
5 *
6 * Computer Center Unix
7 *
8 * Local routines that are installation dependent.
9 */
10
11#include "rcv.h"
12
79ddb121 13static char *SccsId = "@(#)cc.local.c 2.1 %G%";
fd8223c6
KS
14
15/*
16 * Locate the user's mailbox file (ie, the place where new, unread
17 * mail is queued). At Computer Center, it is in /usr/mail/name.
18 */
19
20findmail()
21{
22 register char *cp;
23
24 cp = copy("/usr/mail/", mailname);
25 copy(myname, cp);
26}
27
28/*
29 * Get rid of the queued mail.
30 * This is essentially "mail -n > /dev/null &"
31 */
32
33demail()
34{
35 register int p;
36
37 if (uid == 0) {
38 remove(mailname);
39 return;
40 }
41 if ((p = fork()) != 0)
42 return;
43 for (p = 0; p < 15; p++)
44 close(p);
45 open("/dev/null", 2);
46 dup(0);
47 dup(0);
48 for (p = SIGHUP; p <= SIGQUIT; p++)
49 signal(p, SIG_IGN);
50 execl(MAIL, "mail", "-n", 0);
51 perror(MAIL);
52 exit(1);
53}
54
55/*
56 * Get the value of an environment variable.
57 */
58
59char *
60getenv(name)
61 char name[];
62{
63 register int t;
64 static char val[30];
65
66 t = ttyn(2);
67 hget(t);
68 if (equal(name, "SHELL"))
69 return("/bin/csh");
70 if (!equal(name, "HOME"))
71 return(NOSTR);
72 copy(hgethome(), val);
73 return(val);
74}
75
76/*
77 * Mail file lock / unlock.
78 * Not implemented in this version.
79 */
80
81lock(name)
82 char name[];
83{
84
85 return(0);
86}
87
88unlock()
89{
90 return(0);
91}
92
93/*
94 * Discover user login name.
95 */
96
97username(uid, namebuf)
98 char namebuf[];
99{
100
101 return(getname(uid, namebuf));
102}
103
104/*
105 * Unix routine to do an "fopen" on file descriptor
106 * The mode has to be repeated because you can't query its
107 * status
108 */
109
110FILE *
111fdopen(fd, mode)
112register char *mode;
113{
114 extern int errno;
115 register FILE *iop;
116 extern FILE *_lastbuf;
117
118 for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
119 if (iop >= _lastbuf)
120 return(NULL);
121 iop->_cnt = 0;
122 iop->_file = fd;
123 if (*mode != 'r') {
124 iop->_flag |= _IOWRT;
125 if (*mode == 'a')
126 lseek(fd, 0L, 2);
127 } else
128 iop->_flag |= _IOREAD;
129 return(iop);
130}