From fcfa8470b29d0a16eaf195ca44d85c31b2b1d9d7 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Mon, 3 Aug 2020 13:46:25 -0700 Subject: [PATCH] update platform_config --- components/platform_config/platform_config.c | 12 ++++++++++++ components/platform_config/platform_config.h | 1 + 2 files changed, 13 insertions(+) diff --git a/components/platform_config/platform_config.c b/components/platform_config/platform_config.c index e2b59f66..10bcc121 100644 --- a/components/platform_config/platform_config.c +++ b/components/platform_config/platform_config.c @@ -611,9 +611,21 @@ void config_delete_key(const char *key){ } config_unlock(); } + void * config_alloc_get(nvs_type_t nvs_type, const char *key) { return config_alloc_get_default(nvs_type, key, NULL, 0); } + +void * config_alloc_get_str(const char *key, char *lead, char *fallback) { + if (lead && *lead) return strdup(lead); + char *value = config_alloc_get_default(NVS_TYPE_STR, key, NULL, 0); + if ((!value || !*value) && fallback) { + if (value) free(value); + value = strdup(fallback); + } + return value; +} + void * config_alloc_get_default(nvs_type_t nvs_type, const char *key, void * default_value, size_t blob_size) { void * value = NULL; diff --git a/components/platform_config/platform_config.h b/components/platform_config/platform_config.h index 92d38c86..6215e6b2 100644 --- a/components/platform_config/platform_config.h +++ b/components/platform_config/platform_config.h @@ -35,6 +35,7 @@ void config_commit_to_nvs(); void config_start_timer(); void config_init(); void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size); +void * config_alloc_get_str(const char *key, char *lead, char *fallback); void config_delete_key(const char *key); void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size); void * config_alloc_get(nvs_type_t nvs_type, const char *key) ;