aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-25 12:44:33 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-25 12:44:33 -0500
commit23e5c022b7fdeba95d20d53eaac9cef061440aa7 (patch)
treefad4eff14d3cb0bdf0431a4ff9f9ef1022b28f79
parent22e50a6e8d585072bd16753cf7d581419e06194d (diff)
downloadspmc-23e5c022b7fdeba95d20d53eaac9cef061440aa7.tar.gz
Add spm_mkdtemp() function
-rw-r--r--include/fs.h2
-rw-r--r--src/fs.c18
2 files changed, 19 insertions, 1 deletions
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;
+}
+