cleanups, add manual page
[unix-history] / usr / src / usr.bin / mail / temp.c
index af639db..ce9a9e6 100644 (file)
@@ -3,16 +3,21 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at 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'' without express or implied warranty.
+ * 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.
  */
 
  */
 
-#ifdef notdef
-static char sccsid[] = "@(#)temp.c     5.5 (Berkeley) %G%";
-#endif /* notdef */
+#ifndef lint
+static char sccsid[] = "@(#)temp.c     5.11 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "rcv.h"
 
 
 #include "rcv.h"
 
@@ -32,44 +37,37 @@ char        tempMesg[14];
 tinit()
 {
        register char *cp;
 tinit()
 {
        register char *cp;
-       char uname[PATHSIZE];
-       register int pid;
-       uid_t getuid();
 
 
-       pid = getpid();
-       sprintf(tempMail, "/tmp/Rs%05d", pid);
-       sprintf(tempResid, "/tmp/Rq%05d", pid);
-       sprintf(tempQuit, "/tmp/Rm%05d", pid);
-       sprintf(tempEdit, "/tmp/Re%05d", pid);
-       sprintf(tempSet, "/tmp/Rx%05d", pid);
-       sprintf(tempMesg, "/tmp/Rx%05d", pid);
+       mktemp(strcpy(tempMail, "/tmp/RsXXXXXX"));
+       mktemp(strcpy(tempResid, "/tmp/RqXXXXXX"));
+       mktemp(strcpy(tempQuit, "/tmp/RmXXXXXX"));
+       mktemp(strcpy(tempEdit, "/tmp/ReXXXXXX"));
+       mktemp(strcpy(tempSet, "/tmp/RxXXXXXX"));
+       mktemp(strcpy(tempMesg, "/tmp/RxXXXXXX"));
 
 
-       if (strlen(myname) != 0) {
-               uid = getuserid(myname);
-               if (uid == -1) {
+       /*
+        * It's okay to call savestr in here because main will
+        * do a spreserve() after us.
+        */
+       if (myname != NOSTR) {
+               if (getuserid(myname) < 0) {
                        printf("\"%s\" is not a user of this system\n",
                            myname);
                        exit(1);
                }
                        printf("\"%s\" is not a user of this system\n",
                            myname);
                        exit(1);
                }
-       }
-       else {
-               uid = getuid();
-               if (username(uid, uname) < 0) {
-                       strcpy(myname, "ubluit");
+       } else {
+               if ((cp = username()) == NOSTR) {
+                       myname = "ubluit";
                        if (rcvmode) {
                                printf("Who are you!?\n");
                                exit(1);
                        }
                } else
                        if (rcvmode) {
                                printf("Who are you!?\n");
                                exit(1);
                        }
                } else
-                       strcpy(myname, uname);
+                       myname = savestr(cp);
        }
        }
-       if ((cp = value("HOME")) == NOSTR)
+       if ((cp = getenv("HOME")) == NOSTR)
                cp = ".";
                cp = ".";
-       strcpy(homedir, cp);
-       strcpy(copy(homedir, mailrc), "/.mailrc");
-       strcpy(copy(homedir, deadletter), "/dead.letter");
-       if (debug) {
-               printf("uid = %d, user = %s\n", uid, myname);
-               printf("deadletter = %s, mailrc = %s\n", deadletter, mailrc);
-       }
+       homedir = savestr(cp);
+       if (debug)
+               printf("user = %s, homedir = %s\n", myname, homedir);
 }
 }