Re: [PATCH] dir: allow a BOM at the beginning of exclude files
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Apr 16, 2015, 16:10 UTC
- Message-ID
- <552FDF05.4060000@web.de>
- In-Reply-To
- <1429193112-41184-1-git-send-email-cmn@elego.de>
On 2015-04-16 16.05, Carlos Martín Nieto wrote: [] May be it is easier to move this into an own function, like remove_utf8_bom() ?
Show 13 quoted lines
> dir.c | 8 +++++++- > t/t7061-wtstatus-ignore.sh | 2 ++ > 2 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/dir.c b/dir.c > index 0943a81..6368247 100644 > --- a/dir.c > +++ b/dir.c > @@ -581,6 +581,7 @@ int add_excludes_from_file_to_list(const char *fname, > struct stat st; > int fd, i, lineno = 1; > size_t size = 0; > + static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
Do we really need to cast here (and if, is the cast dropping the "const" ?)
Another suggestion, see below: either: static const size_t bom_len = 3; or static const size_t bom_len = strlen(utf8_bom);
Show 9 quoted lines
> char *buf, *entry; > > fd = open(fname, O_RDONLY); > @@ -617,7 +618,12 @@ int add_excludes_from_file_to_list(const char *fname, > } > > el->filebuf = buf; > - entry = buf; > +
And now we can avoid magic numbers: if (size >= bom_len && !memcmp(buf, utf8_bom, bom_len)) entry = buf + bom_len; else entry = buf; []