ed: Use TMPDIR to locate the temporal file
The current behaviour of storing the scratch file in the current directory is a bit painful, because it generates files in all the directories where you execute ed. BSD ed uses TMPDIR for this purpouse, so if the user wants to put the scratch file in other place different of /tmp it only has to set this variable.
This commit is contained in:
parent
cf0a0fc940
commit
36e2bdf517
10
ed.c
10
ed.c
|
@ -329,14 +329,16 @@ static void
|
|||
setscratch()
|
||||
{
|
||||
int k;
|
||||
char *dir;
|
||||
|
||||
clearbuf();
|
||||
clearundo();
|
||||
strcpy(tmpname, "ed.XXXXXX");
|
||||
if ((dir = getenv("TMPDIR")) == NULL)
|
||||
dir = "/tmp/";
|
||||
if (strlen(dir) + sizeof("ed.XXXXXX") > FILENAME_MAX)
|
||||
error("incorrect scratch file name");
|
||||
strcat(strcpy(tmpname, dir), "ed.XXXXX");
|
||||
if ((scratch = mkstemp(tmpname)) < 0) {
|
||||
/* try /tmp if cwd is not writable */
|
||||
strcpy(tmpname, "/tmp/ed.XXXXXX");
|
||||
if ((scratch = mkstemp(tmpname)) < 0)
|
||||
error("failed to create scratch file");
|
||||
}
|
||||
if ((k = makeline("", NULL)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user