temp.c (50477) | temp.c (74769) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93"; 37#endif 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93"; 37#endif 38static const char rcsid[] = |
39 "$FreeBSD: head/usr.bin/mail/temp.c 50477 1999-08-28 01:08:13Z peter $"; | 39 "$FreeBSD: head/usr.bin/mail/temp.c 74769 2001-03-25 04:57:05Z mikeh $"; |
40#endif /* not lint */ 41 42#include "rcv.h" | 40#endif /* not lint */ 41 42#include "rcv.h" |
43#include <err.h> | |
44#include "extern.h" 45 46/* 47 * Mail -- a mail program 48 * 49 * Give names to all the temporary files that we will need. 50 */ 51 | 43#include "extern.h" 44 45/* 46 * Mail -- a mail program 47 * 48 * Give names to all the temporary files that we will need. 49 */ 50 |
52char *tempMail; 53char *tempQuit; 54char *tempEdit; 55char *tempResid; 56char *tempMesg; | |
57char *tmpdir; 58 59void 60tinit() 61{ 62 register char *cp; | 51char *tmpdir; 52 53void 54tinit() 55{ 56 register char *cp; |
63 int len; | |
64 | 57 |
65 if ((tmpdir = getenv("TMPDIR")) == NULL) | 58 if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') |
66 tmpdir = _PATH_TMP; | 59 tmpdir = _PATH_TMP; |
67 else { 68 len = strlen(tmpdir); 69 if ((cp = malloc(len + 2)) == NULL) 70 panic("Out of memory"); 71 (void)strcpy(cp, tmpdir); 72 cp[len] = '/'; 73 cp[len + 1] = '\0'; 74 tmpdir = cp; | 60 if ((tmpdir = strdup(tmpdir)) == NULL) 61 errx(1, "Out of memory"); 62 /* Strip trailing '/' if necessary */ 63 cp = tmpdir + strlen(tmpdir) - 1; 64 while (cp > tmpdir && *cp == '/') { 65 *cp = '\0'; 66 cp--; |
75 } | 67 } |
76 len = strlen(tmpdir); 77 if ((tempMail = malloc(len + sizeof("RsXXXXXX"))) == NULL) 78 panic("Out of memory"); 79 strcpy(tempMail, tmpdir); 80 mktemp(strcat(tempMail, "RsXXXXXX")); 81 if ((tempResid = malloc(len + sizeof("RqXXXXXX"))) == NULL) 82 panic("Out of memory"); 83 strcpy(tempResid, tmpdir); 84 mktemp(strcat(tempResid, "RqXXXXXX")); 85 if ((tempQuit = malloc(len + sizeof("RmXXXXXX"))) == NULL) 86 panic("Out of memory"); 87 strcpy(tempQuit, tmpdir); 88 mktemp(strcat(tempQuit, "RmXXXXXX")); 89 if ((tempEdit = malloc(len + sizeof("ReXXXXXX"))) == NULL) 90 panic("Out of memory"); 91 strcpy(tempEdit, tmpdir); 92 mktemp(strcat(tempEdit, "ReXXXXXX")); 93 if ((tempMesg = malloc(len + sizeof("RxXXXXXX"))) == NULL) 94 panic("Out of memory"); 95 strcpy(tempMesg, tmpdir); 96 mktemp(strcat(tempMesg, "RxXXXXXX")); | |
97 98 /* 99 * It's okay to call savestr in here because main will 100 * do a spreserve() after us. 101 */ 102 if (myname != NOSTR) { | 68 69 /* 70 * It's okay to call savestr in here because main will 71 * do a spreserve() after us. 72 */ 73 if (myname != NOSTR) { |
103 if (getuserid(myname) < 0) { 104 printf("\"%s\" is not a user of this system\n", 105 myname); 106 exit(1); 107 } | 74 if (getuserid(myname) < 0) 75 errx(1, "\"%s\" is not a user of this system", myname); |
108 } else { 109 if ((cp = username()) == NOSTR) { 110 myname = "ubluit"; | 76 } else { 77 if ((cp = username()) == NOSTR) { 78 myname = "ubluit"; |
111 if (rcvmode) { 112 printf("Who are you!?\n"); 113 exit(1); 114 } | 79 if (rcvmode) 80 errx(1, "Who are you!?"); |
115 } else 116 myname = savestr(cp); 117 } | 81 } else 82 myname = savestr(cp); 83 } |
118 if ((cp = getenv("HOME")) == NOSTR) 119 cp = "."; 120 homedir = savestr(cp); | 84 if ((cp = getenv("HOME")) == NOSTR || *cp == '\0' || 85 strlen(cp) >= PATHSIZE) 86 homedir = NULL; 87 else 88 homedir = savestr(cp); |
121 if (debug) | 89 if (debug) |
122 printf("user = %s, homedir = %s\n", myname, homedir); | 90 printf("user = %s, homedir = %s\n", myname, 91 homedir ? homedir : "NONE"); |
123} | 92} |