aboutsummaryrefslogtreecommitdiff
path: root/lib/fs.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-04-18 23:50:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-04-18 23:50:52 -0400
commit262a399beb9c525633d5ac96d15754faeb65a28c (patch)
treeffb98ee034d8f3a08366041ea2bd596c0c15986f /lib/fs.c
parente0af560cabe6343e38061884c8361daddb5c7545 (diff)
downloadspmc-262a399beb9c525633d5ac96d15754faeb65a28c.tar.gz
spm_mkdtemp requires a base directory:
* test_spm_mkdtemp revealed a difference in how variables are stored (Linux vs. MacOS)
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);