Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <unistd.h>
#endif

#if defined(__linux__)
#if defined(__linux__) || defined(__APPLE__)
#include <sys/types.h>
#include <pwd.h>
#endif
Expand Down Expand Up @@ -969,7 +969,16 @@ std::string fs_get_cache_directory() {
#endif /* defined(__linux__) */
}
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
if (std::getenv("HOME")) {
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
} else {
/* no $HOME is defined (e.g. LaunchDaemon context), fallback to getpwuid */
struct passwd *pw = getpwuid(getuid());
if ((!pw) || (!pw->pw_dir)) {
throw std::runtime_error("Failed to find $HOME directory");
}
cache_directory = std::string(pw->pw_dir) + std::string("/Library/Caches/");
}
#elif defined(_WIN32)
cache_directory = std::getenv("LOCALAPPDATA");
#elif defined(__EMSCRIPTEN__)
Expand Down