1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-15 02:37:37 +01:00

cconfig: allow crlf line endings

This commit is contained in:
Will Xyen 2019-12-01 11:41:09 -05:00
parent 0ca353b250
commit 48622f6a58

View File

@ -19,6 +19,7 @@ enum cconfig_conf_error cconfig_conf_load_from_file(
char *ctx_key_val;
char *data;
size_t len;
bool use_crlf;
if (!file_load(path, (void **) &data, &len, true)) {
/* 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) {
char *pos_line_dup;
@ -90,7 +95,7 @@ enum cconfig_conf_error cconfig_conf_load_from_file(
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);