mirror of https://github.com/PentHertz/srsLTE.git
load config file from user's home directory first before checking etc
This commit is contained in:
parent
d22e53832b
commit
77ca1d9882
|
@ -34,18 +34,10 @@
|
||||||
bool config_exists(std::string &filename, std::string default_name)
|
bool config_exists(std::string &filename, std::string default_name)
|
||||||
{
|
{
|
||||||
std::ifstream conf(filename.c_str(), std::ios::in);
|
std::ifstream conf(filename.c_str(), std::ios::in);
|
||||||
if(conf.fail()) {
|
|
||||||
// try to find file in /etc/srslte
|
|
||||||
char full_path[256];
|
|
||||||
ZERO_OBJECT(full_path);
|
|
||||||
snprintf(full_path, sizeof(full_path), "/etc/srslte/%s", default_name.c_str());
|
|
||||||
filename = std::string(full_path);
|
|
||||||
|
|
||||||
// try to open again
|
|
||||||
conf.open(filename.c_str());
|
|
||||||
if (conf.fail()) {
|
if (conf.fail()) {
|
||||||
// try home folder
|
// try config folder instead
|
||||||
const char* homedir = NULL;
|
const char* homedir = NULL;
|
||||||
|
char full_path[256];
|
||||||
ZERO_OBJECT(full_path);
|
ZERO_OBJECT(full_path);
|
||||||
if ((homedir = getenv("HOME")) == NULL) {
|
if ((homedir = getenv("HOME")) == NULL) {
|
||||||
homedir = getpwuid(getuid())->pw_dir;
|
homedir = getpwuid(getuid())->pw_dir;
|
||||||
|
@ -53,7 +45,15 @@ bool config_exists(std::string &filename, std::string default_name)
|
||||||
if (!homedir) {
|
if (!homedir) {
|
||||||
homedir = ".";
|
homedir = ".";
|
||||||
}
|
}
|
||||||
snprintf(full_path, sizeof(full_path), "%s/.srs/%s", homedir, default_name.c_str());
|
snprintf(full_path, sizeof(full_path), "%s/.config/srslte/%s", homedir, default_name.c_str());
|
||||||
|
filename = std::string(full_path);
|
||||||
|
|
||||||
|
// try to open again
|
||||||
|
conf.open(filename.c_str());
|
||||||
|
if (conf.fail()) {
|
||||||
|
// Last chance, try to find file in /etc/srslte
|
||||||
|
ZERO_OBJECT(full_path);
|
||||||
|
snprintf(full_path, sizeof(full_path), "/etc/srslte/%s", default_name.c_str());
|
||||||
filename = std::string(full_path);
|
filename = std::string(full_path);
|
||||||
|
|
||||||
// try to open again
|
// try to open again
|
||||||
|
|
Loading…
Reference in New Issue