mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
plugins: Make 'struct configdata' argument to the configfile helper const
So plugins can use const structures, possibly saving a little bit of RAM. Change-Id: I15b0ef20e7554caf5f6d1c12f6ab109ddf3c0dbd
This commit is contained in:
parent
08c4b708ae
commit
0d4752e3f6
2 changed files with 12 additions and 12 deletions
|
@ -42,7 +42,7 @@ static void get_cfg_filename(char* buf, int buf_len, const char* filename)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int configfile_save(const char *filename, struct configdata *cfg,
|
int configfile_save(const char *filename, const struct configdata *cfg,
|
||||||
int num_items, int version)
|
int num_items, int version)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -56,7 +56,7 @@ int configfile_save(const char *filename, struct configdata *cfg,
|
||||||
|
|
||||||
/* pre-allocate 10 bytes for INT */
|
/* pre-allocate 10 bytes for INT */
|
||||||
rb->fdprintf(fd, "file version: %10d\n", version);
|
rb->fdprintf(fd, "file version: %10d\n", version);
|
||||||
|
|
||||||
for(i = 0;i < num_items;i++) {
|
for(i = 0;i < num_items;i++) {
|
||||||
switch(cfg[i].type) {
|
switch(cfg[i].type) {
|
||||||
case TYPE_INT:
|
case TYPE_INT:
|
||||||
|
@ -91,7 +91,7 @@ int configfile_save(const char *filename, struct configdata *cfg,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int configfile_load(const char *filename, struct configdata *cfg,
|
int configfile_load(const char *filename, const struct configdata *cfg,
|
||||||
int num_items, int min_version)
|
int num_items, int min_version)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -118,7 +118,7 @@ int configfile_load(const char *filename, struct configdata *cfg,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0;i < num_items;i++) {
|
for(i = 0;i < num_items;i++) {
|
||||||
if(!rb->strcmp(cfg[i].name, name)) {
|
if(!rb->strcmp(cfg[i].name, name)) {
|
||||||
switch(cfg[i].type) {
|
switch(cfg[i].type) {
|
||||||
|
@ -149,7 +149,7 @@ int configfile_load(const char *filename, struct configdata *cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -190,13 +190,13 @@ int configfile_update_entry(const char* filename, const char* name, int val)
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int line_len = 0;
|
int line_len = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
/* open the current config file */
|
/* open the current config file */
|
||||||
get_cfg_filename(path, MAX_PATH, filename);
|
get_cfg_filename(path, MAX_PATH, filename);
|
||||||
fd = rb->open(path, O_RDWR);
|
fd = rb->open(path, O_RDWR);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* read in the current stored settings */
|
/* read in the current stored settings */
|
||||||
while((line_len = rb->read_line(fd, buf, 256)) > 0)
|
while((line_len = rb->read_line(fd, buf, 256)) > 0)
|
||||||
{
|
{
|
||||||
|
@ -211,13 +211,13 @@ int configfile_update_entry(const char* filename, const char* name, int val)
|
||||||
}
|
}
|
||||||
pos += line_len;
|
pos += line_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if (name/val) is a new entry just append to file */
|
/* if (name/val) is a new entry just append to file */
|
||||||
if (found == 0)
|
if (found == 0)
|
||||||
/* pre-allocate 10 bytes for INT */
|
/* pre-allocate 10 bytes for INT */
|
||||||
rb->fdprintf(fd, "%s: %10d\n", name, val);
|
rb->fdprintf(fd, "%s: %10d\n", name, val);
|
||||||
|
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,10 @@ struct configdata
|
||||||
/* configfile_save - Given configdata entries this function will
|
/* configfile_save - Given configdata entries this function will
|
||||||
create a config file with these entries, destroying any
|
create a config file with these entries, destroying any
|
||||||
previous config file of the same name */
|
previous config file of the same name */
|
||||||
int configfile_save(const char *filename, struct configdata *cfg,
|
int configfile_save(const char *filename, const struct configdata *cfg,
|
||||||
int num_items, int version);
|
int num_items, int version);
|
||||||
|
|
||||||
int configfile_load(const char *filename, struct configdata *cfg,
|
int configfile_load(const char *filename, const struct configdata *cfg,
|
||||||
int num_items, int min_version);
|
int num_items, int min_version);
|
||||||
|
|
||||||
/* configfile_get_value - Given a key name, this function will
|
/* configfile_get_value - Given a key name, this function will
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue