From 23e5c022b7fdeba95d20d53eaac9cef061440aa7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 25 Feb 2020 12:44:33 -0500 Subject: Add spm_mkdtemp() function --- include/fs.h | 2 ++ src/fs.c | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/fs.h b/include/fs.h index 2b656c9..eff266d 100644 --- a/include/fs.h +++ b/include/fs.h @@ -27,5 +27,7 @@ char *basename(char *path); int rsync(const char *_args, const char *_source, const char *_destination); char *human_readable_size(uint64_t n); char *expandpath(const char *_path); +char *spm_mkdtemp(const char *name); + #endif //SPM_FSTREE_H diff --git a/src/fs.c b/src/fs.c index 2058720..ffb9135 100644 --- a/src/fs.c +++ b/src/fs.c @@ -468,4 +468,20 @@ char *human_readable_size(uint64_t n) { } return strdup(r); -} \ No newline at end of file +} + +/** + * Create a named temporary directory + * @param name + * @return success=path, failure=NULL + */ +char *spm_mkdtemp(const char *name) { + const char *template_unique = "XXXXXX"; + char *tmpdir = NULL; + char *template = calloc(PATH_MAX, sizeof(char)); + + sprintf(template, "%s%s%s_%s", TMP_DIR, DIRSEPS, name, template_unique); + tmpdir = mkdtemp(template); + return tmpdir; +} + -- cgit