Hi Daniel, Kevin,

On 2026-02-12T16:02:11+0100, Daniel Tameling wrote:
> On Thu, Feb 12, 2026 at 01:20:18PM +0800, Kevin J. McCarthy wrote:
> > 
> > The ones in wchar.h include wcrtomb(), mbrtowc(), and wcwidth().
> > 
> > So, in this case, why are we only getting in trouble with wcwidth(), but
> > not the first two?
> > 
> 
> FreeBSD defines wcwidth as __wcwidth [1] and has in a different header
> the complete implementation of __wcwidth so that it can always be
> inlined [2].  An undef wcwidth solves the problem.
> 
> Honestly, wchar.h and wctype.h are nowadays part of POSIX and the
> C standard,

To be precise, <wchar.h> and <wctype.h> were standardized in ISO C95
(ISO/IEC 9899:1990/Amd1:1995).  It is available as N412:
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n412.pdf>.

POSIX says that these two headers were added in Issue 4, which is XPG4
(the X/Open Portability Guide), released in 1992.  However, I don't know
any public copies of that.

Issue 5, which is SUSv2, aligned with C95.

I don't know if they were available as part of POSIX.1-1996, as SUS and
POSIX hadn't merged yet.  POSIX.1-1990 certainly didn't have them (but
it had wchar_t in <stdlib.h>):
<https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub151-2.pdf>
I don't know if there's any public copy of POSIX.1-1996.

Since mutt(1) requires C99, I think it would be reasonable to assume
that these headers exist, including iwblank().

> and have been for a long time. The workaround isn't really needed
> anymore.  If somebody disagrees, they should step up and maintain the
> code.  Your limited time is better spend elsewhere.
> 
> Maybe this excerpt from POSIX is the reason for the weirdness in the
> source code?
> 
>   "The iswblank() function was a late addition to the ISO C standard
>    and was introduced at the same time as the ISO C standard
>    introduced <wctype.h>, which contains all of the isw*() functions.

This claim from POSIX doesn't seem correct.  I can't find iswblank() in
ISO C95 (N412), while I can certainly find <wctype.h>.

Even in ISO C96 (ISO/IEC 9899:1990/Cor2:1996), iswblank() still doesn't
appear: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n457.pdf>.

The first appearance of iswblank() seems to be in ISO C99.
POSIX added it in Issue 6 (POSIX.1-2001).

>    The Open Group Base Specifications had previously aligned with the
>    MSE working draft and had introduced the rest of the isw*()
>    functions into <wchar.h>.  For backwards-compatibility, the
>    original set of isw*() functions, without iswblank(), are permitted
>    (as an XSI extension) in <wchar.h>.  For maximum portability,
>    applications should include <wctype.h> in order to obtain
>    declarations for the isw*() functions."[3]

Yeah, just include both.  I think it was a mistake to have a single huge
header file for all wchar_t APIs.


Have a lovely day!
Alex

> 
> Best regards,
> Daniel
> 
> [1]: https://cgit.freebsd.org/src/tree/include/wchar.h#n221
> [2]: https://cgit.freebsd.org/src/tree/include/_ctype.h#n157
> [3]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/wchar.h.html

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to