Skip to content
Snippets Groups Projects
Commit 0bad3364 authored by schneider's avatar schneider
Browse files

fix(config): deal with windows line endings

parent 30fe792a
No related branches found
No related tags found
1 merge request!339New config api with support for dynamic keys
...@@ -186,6 +186,18 @@ parse_line(char *line, char *eol, int line_number, size_t line_offset) ...@@ -186,6 +186,18 @@ parse_line(char *line, char *eol, int line_number, size_t line_offset)
add_config_pair(key, value, line_number, value_offset); add_config_pair(key, value, line_number, value_offset);
} }
// convert windows line endings to unix line endings.
// we don't care about the extra empty lines
static void convert_crlf_to_lflf(char *buf, int n)
{
while (n--) {
if (*buf == '\r') {
*buf = '\n';
}
buf++;
}
}
// parses the entire config file // parses the entire config file
void load_config(void) void load_config(void)
{ {
...@@ -206,6 +218,7 @@ void load_config(void) ...@@ -206,6 +218,7 @@ void load_config(void)
int nread; int nread;
do { do {
nread = epic_file_read(fd, buf, MAX_LINE_LENGTH); nread = epic_file_read(fd, buf, MAX_LINE_LENGTH);
convert_crlf_to_lflf(buf, nread);
if (nread < MAX_LINE_LENGTH) { if (nread < MAX_LINE_LENGTH) {
//add fake EOL to ensure termination //add fake EOL to ensure termination
buf[nread++] = '\n'; buf[nread++] = '\n';
...@@ -257,7 +270,7 @@ void load_config(void) ...@@ -257,7 +270,7 @@ void load_config(void)
} }
char newline; char newline;
rc = epic_file_read(fd, &newline, 1); rc = epic_file_read(fd, &newline, 1);
if (rc < 0 || newline != '\n') { if (rc < 0 || (newline != '\n' && newline != '\r')) {
LOG_ERR("card10.cfg", "seek failed, aborting"); LOG_ERR("card10.cfg", "seek failed, aborting");
LOG_DEBUG( LOG_DEBUG(
"card10.cfg", "card10.cfg",
......
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