Skip to content

Commit

Permalink
subsys/settings: Add const modifier to the value pointer
Browse files Browse the repository at this point in the history
This commit adds const modifier for value pointer in
settings_save_one function.

Signed-off-by: Radoslaw Koppel <[email protected]>
  • Loading branch information
rakons authored and nashif committed May 29, 2019
1 parent f8f6e7e commit 974231e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct settings_handler {
* User might use it to apply setting to the application.
*/

int (*h_export)(int (*export_func)(const char *name, void *val,
int (*h_export)(int (*export_func)(const char *name, const void *val,
size_t val_len));
/**< This gets called to dump all current settings items.
*
Expand Down Expand Up @@ -139,7 +139,7 @@ int settings_save(void);
*
* @return 0 on success, non-zero on failure.
*/
int settings_save_one(const char *name, void *value, size_t val_len);
int settings_save_one(const char *name, const void *value, size_t val_len);

/**
* Delete a single serialized in persisted storage.
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static int commit(void)
return 0;
}

static int export(int (*export_func)(const char *name, void *val,
static int export(int (*export_func)(const char *name, const void *val,
size_t val_len))

{
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/host/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct bt_settings_handler {
int (*set)(int argc, char **argv, size_t len, settings_read_cb read_cb,
void *cb_arg);
int (*commit)(void);
int (*export)(int (*func)(const char *name, void *val,
size_t val_len));
int (*export)(int (*func)(const char *name,
const void *val, size_t val_len));
};

#define BT_SETTINGS_DEFINE(_name, _set, _commit, _export) \
Expand Down
2 changes: 1 addition & 1 deletion subsys/settings/src/settings_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int settings_load(void)
/*
* Append a single value to persisted config. Don't store duplicate value.
*/
int settings_save_one(const char *name, void *value, size_t val_len)
int settings_save_one(const char *name, const void *value, size_t val_len)
{
struct settings_store *cs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct deletable_s {

u32_t val4v2;

int c4_handle_export(int (*cb)(const char *name, void *value, size_t val_len));
int c4_handle_export(int (*cb)(const char *name, const void *value, size_t val_len));

struct settings_handler c4_test_handler = {
.name = "4",
Expand All @@ -38,7 +38,7 @@ struct settings_handler c4_test_handler = {
.h_export = c4_handle_export
};

int c4_handle_export(int (*cb)(const char *name, void *value, size_t val_len))
int c4_handle_export(int (*cb)(const char *name, const void *value, size_t val_len))
{
if (deletable_val.valid) {
(void)cb(NAME_DELETABLE, &deletable_val.val32,
Expand Down
18 changes: 12 additions & 6 deletions tests/subsys/settings/fcb/src/settings_test_fcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max);
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
void *cb_arg);
int c1_handle_commit(void);
int c1_handle_export(int (*cb)(const char *name, void *value, size_t val_len));
int c1_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len));

int c2_handle_get(int argc, char **argv, char *val, int val_len_max);
int c2_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
void *cb_arg);
int c2_handle_export(int (*cb)(const char *name, void *value, size_t val_len));
int c2_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len));

int c3_handle_get(int argc, char **argv, char *val, int val_len_max);
int c3_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
void *cb_arg);
int c3_handle_export(int (*cb)(const char *name, void *value, size_t val_len));
int c3_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len));

struct settings_handler c_test_handlers[] = {
{
Expand Down Expand Up @@ -122,7 +125,8 @@ int c1_handle_commit(void)
return 0;
}

int c1_handle_export(int (*cb)(const char *name, void *value, size_t val_len))
int c1_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len))
{
if (test_export_block) {
return 0;
Expand Down Expand Up @@ -269,7 +273,8 @@ int c2_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
return -ENOENT;
}

int c2_handle_export(int (*cb)(const char *name, void *value, size_t val_len))
int c2_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len))
{
int i;
char name[32];
Expand Down Expand Up @@ -310,7 +315,8 @@ int c3_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
return -ENOENT;
}

int c3_handle_export(int (*cb)(const char *name, void *value, size_t val_len))
int c3_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len))
{
(void)cb("3/v", &val32, sizeof(val32));

Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/settings/fcb_init/src/settings_test_fcb_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ static int c1_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
return -ENOENT;
}

static int c1_export(int (*export_func)(const char *name, void *value,
size_t val_len))
static int c1_export(int (*export_func)(const char *name,
const void *value, size_t val_len))
{
(void)export_func("hello/val32", &val32, sizeof(val32));

Expand Down
6 changes: 4 additions & 2 deletions tests/subsys/settings/nffs/src/settings_test_nffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max);
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
void *cb_arg);
int c1_handle_commit(void);
int c1_handle_export(int (*cb)(const char *name, void *value, size_t val_len));
int c1_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len));

struct settings_handler c_test_handlers[] = {
{
Expand Down Expand Up @@ -108,7 +109,8 @@ int c1_handle_commit(void)
return 0;
}

int c1_handle_export(int (*cb)(const char *name, void *value, size_t val_len))
int c1_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len))
{
if (test_export_block) {
return 0;
Expand Down

0 comments on commit 974231e

Please sign in to comment.