mirror of
https://github.com/lammertb/libhttp.git
synced 2025-09-04 12:42:09 +03:00
Allow directories with non ASCII characters in Windows in UTF-8 encoded conf file
This commit is contained in:
27
src/main.c
27
src/main.c
@@ -259,17 +259,24 @@ static void process_command_line_arguments(char *argv[], char **options)
|
|||||||
|
|
||||||
// Loop over the lines in config file
|
// Loop over the lines in config file
|
||||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||||
|
|
||||||
|
if (!line_no && !memcmp(line,"\xEF\xBB\xBF",3)) {
|
||||||
|
// strip UTF-8 BOM
|
||||||
|
p = line+3;
|
||||||
|
} else {
|
||||||
|
p = line;
|
||||||
|
}
|
||||||
line_no++;
|
line_no++;
|
||||||
|
|
||||||
// Ignore empty lines and comments
|
// Ignore empty lines and comments
|
||||||
for (i = 0; isspace(* (unsigned char *) &line[i]); ) i++;
|
for (i = 0; isspace(* (unsigned char *) &line[i]); ) i++;
|
||||||
if (line[i] == '#' || line[i] == '\0') {
|
if (p[i] == '#' || p[i] == '\0') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(line, "%s %[^\r\n#]", opt, val) != 2) {
|
if (sscanf(p, "%s %[^\r\n#]", opt, val) != 2) {
|
||||||
printf("%s: line %d is invalid, ignoring it:\n %s",
|
printf("%s: line %d is invalid, ignoring it:\n %s",
|
||||||
config_file, (int) line_no, line);
|
config_file, (int) line_no, p);
|
||||||
} else {
|
} else {
|
||||||
set_option(options, opt, val);
|
set_option(options, opt, val);
|
||||||
}
|
}
|
||||||
@@ -334,6 +341,20 @@ static void verify_existence(char **options, const char *option_name,
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
const char *path = get_option(options, option_name);
|
const char *path = get_option(options, option_name);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
wchar_t wbuf[1024];
|
||||||
|
char mbbuf[1024];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
memset(wbuf, 0, sizeof(wbuf));
|
||||||
|
memset(mbbuf, 0, sizeof(mbbuf));
|
||||||
|
len = MultiByteToWideChar(CP_UTF8, 0, path, -1, wbuf, (int) sizeof(wbuf)/sizeof(wbuf[0])-1);
|
||||||
|
wcstombs(mbbuf, wbuf, sizeof(mbbuf)-1);
|
||||||
|
path = mbbuf;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (path != NULL && (stat(path, &st) != 0 ||
|
if (path != NULL && (stat(path, &st) != 0 ||
|
||||||
((S_ISDIR(st.st_mode) ? 1 : 0) != must_be_dir))) {
|
((S_ISDIR(st.st_mode) ? 1 : 0) != must_be_dir))) {
|
||||||
die("Invalid path for %s: [%s]: (%s). Make sure that path is either "
|
die("Invalid path for %s: [%s]: (%s). Make sure that path is either "
|
||||||
|
Reference in New Issue
Block a user