diff options
author | Daniel Mack <github@zonque.org> | 2016-03-23 13:00:33 +0100 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2016-03-23 13:00:33 +0100 |
commit | 51359d02d176d6f7908dcc3456f2e7a913bd5de4 (patch) | |
tree | 32e98756ad8a6abe0aa3b80f19093b8f7506ce1d /src | |
parent | 944dedd302f7b579655d873bcbc91b81dc548820 (diff) | |
parent | 9dd7ea9a7d5053be0c2a744b1b57a7b1dc203f0e (diff) |
Merge pull request #2883 from keszybz/allow-boms
Ignore BOM in config files
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/utf8.h | 1 | ||||
-rw-r--r-- | src/shared/conf-parser.c | 13 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/basic/utf8.h b/src/basic/utf8.h index 12c272d66e..f9b9c9468b 100644 --- a/src/basic/utf8.h +++ b/src/basic/utf8.h @@ -28,6 +28,7 @@ #include "missing.h" #define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd" +#define UTF8_BYTE_ORDER_MARK "\xef\xbb\xbf" bool unichar_is_valid(char32_t c); diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index e7fe9ac21e..bd0a1f483b 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -294,7 +294,7 @@ int config_parse(const char *unit, _cleanup_free_ char *section = NULL, *continuation = NULL; _cleanup_fclose_ FILE *ours = NULL; unsigned line = 0, section_line = 0; - bool section_ignored = false; + bool section_ignored = false, allow_bom = true; int r; assert(filename); @@ -314,11 +314,11 @@ int config_parse(const char *unit, fd_warn_permissions(filename, fileno(f)); - while (!feof(f)) { - char l[LINE_MAX], *p, *c = NULL, *e; + for (;;) { + char buf[LINE_MAX], *l, *p, *c = NULL, *e; bool escaped = false; - if (!fgets(l, sizeof(l), f)) { + if (!fgets(buf, sizeof buf, f)) { if (feof(f)) break; @@ -326,6 +326,11 @@ int config_parse(const char *unit, return -errno; } + l = buf; + if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK)) + l += strlen(UTF8_BYTE_ORDER_MARK); + allow_bom = false; + truncate_nl(l); if (continuation) { |