diff options
author | David Robillard <d@drobilla.net> | 2020-08-05 22:56:34 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-06 17:34:42 +0200 |
commit | 2dcf6144853eb9fd0b77ba04d36bda73dacaf92e (patch) | |
tree | ed016222b9c8898fe08796e667b0ac1405e24b44 /src | |
parent | 5681c3e2531bbc6768ca850391b63e78aff2f2b2 (diff) | |
download | lilv-2dcf6144853eb9fd0b77ba04d36bda73dacaf92e.tar.gz lilv-2dcf6144853eb9fd0b77ba04d36bda73dacaf92e.tar.bz2 lilv-2dcf6144853eb9fd0b77ba04d36bda73dacaf92e.zip |
Add lilv_temp_directory_path()
Diffstat (limited to 'src')
-rw-r--r-- | src/filesystem.c | 19 | ||||
-rw-r--r-- | src/filesystem.h | 4 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index 6b17ccb..39ba2a2 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -68,6 +68,25 @@ is_windows_path(const char* path) } #endif +char* +lilv_temp_directory_path(void) +{ +#ifdef _WIN32 + DWORD len = GetTempPath(0, NULL); + char* buf = (char*)calloc(len, 1); + if (GetTempPath(len, buf) == 0) { + free(buf); + return NULL; + } + + return buf; +#else + const char* const tmpdir = getenv("TMPDIR"); + + return tmpdir ? lilv_strdup(tmpdir) : lilv_strdup("/tmp"); +#endif +} + bool lilv_path_is_absolute(const char* path) { diff --git a/src/filesystem.h b/src/filesystem.h index 9cf6e4b..8971372 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -17,6 +17,10 @@ #include <stdbool.h> #include <stdio.h> +/// Return the path to a directory suitable for making temporary files +char* +lilv_temp_directory_path(void); + /// Return true iff `path` is an absolute path bool lilv_path_is_absolute(const char* path); |