From 2dcf6144853eb9fd0b77ba04d36bda73dacaf92e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 5 Aug 2020 22:56:34 +0200 Subject: Add lilv_temp_directory_path() --- src/filesystem.c | 19 +++++++++++++++++++ src/filesystem.h | 4 ++++ 2 files changed, 23 insertions(+) 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 #include +/// 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); -- cgit v1.2.1