diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index 73d51d7302..feea2afa9e 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -83,6 +84,27 @@ DeprecatedString StandardPaths::data_directory() return LexicalPath::canonicalized_path(builder.to_deprecated_string()); } +ErrorOr StandardPaths::runtime_directory() +{ + if (auto* data_directory = getenv("XDG_RUNTIME_DIR")) + return LexicalPath::canonicalized_path(data_directory); + + StringBuilder builder; + +#if defined(AK_OS_SERENITY) + auto sid = TRY(Core::System::getsid()); + builder.appendff("/tmp/session/{}", sid); +#elif defined(AK_OS_MACOS) + builder.append(home_directory()); + builder.append("/Library/Application Support"sv); +#else + auto uid = getuid(); + builder.appendff("/run/user/{}", uid); +#endif + + return LexicalPath::canonicalized_path(builder.to_deprecated_string()); +} + DeprecatedString StandardPaths::tempfile_directory() { return "/tmp"; diff --git a/Userland/Libraries/LibCore/StandardPaths.h b/Userland/Libraries/LibCore/StandardPaths.h index 78014ea279..ac6dd2b485 100644 --- a/Userland/Libraries/LibCore/StandardPaths.h +++ b/Userland/Libraries/LibCore/StandardPaths.h @@ -6,6 +6,7 @@ #pragma once +#include #include namespace Core { @@ -19,6 +20,7 @@ public: static DeprecatedString tempfile_directory(); static DeprecatedString config_directory(); static DeprecatedString data_directory(); + static ErrorOr runtime_directory(); }; }