diff options
-rw-r--r-- | include/fs.h | 2 | ||||
-rw-r--r-- | src/fs.c | 18 |
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 @@ -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; +} + |