From b4be52ba7889e44ddc8be3e1470af980bb15377f Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 27 Jul 2001 19:27:09 +0000 Subject: [PATCH] * util.c (mc_mkstemps): Don't prepend $TMPDIR if prefix contains path separator. --- src/ChangeLog | 5 +++++ src/util.c | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bc44a2c4d..99e6a42bb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2001-07-27 Pavel Roskin + + * util.c (mc_mkstemps): Don't prepend $TMPDIR if prefix contains + path separator. + 2001-07-26 Pavel Roskin * cmd.c (do_link): Append filename to the default symlink diff --git a/src/util.c b/src/util.c index aa812a33f..82ea27069 100644 --- a/src/util.c +++ b/src/util.c @@ -1316,7 +1316,8 @@ concat_dir_and_file (const char *dir, const char *file) * Arguments: * pname (output) - pointer to the name of the temp file (needs g_free). * NULL if the function fails. - * prefix - part of the filename before the random part (without directory). + * prefix - part of the filename before the random part. + * Prepend $TMPDIR or /tmp if there are no path separators. * suffix - if not NULL, part of the filename after the random part. * * Result: @@ -1328,19 +1329,24 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix) = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static unsigned long value; struct timeval tv; - char *tmpdir; char *tmpbase; char *tmpname; char *XXXXXX; int count; - tmpdir = getenv("TMPDIR"); - if (!tmpdir) { - tmpdir = TMPDIR_DEFAULT; - } + if (strchr(prefix, PATH_SEP) == NULL) { + char *tmpdir; - /* Add prefix first to find the position of XXXXXX */ - tmpbase = concat_dir_and_file (tmpdir, prefix); + tmpdir = getenv("TMPDIR"); + if (!tmpdir) { + tmpdir = TMPDIR_DEFAULT; + } + + /* Add prefix first to find the position of XXXXXX */ + tmpbase = concat_dir_and_file (tmpdir, prefix); + } else { + tmpbase = g_strdup (prefix); + } tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, NULL); *pname = tmpname;