Go to file
Pali Rohár bafccb49a0 crt: Add support for C95 wcstok() function for non-UCRT import libraries
All non-UCRT crt library versions provide wcstok symbol which is not C95+
compatible. Its function prototype is missing the third argument. In UCRT
version this function without third argument is named _wcstok(). So rename
wcstok symbol to _wcstok in all non-UCRT import libraries for compatibility
with UCRT.

msvcr80+ provides wcstok_s symbol which is C95+ compatible wcstok()
function. msvcr80+ wcstok_s() function has same function prototype as C95+
wcstok() and the only difference between MS wcstok_s and C95 wcstok is that
MS wcstok_s validates parameters and sets errno. C95 version has undefined
behavior when called with invalid parameters (e.g. Linux version crashes).

So add appropriate aliases of wcstok_s in msvcr80+ import libraries to have
C95+ compatible wcstok() function under the correct C95 name wcstok.

For pre-msvcr80 import libraries, provide mingw-w64 implementation of
wcstok_s() and C95+ wcstok() functions. So when linking with any crt
library, the wcstok symbol resolve to the correct C95 compatible wcstok()
function. mingw-w64 implementation of wcstok is copied from musl libc which
is very compact and some parts from musl libc are already used in mingw-w64.

Update header files to reflect these changes. With this change, C95+
compatible wcstok() function is available for all builds, not only UCRT as
it was before this change.

For compatibility with C99, add missing restrict keyword for last wcstok()
argument in header files.

mingw-w64 is currently missing MS _wcstok() function for UCRT builds.
So provide it into UCRT import libraries.

Visual Studio 2015+ redefines wcstok() to _wcstok() when macro
_CRT_NON_CONFORMING_WCSTOK is defined. And in C++ mode it provides
overloaded C++ function wcstok() with two arguments unless the macro
_CRT_NO_INLINE_DEPRECATED_WCSTOK is defined. It is documented on:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strtok-strtok-l-wcstok-wcstok-l-mbstok-mbstok-l

Implement same logic for _CRT_NON_CONFORMING_WCSTOK to get the old behavior
by default. And provides C++ inline two-argument function unless define
_CRT_NO_INLINE_DEPRECATED_WCSTOK is set.

With this change mingw-w64 always provides C95+ compatible wcstok()
function and MS two-arg _wcstok() function in all CRT import libraries.
Also every CRT import library provides MS wcstok_s() function.

Signed-off-by: Martin Storsjö <martin@martin.st>
2024-11-15 23:54:11 +02:00
build-aux Regenerate configure with autoconf 2.72 2024-01-09 22:26:23 +08:00
COPYING.MinGW-w64 Remove Fixme about csq.h 2010-02-23 15:17:58 +00:00
COPYING.MinGW-w64-runtime Add 2011-2013 to copyright years 2013-02-26 20:28:23 +00:00
mingw-w64-crt crt: Add support for C95 wcstok() function for non-UCRT import libraries 2024-11-15 23:54:11 +02:00
mingw-w64-doc doc: ucrt-vs-msvcrt.txt: Update information about CRT options and links how to obtain UCRT 2024-09-02 23:17:51 +03:00
mingw-w64-headers crt: Add support for C95 wcstok() function for non-UCRT import libraries 2024-11-15 23:54:11 +02:00
mingw-w64-libraries winpthreads: also use SetThreadDescription to set thread name 2024-10-29 22:39:01 +08:00
mingw-w64-tools widl: Import Wine version wine-9.20. 2024-10-18 23:16:01 +02:00
.gitignore winpthreads: Ignore MSVC object files and Autotools generated files 2023-12-19 15:25:13 +02:00
aclocal.m4 Regenerate configure with autoconf 2.72 2024-01-09 22:26:23 +08:00
AUTHORS Merge commit '954b97bcfc515152cb5e666411d3ca0b256d589b' 2019-06-03 10:37:03 +02:00
config.h.in Add top level configury system 2010-02-24 17:55:02 +00:00
configure Regenerate configure with autoconf 2.72 2024-01-09 22:26:23 +08:00
configure.ac build: enable specific tools and libraries 2017-11-06 23:05:00 +00:00
COPYING Add 2013 as copyright year. 2013-02-26 20:29:09 +00:00
DISCLAIMER removed svn:executable property. 2010-01-15 20:22:39 +00:00
DISCLAIMER.PD Replace 'w64 mingw-runtime' by 'mingw-w64 runtime' 2012-06-28 15:40:59 +00:00
Makefile.am build: autoconf: support winpthreads library 2017-10-07 23:36:26 +00:00
Makefile.in Regenerate autotools scripts with automake 1.16.5 2023-11-17 13:14:02 +08:00