1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-18 11:09:56 +00:00

Add additional argument to volk_get_config_path

This commit is contained in:
Carles Fernandez 2019-08-23 22:43:01 +02:00
parent 79b7233da0
commit f5cf32a142
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
3 changed files with 15 additions and 9 deletions

View File

@ -193,7 +193,7 @@ int main(int argc, char *argv[])
void read_results(std::vector<volk_gnsssdr_test_results_t> *results)
{
char path[1024];
volk_gnsssdr_get_config_path(path);
volk_gnsssdr_get_config_path(path, true);
read_results(results, std::string(path));
}
@ -255,7 +255,7 @@ void read_results(std::vector<volk_gnsssdr_test_results_t> *results, std::string
void write_results(const std::vector<volk_gnsssdr_test_results_t> *results, bool update_result)
{
char path[1024];
volk_gnsssdr_get_config_path(path);
volk_gnsssdr_get_config_path(path, false);
write_results(results, update_result, std::string(path));
}

View File

@ -26,6 +26,7 @@
#define INCLUDED_VOLK_GNSSSDR_PREFS_H
#include <volk_gnsssdr/volk_gnsssdr_common.h>
#include <stdbool.h>
#include <stdlib.h>
__VOLK_DECL_BEGIN
@ -38,10 +39,11 @@ typedef struct volk_gnsssdr_arch_pref
} volk_gnsssdr_arch_pref_t;
////////////////////////////////////////////////////////////////////////
// get path to volk_gnsssdr_config profiling info;
// get path to volk_gnsssdr_config profiling info; second arguments specifies
// if config file should be tested on existence for reading.
// returns \0 in the argument on failure.
////////////////////////////////////////////////////////////////////////
VOLK_API void volk_gnsssdr_get_config_path(char *);
VOLK_API void volk_gnsssdr_get_config_path(char *, bool);
////////////////////////////////////////////////////////////////////////
// load prefs into global prefs struct

View File

@ -16,6 +16,7 @@
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -29,7 +30,7 @@
#include <volk_gnsssdr/volk_gnsssdr_prefs.h>
void volk_gnsssdr_get_config_path(char *path)
void volk_gnsssdr_get_config_path(char *path, bool read)
{
if (!path) return;
const char *suffix = "/.volk_gnsssdr/volk_gnsssdr_config";
@ -42,7 +43,10 @@ void volk_gnsssdr_get_config_path(char *path)
{
strncpy(path, home, 512);
strcat(path, suffix2);
return;
if (!read || (access(path, F_OK) != -1))
{
return;
}
}
// check for user-local config file
@ -51,7 +55,7 @@ void volk_gnsssdr_get_config_path(char *path)
{
strncpy(path, home, 512);
strcat(path, suffix);
if (access(path, F_OK) != -1)
if (!read || (access(path, F_OK) != -1))
{
return;
}
@ -63,7 +67,7 @@ void volk_gnsssdr_get_config_path(char *path)
{
strncpy(path, home, 512);
strcat(path, suffix);
if (access(path, F_OK) != -1)
if (!read || (access(path, F_OK) != -1))
{
return;
}
@ -99,7 +103,7 @@ size_t volk_gnsssdr_load_preferences(volk_gnsssdr_arch_pref_t **prefs_res)
volk_gnsssdr_arch_pref_t *prefs = NULL;
// get the config path
volk_gnsssdr_get_config_path(path);
volk_gnsssdr_get_config_path(path, true);
if (!path[0]) return n_arch_prefs; //no prefs found
config_file = fopen(path, "r");
if (!config_file) return n_arch_prefs; //no prefs found