diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-25 12:44:33 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-25 12:44:33 -0500 |
commit | 23e5c022b7fdeba95d20d53eaac9cef061440aa7 (patch) | |
tree | fad4eff14d3cb0bdf0431a4ff9f9ef1022b28f79 | |
parent | 22e50a6e8d585072bd16753cf7d581419e06194d (diff) | |
download | spmc-23e5c022b7fdeba95d20d53eaac9cef061440aa7.tar.gz |
Add spm_mkdtemp() function
-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; +} + |