On Thursday 08 May 2025 16:40:46 Lasse Collin wrote:
> It returns the code page that the CRT currently uses for filenames.
> With UCRT, setlocale(LC_ALL, ".UTF-8") makes the CRT use UTF-8
> for filenames, ignoring CP_ACP and CP_OEMCP. Such a setlocale() call
> can make the WinAPI filename code page differ from the code page
> used by the CRT.
>
> Otherwise the CRT and WinAPI use the same code page which is either
> CP_ACP or CP_OEMCP. The latter is used if SetFileApisToOEM has been
> called.
> ---
> mingw-w64-crt/Makefile.am | 1 +
> mingw-w64-crt/misc/__mingw_filename_cp.c | 18 ++++++++++++++++++
> mingw-w64-headers/crt/locale.h | 3 +++
> 3 files changed, 22 insertions(+)
> create mode 100644 mingw-w64-crt/misc/__mingw_filename_cp.c
>
> diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
> index 4adfbff3f..139eaa29a 100644
> --- a/mingw-w64-crt/Makefile.am
> +++ b/mingw-w64-crt/Makefile.am
> @@ -1092,6 +1092,7 @@ src_libmingwex=\
> misc/wmemchr.c misc/wmemcmp.c misc/wmemcpy.c
> misc/wmemmove.c misc/wmempcpy.c \
> misc/wmemset.c misc/mingw-access.c \
> misc/ftw32.c misc/ftw32i64.c misc/ftw64.c
> misc/ftw64i32.c \
> + misc/__mingw_filename_cp.c \
> \
> ssp/chk_fail.c ssp/gets_chk.c ssp/memcpy_chk.c
> ssp/memmove_chk.c \
> ssp/mempcpy_chk.c \
> diff --git a/mingw-w64-crt/misc/__mingw_filename_cp.c
> b/mingw-w64-crt/misc/__mingw_filename_cp.c
> new file mode 100644
> index 000000000..f6de486e9
> --- /dev/null
> +++ b/mingw-w64-crt/misc/__mingw_filename_cp.c
> @@ -0,0 +1,18 @@
> +/**
> + * This file has no copyright assigned and is placed in the Public Domain.
> + * This file is part of the mingw-w64 runtime package.
> + * No warranty is given; refer to the file DISCLAIMER.PD within this package.
> + */
> +
> +#ifndef WIN32_LEAN_AND_MEAN
> +#define WIN32_LEAN_AND_MEAN
> +#endif
> +#include <windows.h>
> +#include <locale.h>
> +
> +unsigned int __cdecl __mingw_filename_cp(void)
> +{
> + return (___lc_codepage_func() == CP_UTF8)
> + ? CP_UTF8
> + : AreFileApisANSI() ? CP_ACP : CP_OEMCP;
> +}
> diff --git a/mingw-w64-headers/crt/locale.h b/mingw-w64-headers/crt/locale.h
> index f69bd6ed7..1ec5a70ed 100644
> --- a/mingw-w64-headers/crt/locale.h
> +++ b/mingw-w64-headers/crt/locale.h
> @@ -98,6 +98,9 @@ extern "C" {
>
> _CRTIMP unsigned int __cdecl ___lc_codepage_func(void);
>
> + /* Get the code page that the CRT currently uses for filenames. */
> + unsigned int __cdecl __mingw_filename_cp(void);
> +
> #ifndef _WLOCALE_DEFINED
> #define _WLOCALE_DEFINED
> _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale);
> --
> 2.49.0
>
Just a minor question: It is OK to have this function visible in public
header file for applications? Should not be this function just internal
for mingw-w64 build?
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public