projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Typos.
[bertos.git]
/
bertos
/
mware
/
ini_reader.c
diff --git
a/bertos/mware/ini_reader.c
b/bertos/mware/ini_reader.c
index 5e7c28733722cdf7dba7903797ed416209bd75a1..2f1e3abedd4b6a060ea671ea8a2f5480bfd43c86 100644
(file)
--- a/
bertos/mware/ini_reader.c
+++ b/
bertos/mware/ini_reader.c
@@
-32,7
+32,6
@@
*
* \brief Ini file reader module.
*
*
* \brief Ini file reader module.
*
- * \version $Id$
* \author Luca Ottaviano <lottaviano@develer.com>
*/
* \author Luca Ottaviano <lottaviano@develer.com>
*/
@@
-47,7
+46,7
@@
* The file pointer is positioned at the start of the next line.
* Returns EOF if no section was found, 0 otherwise.
*/
* The file pointer is positioned at the start of the next line.
* Returns EOF if no section was found, 0 otherwise.
*/
-static int findSection(KFile *fd, const char *section, char *line, size_t size)
+static int findSection(KFile *fd, const char *section,
size_t section_len,
char *line, size_t size)
{
while (kfile_gets(fd, line, size) != EOF)
{
{
while (kfile_gets(fd, line, size) != EOF)
{
@@
-56,11
+55,21
@@
static int findSection(KFile *fd, const char *section, char *line, size_t size)
/* accept only sections that begin at first char */
if (*ptr++ != '[')
continue;
/* accept only sections that begin at first char */
if (*ptr++ != '[')
continue;
+
/* find the end-of-section character */
for (i = 0; i < size && *ptr != ']'; ++i, ++ptr)
;
/* find the end-of-section character */
for (i = 0; i < size && *ptr != ']'; ++i, ++ptr)
;
+
+ /* The found section could be long that our section key */
+ if (section_len != i)
+ continue;
+
/* did we find the correct section? */
/* did we find the correct section? */
- if(strncmp(&line[1], section, i))
+#if CONFIG_INI_CASE_INSENSITIVE
+ if(strncasecmp(&line[1], section, section_len))
+#else
+ if(strncmp(&line[1], section, section_len))
+#endif
continue;
else
return 0;
continue;
else
return 0;
@@
-74,10
+83,10
@@
static int findSection(KFile *fd, const char *section, char *line, size_t size)
static char *getKey(const char *line, char *key, size_t size)
{
/* null-terminated string */
static char *getKey(const char *line, char *key, size_t size)
{
/* null-terminated string */
- while (isspace(*line))
+ while (isspace(
(unsigned char)
*line))
++line;
int i = 0;
++line;
int i = 0;
- while (*line != '=' && !isspace(*line) && size)
+ while (*line != '=' && !isspace(
(unsigned char)
*line) && size)
{
key[i++] = *line;
++line;
{
key[i++] = *line;
++line;
@@
-94,7
+103,7
@@
static char *getValue(const char *line, char *value, size_t size)
{
while (*line++ != '=')
;
{
while (*line++ != '=')
;
- while (isspace(*line))
+ while (isspace(
(unsigned char)
*line))
++line;
int i = 0;
while (*line && size)
++line;
int i = 0;
while (*line && size)
@@
-122,7
+131,11
@@
static int findKey(KFile *fd, const char *key, char *line, size_t size)
char curr_key[30];
getKey(line, curr_key, 30);
/* check key */
char curr_key[30];
getKey(line, curr_key, 30);
/* check key */
+#if CONFIG_INI_CASE_INSENSITIVE
+ if (!strcasecmp(curr_key, key))
+#else
if (!strcmp(curr_key, key))
if (!strcmp(curr_key, key))
+#endif
return 0;
}
while (err != EOF && *line != '[');
return 0;
}
while (err != EOF && *line != '[');
@@
-135,10
+148,11
@@
static int findKey(KFile *fd, const char *key, char *line, size_t size)
int ini_getString(KFile *fd, const char *section, const char *key, const char *default_value, char *buf, size_t size)
{
char line[CONFIG_INI_MAX_LINE_LEN];
int ini_getString(KFile *fd, const char *section, const char *key, const char *default_value, char *buf, size_t size)
{
char line[CONFIG_INI_MAX_LINE_LEN];
+
if (kfile_seek(fd, 0, KSM_SEEK_SET) == EOF)
goto error;
if (kfile_seek(fd, 0, KSM_SEEK_SET) == EOF)
goto error;
- if (findSection(fd, section, line, CONFIG_INI_MAX_LINE_LEN) == EOF)
+ if (findSection(fd, section,
strlen(section),
line, CONFIG_INI_MAX_LINE_LEN) == EOF)
goto error;
if (findKey(fd, key, line, CONFIG_INI_MAX_LINE_LEN) == EOF)
goto error;
if (findKey(fd, key, line, CONFIG_INI_MAX_LINE_LEN) == EOF)