Skip to content
Snippets Groups Projects
Commit 272c1379 authored by Dmitry Petrov's avatar Dmitry Petrov Committed by Jonas Höppner
Browse files

platform: fix read_from_file function


According to the description of "read_from_file", the function should
return a line from file when this line starts with 'match' string,
provided as an argument. But the current implementation does not follow
this description - it compares a full line (not only beginning) with the
'match' string. As a result, a desired result (line) will be returned by
the function only if a line is equal to the 'match' string.

To make the function work according to the description, replace strcmp
with strncmp.

Also remove tabulation from eol symbols to return a full line.

Signed-off-by: default avatarDmitry Petrov <dmitry.petrov@rtsoft.de>
parent 9149c6ed
No related branches found
No related tags found
1 merge request!93santvend: add an alternative way to get board rev
......@@ -231,7 +231,7 @@ char * read_from_file( const char * path, const char * match)
while ((nread = getline(&line, &len, f)) != -1 )
{
if( match == NULL || !strcmp(match, line )){
if (match == NULL || !strncmp(match, line, strlen(match))) {
found = line;
break;
}
......@@ -239,7 +239,7 @@ char * read_from_file( const char * path, const char * match)
fclose(f);
if( found != NULL ){
char *eol = strpbrk(found, "\n\r\t");
char *eol = strpbrk(found, "\n\r");
if(eol) *eol = '\0'; //replace nwematchs with null-character
}else{
free(line);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment