mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
3f3f45580a
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/LexicalPath.h>
|
|
#include <AK/String.h>
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibCore/StandardPaths.h>
|
|
#include <pwd.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
namespace Core {
|
|
|
|
String StandardPaths::home_directory()
|
|
{
|
|
if (auto* home_env = getenv("HOME"))
|
|
return LexicalPath::canonicalized_path(home_env);
|
|
|
|
auto* pwd = getpwuid(getuid());
|
|
String path = pwd ? pwd->pw_dir : "/";
|
|
endpwent();
|
|
return LexicalPath::canonicalized_path(path);
|
|
}
|
|
|
|
String StandardPaths::desktop_directory()
|
|
{
|
|
StringBuilder builder;
|
|
builder.append(home_directory());
|
|
builder.append("/Desktop"sv);
|
|
return LexicalPath::canonicalized_path(builder.to_string());
|
|
}
|
|
|
|
String StandardPaths::downloads_directory()
|
|
{
|
|
StringBuilder builder;
|
|
builder.append(home_directory());
|
|
builder.append("/Downloads"sv);
|
|
return LexicalPath::canonicalized_path(builder.to_string());
|
|
}
|
|
|
|
String StandardPaths::config_directory()
|
|
{
|
|
StringBuilder builder;
|
|
builder.append(home_directory());
|
|
builder.append("/.config"sv);
|
|
return LexicalPath::canonicalized_path(builder.to_string());
|
|
}
|
|
|
|
String StandardPaths::tempfile_directory()
|
|
{
|
|
return "/tmp";
|
|
}
|
|
|
|
}
|