From 0022b746edc14ed9514b609437d3a42ce7509f83 Mon Sep 17 00:00:00 2001 From: lottaviano Date: Mon, 8 Jun 2009 16:00:34 +0000 Subject: [PATCH] Fix ini_reader when no new line at EOF git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2711 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/mware/ini_reader.c | 5 ++++- bertos/mware/ini_reader_test.c | 3 +++ test/ini_reader_file.ini | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bertos/mware/ini_reader.c b/bertos/mware/ini_reader.c index 037570dc..5e7c2873 100644 --- a/bertos/mware/ini_reader.c +++ b/bertos/mware/ini_reader.c @@ -115,14 +115,17 @@ static char *getValue(const char *line, char *value, size_t size) */ static int findKey(KFile *fd, const char *key, char *line, size_t size) { - while (kfile_gets(fd, line, size) != EOF && *line != '[') + int err; + do { + err = kfile_gets(fd, line, size); char curr_key[30]; getKey(line, curr_key, 30); /* check key */ if (!strcmp(curr_key, key)) return 0; } + while (err != EOF && *line != '['); return EOF; } diff --git a/bertos/mware/ini_reader_test.c b/bertos/mware/ini_reader_test.c index 495685eb..8237d970 100644 --- a/bertos/mware/ini_reader_test.c +++ b/bertos/mware/ini_reader_test.c @@ -87,6 +87,9 @@ int ini_reader_testRun(void) ASSERT(ini_getString(&kf.fd, "Long section with spaces", "value", "", buf, 30) != EOF); ASSERT(strcmp(buf, "long value") == 0); + + ASSERT(ini_getString(&kf.fd, "Long section with spaces", "no_new_line", "", buf, 30) != EOF); + ASSERT(strcmp(buf, "value") == 0); return 0; } diff --git a/test/ini_reader_file.ini b/test/ini_reader_file.ini index 8837e105..606c439c 100644 --- a/test/ini_reader_file.ini +++ b/test/ini_reader_file.ini @@ -13,3 +13,4 @@ comment = line with #comment [Long section with spaces] value = long value +no_new_line = value \ No newline at end of file -- 2.25.1