attr: skip UTF8 BOM at the beginning of the input file
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 16, 2015 at 10:48 UTC
27547e5fccda134560ad0441aa5bfa187387cec0
1 file changed
+7
-2
attr.c
+7
-2
@@ -12,6 +12,7 @@
12
#include "exec_cmd.h"
13
#include "attr.h"
14
#include "dir.h"
15
+#include "utf8.h"
16
17
const char git_attr__true[] = "(builtin)true";
18
const char git_attr__false[] = "\0(builtin)false";
@@ -369,8 +370,12 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
370
return NULL;
371
}
372
res = xcalloc(1, sizeof(*res));
372
- while (fgets(buf, sizeof(buf), fp))
373
- handle_attr_line(res, buf, path, ++lineno, macro_ok);
373
+ while (fgets(buf, sizeof(buf), fp)) {
374
+ char *bufp = buf;
375
+ if (!lineno)
376
+ skip_utf8_bom(&bufp, strlen(bufp));
377
+ handle_attr_line(res, bufp, path, ++lineno, macro_ok);
378
+ }
379
fclose(fp);
380
return res;
381
}