* PR29915, bfdio.c does not compile with mingw.org's MinGW
@ 2022-12-20 8:34 Alan Modra
2022-12-20 10:42 ` Torbjorn SVENSSON
0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2022-12-20 8:34 UTC (permalink / raw)
To: binutils; +Cc: torbjorn.svensson
PR 29915
* configure.ac: Add AC_CHECK_DECLS test ___lc_codepage_func.
* configure: Regenerate.
* config.in: Regenerate.
* bfdio.c (___lc_codepage_func): Move declaration to..
(_bfd_real_fopen): ..here, and use !HAVE_DECL____LC_CODEPAGE_FUNC.
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 571f12b625a..a67d4bbbeb7 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -31,11 +31,6 @@
#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
@@ -127,7 +122,11 @@ _bfd_real_fopen (const char *filename, const char *modes)
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
diff --git a/bfd/config.in b/bfd/config.in
index a59304e0a66..e5132df393c 100644
--- a/bfd/config.in
+++ b/bfd/config.in
@@ -64,6 +64,10 @@
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
diff --git a/bfd/configure b/bfd/configure
index b532fe7e8af..31dfac508a2 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13006,6 +13006,18 @@ cat >>confdefs.h <<_ACEOF
#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
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 45a293d0bcb..da6933bffc6 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -227,6 +227,7 @@ AC_CHECK_FUNCS(fcntl fdopen fileno fls getgid getpagesize getrlimit getuid \
sysconf)
AC_CHECK_DECLS([basename, ffs, stpcpy, asprintf, vasprintf, strnlen])
+AC_CHECK_DECLS([___lc_codepage_func], [], [], [[#include <locale.h>]])
BFD_BINARY_FOPEN
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PR29915, bfdio.c does not compile with mingw.org's MinGW
2022-12-20 8:34 PR29915, bfdio.c does not compile with mingw.org's MinGW Alan Modra
@ 2022-12-20 10:42 ` Torbjorn SVENSSON
0 siblings, 0 replies; 2+ messages in thread
From: Torbjorn SVENSSON @ 2022-12-20 10:42 UTC (permalink / raw)
To: Alan Modra, binutils
On 2022-12-20 09:34, Alan Modra wrote:
> PR 29915
> * configure.ac: Add AC_CHECK_DECLS test ___lc_codepage_func.
> * configure: Regenerate.
> * config.in: Regenerate.
> * bfdio.c (___lc_codepage_func): Move declaration to..
> (_bfd_real_fopen): ..here, and use !HAVE_DECL____LC_CODEPAGE_FUNC.
>
> diff --git a/bfd/bfdio.c b/bfd/bfdio.c
> index 571f12b625a..a67d4bbbeb7 100644
> --- a/bfd/bfdio.c
> +++ b/bfd/bfdio.c
> @@ -31,11 +31,6 @@
> #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
> @@ -127,7 +122,11 @@ _bfd_real_fopen (const char *filename, const char *modes)
> 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
> diff --git a/bfd/config.in b/bfd/config.in
> index a59304e0a66..e5132df393c 100644
> --- a/bfd/config.in
> +++ b/bfd/config.in
> @@ -64,6 +64,10 @@
> 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
>
> diff --git a/bfd/configure b/bfd/configure
> index b532fe7e8af..31dfac508a2 100755
> --- a/bfd/configure
> +++ b/bfd/configure
> @@ -13006,6 +13006,18 @@ cat >>confdefs.h <<_ACEOF
> #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
> diff --git a/bfd/configure.ac b/bfd/configure.ac
> index 45a293d0bcb..da6933bffc6 100644
> --- a/bfd/configure.ac
> +++ b/bfd/configure.ac
> @@ -227,6 +227,7 @@ AC_CHECK_FUNCS(fcntl fdopen fileno fls getgid getpagesize getrlimit getuid \
> sysconf)
>
> AC_CHECK_DECLS([basename, ffs, stpcpy, asprintf, vasprintf, strnlen])
> +AC_CHECK_DECLS([___lc_codepage_func], [], [], [[#include <locale.h>]])
>
> BFD_BINARY_FOPEN
>
>
Looks like a much cleaner way to handle the possible absence of the
symbol. Thanks for fixing it!
Kind regards,
Torbjörn
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-20 10:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 8:34 PR29915, bfdio.c does not compile with mingw.org's MinGW Alan Modra
2022-12-20 10:42 ` Torbjorn SVENSSON
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).