#include <locale.h>
 #endif
 
-#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR < 9
-/* This prototype was added to locale.h in version 9.0 of MinGW-w64.  */
-_CRTIMP unsigned int __cdecl ___lc_codepage_func(void);
-#endif
-
 #ifndef S_IXUSR
 #define S_IXUSR 0100    /* Execute by owner.  */
 #endif
    const wchar_t  prefix[] = L"\\\\?\\";
    const size_t   partPathLen = strlen (filename) + 1;
 #ifdef __MINGW32__
-   const unsigned int cp = ___lc_codepage_func();
+#if !HAVE_DECL____LC_CODEPAGE_FUNC
+/* This prototype was added to locale.h in version 9.0 of MinGW-w64.  */
+   _CRTIMP unsigned int __cdecl ___lc_codepage_func (void);
+#endif
+   const unsigned int cp = ___lc_codepage_func ();
 #else
    const unsigned int cp = CP_UTF8;
 #endif
 
    don't. */
 #undef HAVE_DECL_VASPRINTF
 
+/* Define to 1 if you have the declaration of `___lc_codepage_func', and to 0
+   if you don't. */
+#undef HAVE_DECL____LC_CODEPAGE_FUNC
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
 
 #define HAVE_DECL_STRNLEN $ac_have_decl
 _ACEOF
 
+ac_fn_c_check_decl "$LINENO" "___lc_codepage_func" "ac_cv_have_decl____lc_codepage_func" "#include <locale.h>
+"
+if test "x$ac_cv_have_decl____lc_codepage_func" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL____LC_CODEPAGE_FUNC $ac_have_decl
+_ACEOF
+
 
 
 case "${host}" in
 
               sysconf)
 
 AC_CHECK_DECLS([basename, ffs, stpcpy, asprintf, vasprintf, strnlen])
+AC_CHECK_DECLS([___lc_codepage_func], [], [], [[#include <locale.h>]])
 
 BFD_BINARY_FOPEN