mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
LibCore: Add a standard path for runtime communication files
This corresponds to XDG_RUNTIME_DIR, which is the path applications may place runtime communication files, like local sockets.
This commit is contained in:
parent
7a5ceebb50
commit
c46c3555a1
2 changed files with 24 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -83,6 +84,27 @@ DeprecatedString StandardPaths::data_directory()
|
||||||
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
|
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<DeprecatedString> 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()
|
DeprecatedString StandardPaths::tempfile_directory()
|
||||||
{
|
{
|
||||||
return "/tmp";
|
return "/tmp";
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Error.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
@ -19,6 +20,7 @@ public:
|
||||||
static DeprecatedString tempfile_directory();
|
static DeprecatedString tempfile_directory();
|
||||||
static DeprecatedString config_directory();
|
static DeprecatedString config_directory();
|
||||||
static DeprecatedString data_directory();
|
static DeprecatedString data_directory();
|
||||||
|
static ErrorOr<DeprecatedString> runtime_directory();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue