From: Peter Krefting Date: Mon, 26 Feb 2018 18:43:08 GMT Subject: Re: [PATCH/RFC 1/1] Auto diff of UTF-16 files in UTF-8 Message-ID: In-Reply-To: <20180226172706.7822-1-tboegi@web.de> tboegi@web.de: > +static inline int buffer_has_utf16_bom(const void *buf, size_t len) { > + const unsigned char *text = (unsigned char *)buf; > + if (!text || len < 2) > + return 0; > + if (text[0] == 0xff && text[1] == 0xfe) > + return 1; > + if (text[0] == 0xfe && text[1] == 0xff) > + return 1; > + return 0; > +} This would also match a UTF-32LE BOM, not that I think anyone would actually use that for text files, but it might be worth adding a test for that, just in case? if (text[0] == 0xff && text[1] == 0xfe) return len < 4 || (text[2] != 0 && text[3] != 0); -- \\// Peter - http://www.softwolves.pp.se/