aboutsummaryrefslogtreecommitdiff
path: root/lib/fs.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-04-18 23:54:54 -0400
committerGitHub <noreply@github.com>2020-04-18 23:54:54 -0400
commit59f7d29e2d707373ba1153337dca3279a2e3acc5 (patch)
treeffb98ee034d8f3a08366041ea2bd596c0c15986f /lib/fs.c
parente0af560cabe6343e38061884c8361daddb5c7545 (diff)
parent262a399beb9c525633d5ac96d15754faeb65a28c (diff)
downloadspmc-59f7d29e2d707373ba1153337dca3279a2e3acc5.tar.gz
Merge pull request #26 from jhunkeler/fix_spm_mkdtemp
spm_mkdtemp requires a base directory:
Diffstat (limited to 'lib/fs.c')
-rw-r--r--lib/fs.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/fs.c b/lib/fs.c
index 76dfea8..3ba01e7 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -576,19 +576,27 @@ char *human_readable_size(uint64_t n) {
/**
* Create a named temporary directory
- * @param name
+ * @param base path where temporary directory will be created
+ * @param name name of temporary directory
+ * @param extended_path a subdirectory to create beneath `base/name`, may be NULL
* @return success=path, failure=NULL
*/
-char *spm_mkdtemp(const char *name, const char *extended_path) {
+char *spm_mkdtemp(const char *base, const char *name, const char *extended_path) {
const char *template_unique = "XXXXXX";
char *tmpdir = NULL;
char template[PATH_MAX];
- sprintf(template, "%s%s%s_%s", TMP_DIR, DIRSEPS, name, template_unique);
+ if (base == NULL || name == NULL) { // extended_path is optional
+ return NULL;
+ }
+
+ sprintf(template, "%s%s%s_%s", base, DIRSEPS, name, template_unique);
tmpdir = mkdtemp(template);
+
if (tmpdir == NULL) {
return NULL;
}
+
if (extended_path != NULL) {
char extended[PATH_MAX] = {0,};
strncpy(extended, tmpdir, PATH_MAX - 1);