1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 10:44:57 +00:00
serenity/Userland/Libraries/LibCore/StandardPaths.cpp
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

65 lines
1.6 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/StandardPaths.h>
#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
namespace Core {
DeprecatedString StandardPaths::home_directory()
{
if (auto* home_env = getenv("HOME"))
return LexicalPath::canonicalized_path(home_env);
auto* pwd = getpwuid(getuid());
DeprecatedString path = pwd ? pwd->pw_dir : "/";
endpwent();
return LexicalPath::canonicalized_path(path);
}
DeprecatedString StandardPaths::desktop_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Desktop"sv);
return LexicalPath::canonicalized_path(builder.to_string());
}
DeprecatedString StandardPaths::documents_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Documents"sv);
return LexicalPath::canonicalized_path(builder.to_string());
}
DeprecatedString StandardPaths::downloads_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Downloads"sv);
return LexicalPath::canonicalized_path(builder.to_string());
}
DeprecatedString StandardPaths::config_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/.config"sv);
return LexicalPath::canonicalized_path(builder.to_string());
}
DeprecatedString StandardPaths::tempfile_directory()
{
return "/tmp";
}
}