blob: 9adc689794ad56414c3631f252af97fa8a090a85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* 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::documents_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Documents"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";
}
}
|