2 * This file is part of DisOrder
3 * Copyright (C) 2020 Mark Wooding
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @brief Find things in the user's home directory
47 static char *profiledir
;
50 /** @brief Return the user's profile directory
51 * @return profile directory
52 * On Unix, this defaults to `$HOME/.disorder/'; on Windows, it's
53 * `%APPDATA%\DisOrder\'. The trailing delimiter is included.
55 const char *profile_directory(void) {
58 if(profiledir
) return profiledir
;
59 if((t
= getenv("DISORDER_HOME")))
65 if(SHGetKnownFolderPath(&FOLDERID_RoamingAppData
, 0, NULL
, &wpath
) != S_OK
) {
66 disorder_error(0, "error calling SHGetKnownFolderPath");
71 byte_xasprintf(&profiledir
, "%s\\DisOrder", appdata
);
74 if(!(t
= getenv("HOME"))) {
75 if(!(pw
= getpwuid(getuid())))
76 disorder_error(0, "user not found in password database");
79 byte_xasprintf(&profiledir
, "%s/.disorder", t
);
85 /** @brief Return the name of a file within the user's profile directory
86 * @param file Basename of the file desired
87 * @return Full path name of selected file.
88 * This currently doesn't do anything very useful with directory separators
91 char *profile_filename(const char *file
) {
94 if(!(d
= profile_directory())) return 0;
95 byte_xasprintf(&t
, "%s" DIRSEP
"%s", d
, file
);