mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2025-02-27 15:10:35 +01:00
cconfig: allow crlf line endings
This commit is contained in:
parent
f69f0a8b46
commit
d8e4d6b88b
@ -19,6 +19,7 @@ enum cconfig_conf_error cconfig_conf_load_from_file(
|
|||||||
char *ctx_key_val;
|
char *ctx_key_val;
|
||||||
char *data;
|
char *data;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
bool use_crlf;
|
||||||
|
|
||||||
if (!file_load(path, (void **) &data, &len, true)) {
|
if (!file_load(path, (void **) &data, &len, true)) {
|
||||||
/* If file does not exist, create one with default configuration
|
/* If file does not exist, create one with default configuration
|
||||||
@ -30,7 +31,11 @@ enum cconfig_conf_error cconfig_conf_load_from_file(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_lines = strtok_r(data, "\n", &ctx_lines);
|
use_crlf = false;
|
||||||
|
if (strstr(data, "\r\n")) {
|
||||||
|
use_crlf = true;
|
||||||
|
}
|
||||||
|
pos_lines = strtok_r(data, use_crlf ? "\r\n" : "\n", &ctx_lines);
|
||||||
|
|
||||||
while (pos_lines != NULL) {
|
while (pos_lines != NULL) {
|
||||||
char *pos_line_dup;
|
char *pos_line_dup;
|
||||||
@ -90,7 +95,7 @@ enum cconfig_conf_error cconfig_conf_load_from_file(
|
|||||||
free(pos_line_dup);
|
free(pos_line_dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_lines = strtok_r(NULL, "\n", &ctx_lines);
|
pos_lines = strtok_r(NULL, use_crlf ? "\r\n" : "\n", &ctx_lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user