summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-09-01 22:05:22 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-09-01 22:05:22 +0000
commit42ad49625167131af5054cd4c42cefb260eb88e8 (patch)
tree30c6883c862bf08527ebd6ad081da4cd3964e6fd
parent478f924c896218cf28f4e74b63854ad446ecc233 (diff)
downloadmailutils-42ad49625167131af5054cd4c42cefb260eb88e8.tar.gz
mailutils-42ad49625167131af5054cd4c42cefb260eb88e8.tar.bz2
(mu_tempname): New function. Creates a unique temporary file name in tmpdir.
-rw-r--r--include/mailutils/mutil.h1
-rw-r--r--mailbox/mutil.c17
2 files changed, 17 insertions, 1 deletions
diff --git a/include/mailutils/mutil.h b/include/mailutils/mutil.h
index c9dcc69d3..b89091f6f 100644
--- a/include/mailutils/mutil.h
+++ b/include/mailutils/mutil.h
@@ -96,6 +96,7 @@ extern char *mu_get_user_email __P ((const char *name));
extern char *mu_normalize_path __P ((char *path, const char *delim));
extern char *mu_normalize_maildir __P ((const char *dir));
extern int mu_tempfile __P ((const char *tmpdir, char **namep));
+extern char *mu_tempname __P ((const char *tmpdir));
extern char * mu_get_full_path __P((const char *file));
extern char * mu_getcwd __P((void));
diff --git a/mailbox/mutil.c b/mailbox/mutil.c
index 4e23895ea..3312cdcb4 100644
--- a/mailbox/mutil.c
+++ b/mailbox/mutil.c
@@ -692,7 +692,7 @@ mu_normalize_maildir (const char *dir)
}
}
-/* Create and open a temporary file. Be vary careful about it, since we
+/* Create and open a temporary file. Be very careful about it, since we
may be running with extra privilege i.e setgid().
Returns file descriptor of the open file.
If namep is not NULL, the pointer to the malloced file name will
@@ -748,6 +748,21 @@ mu_tempfile (const char *tmpdir, char **namep)
return fd;
}
+/* Create a unique temporary file name in tmpdir. The function
+ creates an empty file with this name to avoid possible race
+ conditions. Returns a pointer to the malloc'ed file name.
+ If tmpdir is NULL, the value of the environment variable
+ TMPDIR or the hardcoded P_tmpdir is used, whichever is defined. */
+
+char *
+mu_tempname (const char *tmpdir)
+{
+ char *filename = NULL;
+ int fd = mu_tempfile (tmpdir, &filename);
+ close (fd);
+ return filename;
+}
+
/* See Advanced Programming in the UNIX Environment, Stevens,
* program 10.20 for the rational for the signal handling. I
* had to look it up, so if somebody else is curious, thats where

Return to:

Send suggestions and report system problems to the System administrator.