2018-10-10 12:35:40 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2018-10-10 12:35:40 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
#include "profile.h"
|
2018-10-10 12:35:40 +00:00
|
|
|
|
2019-05-20 13:10:47 +00:00
|
|
|
#define SVAR(varname) \
|
|
|
|
static char *varname; \
|
|
|
|
if (varname) { \
|
|
|
|
return varname; \
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 13:10:47 +00:00
|
|
|
#define GETENV(varname, envname, fallback) \
|
|
|
|
varname = getenv(envname); \
|
|
|
|
if (!varname) { \
|
|
|
|
varname = fallback; \
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 13:10:47 +00:00
|
|
|
#define FILE_PATH(varname, filename) \
|
|
|
|
if (asprintf(&varname, "%s/" filename, profile_dir()) < 0) { \
|
|
|
|
varname = NULL; \
|
|
|
|
} \
|
|
|
|
if (!varname) { \
|
|
|
|
varname = PROFILE_DIR_DEFAULT filename; \
|
2019-03-29 15:26:02 +00:00
|
|
|
}
|
2019-05-20 13:10:47 +00:00
|
|
|
|
|
|
|
const char *profile_name(void) {
|
|
|
|
SVAR(_profile_name);
|
|
|
|
GETENV(_profile_name, "TREZOR_PROFILE_NAME", PROFILE_NAME_DEFAULT);
|
|
|
|
return _profile_name;
|
2018-10-10 12:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *profile_dir(void) {
|
2019-05-20 13:10:47 +00:00
|
|
|
SVAR(_profile_dir);
|
|
|
|
GETENV(_profile_dir, "TREZOR_PROFILE_DIR", PROFILE_DIR_DEFAULT);
|
2019-03-29 15:26:02 +00:00
|
|
|
return _profile_dir;
|
2018-10-10 12:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *profile_flash_path(void) {
|
2019-05-20 13:10:47 +00:00
|
|
|
SVAR(_flash_path);
|
|
|
|
FILE_PATH(_flash_path, "/trezor.flash");
|
2019-03-29 15:26:02 +00:00
|
|
|
return _flash_path;
|
2018-10-10 12:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *profile_sdcard_path(void) {
|
2019-05-20 13:10:47 +00:00
|
|
|
SVAR(_sdcard_path);
|
|
|
|
FILE_PATH(_sdcard_path, "/trezor.sdcard");
|
2019-03-29 15:26:02 +00:00
|
|
|
return _sdcard_path;
|
2018-10-10 12:35:40 +00:00
|
|
|
}
|