This is a good point.

I know that, for example, gnulib has a module which provides mbs* equivalents 
of str* functions. Maybe it would be better to provide similar mbs* functions 
as extensions, rather than replacing standard str* functions. I was considering 
that, but I didn't make up my mind so far.

In fact, I have internal "p32_private_str*_l" version of each standard str* 
function, and what I can do is to simply rename them to mbs*_l. We are lucky 
that all Microsoft functions in mbsting.h are prefixed with an underscore (e.g. 
_mbschr) so there should be no issues with declaring them.

Another issue I have actually run into with str* is that tests for these 
functions started to failing at some point since gcc and clang were replacing 
them with built-in variants, so I had to add -fno-builtin (/Oi- for 
clang-cl.exe) when building tests.

You may take a look at library's implementation[1], and you'll see that it 
still may call CRT's str* functions for SBCS locales. Still adds some cost of 
accessing TLS to get locale_t object though.

- Kirill Makurin

[1] 
https://github.com/maiddaisuki/posix32/blob/master/lib/posix32-crt/src/string/common/strchr.c

________________________________
From: LIU Hao
Sent: Wednesday, December 17, 2025 3:32 PM
To: [email protected]; Kirill Makurin
Subject: Re: [Mingw-w64-public] work-in-progress POSIX API library for native 
Windows

在 2025-12-17 00:09, Kirill Makurin 写道:
> 2. string.h
>
> The library provides a few replacements:
>
> - strchr
> - strrchr
> - strstr
> - strpbrk
> - strspn
> - strcspn
> - strtok
>
> These replacements operate correctly on multibyte string. Library also 
> implements its own `strtok_r` and `strndup`.

I think this is not a good decision. These functions have dominant use on ASCII 
strings and should be
fast. The fact that they don't handle multi-byte strings correctly is a known 
limitation, and in that
case one should call `mbschr()` etc. instead.



--
Best regards,
LIU Hao

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to