[hackers] [sbase] ed: Use TMPDIR to locate the temporal file || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 2 Jan 2016 10:47:10 +0100 (CET)

commit 36e2bdf517773553053571a787ba720bcbfec367
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Jan 1 18:25:58 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat Jan 2 09:46:48 2016 +0000

    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.

diff --git a/ed.c b/ed.c
index 1ecd0d9..62f8477 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -329,15 +329,17 @@ 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");
+ error("failed to create scratch file");
         }
         if ((k = makeline("", NULL)))
                 error("input/output error in scratch file");
Received on Sat Jan 02 2016 - 10:47:10 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 02 2016 - 10:48:19 CET