Subject: bug#72335: An attempt to fix UCRT64 build failure

From: "YI Yue" <[email-masked]>
Date: Sun, 28 Jul 2024 22:55:48 +0900

Hello, everyone

I occasionally try to compile Emacs to get the latest commits. But on Windows, I
only use Mingw64 because it's the only one officially supported by Emacs.[1]
When I try to build Emacs in MSYS2/UCRT64, I'll get these outputs:

./temacs --batch  -l loadup --temacs=pbootstrap \
        --bin-dest '/d/user/yy/emacs-build/bin/' --eln-dest '/d/user/yy/emacs-build/lib/emacs/31.0.50/'
D:\user\yy\emacs-master\src\temacs.exe: Write error to standard output: No such file or directory

MSYS2 do provides a patch[2] that do something about function
`close_output_streams' in src/sysdep.c. By applying it, I can get these results:

***
*** "make all" succeeded, but Emacs is not functional.
***

Sometimes I'll check emacs-devel to see if there are any progress in solving
this problem, such as this[3]. Two days ago I saw Pip Cet's "MPS: Win64
testers?"[4] and it inspired me that the problem may come from `init_ntproc' in
src/w32.c. After seeing UCRT's documentation[5], I think maybe we can use
`_fcloseall' instead of `fclose'? By using this, I get no error above when building 
in MSYS2/UCRT64.

I have little knowledge of MSVCRT and UCRT, it just works :)

Here is my patch, regards.

[1]: https://lists.gnu.org/archive/html/help-gnu-emacs/2022-01/msg00441.html
[2]: https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-emacs/001-ucrt.patch
[3]: https://lists.gnu.org/archive/html/emacs-devel/2024-02/msg00744.html
[4]: https://lists.gnu.org/archive/html/emacs-devel/2024-07/msg01055.html
[5]: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fclose-fcloseall