From 1e6f5f012cf572c343fa77a4eb42133436320171 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Oct 2021 09:04:42 +0200 Subject: [PATCH] fs/StandardDirectory: add GetUserRuntimeDir() --- src/Listen.cxx | 3 ++- src/fs/StandardDirectory.cxx | 10 ++++++++++ src/fs/StandardDirectory.hxx | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Listen.cxx b/src/Listen.cxx index 34a9fe8d9..6ce7db6dc 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -32,6 +32,7 @@ #include "net/SocketUtil.hxx" #include "system/Error.hxx" #include "fs/AllocatedPath.hxx" +#include "fs/StandardDirectory.hxx" #include "fs/XDG.hxx" #include "util/Domain.hxx" #include "util/RuntimeError.hxx" @@ -85,7 +86,7 @@ ListenXdgRuntimeDir(ClientListener &listener) noexcept use $XDG_RUNTIME_DIR */ return false; - Path xdg_runtime_dir = Path::FromFS(getenv("XDG_RUNTIME_DIR")); + const auto xdg_runtime_dir = GetUserRuntimeDir(); if (xdg_runtime_dir.IsNull()) return false; diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index 7eb0fcb31..36fc914d4 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -282,6 +282,16 @@ GetUserCacheDir() noexcept #endif } +AllocatedPath +GetUserRuntimeDir() noexcept +{ +#ifdef USE_XDG + return SafePathFromFS(getenv("XDG_RUNTIME_DIR")); +#else + return nullptr; +#endif +} + #ifdef _WIN32 AllocatedPath diff --git a/src/fs/StandardDirectory.hxx b/src/fs/StandardDirectory.hxx index 4359cd68a..82b926073 100644 --- a/src/fs/StandardDirectory.hxx +++ b/src/fs/StandardDirectory.hxx @@ -43,6 +43,13 @@ GetUserMusicDir() noexcept; AllocatedPath GetUserCacheDir() noexcept; +/** + * Obtains the runtime directory for the current user. + */ +[[gnu::const]] +AllocatedPath +GetUserRuntimeDir() noexcept; + #ifdef _WIN32 /**