Re: [PATCH v2 2/3] configure.ac: define ICONV_OMITS_BOM if necessary
From: Danh Doan <hidden>
Date: 2019-11-02 00:43:54
From: Danh Doan <hidden>
Date: 2019-11-02 00:43:54
On 2019-11-01 12:56:57 -0400, Jeff King wrote:
On Fri, Nov 01, 2019 at 03:25:10PM +0700, Doan Tran Cong Danh wrote:quoted
+ v = (unsigned char)(out[0]) + (unsigned char)(out[1]); + return v != 0xfe + 0xff;I wondered at first why not just: return v[0] != 0xfe || v[1] != 0xff; but the answer is that you are catching BOMs of either endianness. We might at some point need to distinguish the two,
Yes, it's about catching BOM of either endianess. To distinguish
between LE and BE, it'll be better to use AC_C_BIGENDIAN instead (it's
friendlier for cross-compiling).
Anyway, we couldn't compare out[0] and out[1] with 0xf{e,f} directly
because char could be either signed (-2 and -1) or unsigned (0xfe, 0xff).
We must cast it to unsigned char (required to be 8 bits by POSIX),
then let the integer promotion promote it to int (at least 16 bits).
--
Danh