diff options
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); |