xref: /csrg-svn/usr.bin/mail/temp.c (revision 62083)
122468Sdist /*
2*62083Sbostic  * Copyright (c) 1980, 1993
3*62083Sbostic  *	The Regents of the University of California.  All rights reserved.
433499Sbostic  *
542741Sbostic  * %sccs.include.redist.c%
622468Sdist  */
722468Sdist 
834905Sbostic #ifndef lint
9*62083Sbostic static char sccsid[] = "@(#)temp.c	8.1 (Berkeley) 06/06/93";
1034905Sbostic #endif /* not lint */
111246Skas 
1254505Sbostic #include "rcv.h"
1352909Sbostic #include <errno.h>
1454505Sbostic #include "extern.h"
151246Skas 
161246Skas /*
171246Skas  * Mail -- a mail program
181246Skas  *
191246Skas  * Give names to all the temporary files that we will need.
201246Skas  */
211246Skas 
2237870Sbostic char	tempMail[24];
2337870Sbostic char	tempQuit[24];
2437870Sbostic char	tempEdit[24];
2537870Sbostic char	tempResid[24];
2637870Sbostic char	tempMesg[24];
2752909Sbostic char	*tmpdir;
281246Skas 
2954505Sbostic void
tinit()301246Skas tinit()
311246Skas {
3231142Sedward 	register char *cp;
3352909Sbostic 	int len;
341246Skas 
3552909Sbostic 	if ((tmpdir = getenv("TMPDIR")) == NULL)
3652909Sbostic 		tmpdir = _PATH_TMP;
3752909Sbostic 	else {
3852909Sbostic 		len = strlen(tmpdir);
3952909Sbostic 		if ((cp = malloc(len + 2)) == NULL) {
4052909Sbostic 			(void)fprintf(stderr, "mail: %s\n", strerror(errno));
4152909Sbostic 			exit (1);
4252909Sbostic 		}
4352909Sbostic 		(void)strcpy(cp, tmpdir);
4452909Sbostic 		cp[len] = '/';
4552909Sbostic 		cp[len + 1] = '\0';
4652909Sbostic 		tmpdir = cp;
4752909Sbostic 	}
4852909Sbostic 
4952909Sbostic 	strcpy(tempMail, tmpdir);
5038698Sbostic 	mktemp(strcat(tempMail, "RsXXXXXX"));
5152909Sbostic 	strcpy(tempResid, tmpdir);
5238698Sbostic 	mktemp(strcat(tempResid, "RqXXXXXX"));
5352909Sbostic 	strcpy(tempQuit, tmpdir);
5438698Sbostic 	mktemp(strcat(tempQuit, "RmXXXXXX"));
5552909Sbostic 	strcpy(tempEdit, tmpdir);
5638698Sbostic 	mktemp(strcat(tempEdit, "ReXXXXXX"));
5752909Sbostic 	strcpy(tempMesg, tmpdir);
5838698Sbostic 	mktemp(strcat(tempMesg, "RxXXXXXX"));
591246Skas 
6034968Sedward 	/*
6134968Sedward 	 * It's okay to call savestr in here because main will
6234968Sedward 	 * do a spreserve() after us.
6334968Sedward 	 */
6434968Sedward 	if (myname != NOSTR) {
6534968Sedward 		if (getuserid(myname) < 0) {
661725Skas 			printf("\"%s\" is not a user of this system\n",
671725Skas 			    myname);
681725Skas 			exit(1);
691725Skas 		}
7034962Sedward 	} else {
7134968Sedward 		if ((cp = username()) == NOSTR) {
7234968Sedward 			myname = "ubluit";
731246Skas 			if (rcvmode) {
741246Skas 				printf("Who are you!?\n");
751246Skas 				exit(1);
761246Skas 			}
7731142Sedward 		} else
7834968Sedward 			myname = savestr(cp);
791246Skas 	}
8035374Sedward 	if ((cp = getenv("HOME")) == NOSTR)
811246Skas 		cp = ".";
8234968Sedward 	homedir = savestr(cp);
8334968Sedward 	if (debug)
8435374Sedward 		printf("user = %s, homedir = %s\n", myname, homedir);
851246Skas }
86