Hi Stefan,

As this function is first available starting from OS X 10.7,
I tried to solve the problem using towlower and wcsncmp.

The problem with these functions is that towlower takes a wint_t argument but wcsncmp takes wchar_t arguments. A colleague of mine however pointer out that you can do:

   res = towlower (awc) - towlower (bwc)

and achieve the same effect as calling wcsncmp.

I do not know how to enable a HAVE_WCTYPE_H test in the
corresponding configure.

Fortunately I do. :-)


Please can you try out the attached patch. If it works in your environment that I will check it in. I have already checked the patch locally and it works for builds on a Linux host.

Cheers
  Nick


diff --git a/bfd/config.in b/bfd/config.in
index b911bf6..96a3e74 100644
--- a/bfd/config.in
+++ b/bfd/config.in
@@ -262,6 +262,9 @@
 /* Define to 1 if you have the <wchar.h> header file. */
 #undef HAVE_WCHAR_H
 
+/* Define to 1 if you have the <wctype.h> header file. */
+#undef HAVE_WCTYPE_H
+
 /* Define if <sys/procfs.h> has win32_pstatus_t. */
 #undef HAVE_WIN32_PSTATUS_T
 
diff --git a/bfd/configure b/bfd/configure
index 20b2e27..a328813 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -12988,7 +12988,7 @@ $as_echo "$bfd_cv_build_exeext" >&6; }
 fi
 
 
-for ac_header in alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h wchar.h
+for ac_header in alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h wchar.h wctype.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/bfd/configure.ac b/bfd/configure.ac
index cd18689..a1b2035 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -207,7 +207,7 @@ AC_SUBST(BFD_HOSTPTR_T)
 
 BFD_CC_FOR_BUILD
 
-AC_CHECK_HEADERS(alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h wchar.h)
+AC_CHECK_HEADERS(alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h wchar.h wctype.h)
 AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h sys/stat.h sys/resource.h)
 GCC_HEADER_STDINT(bfd_stdint.h)
 AC_HEADER_TIME
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index a7e9f04..720284d 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -65,6 +65,9 @@
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
 
 /* NOTE: it's strange to be including an architecture specific header
    in what's supposed to be general (to PE/PEI) code.  However, that's
@@ -3537,7 +3540,11 @@ rsrc_write_directory (rsrc_write_data * data,
    putting its 'ucs4_t' representation in *PUC.  */
 
 static unsigned int
+#if defined HAVE_WCTYPE_H
+u16_mbtouc (wint_t * puc, const unsigned short * s, unsigned int n)
+#else
 u16_mbtouc (wchar_t * puc, const unsigned short * s, unsigned int n)
+#endif
 {
   unsigned short c = * s;
 
@@ -3609,20 +3616,34 @@ rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b)
 #elif defined HAVE_WCHAR_H
   {
     unsigned int  i;
+
     res = 0;
     for (i = min (alen, blen); i--; astring += 2, bstring += 2)
       {
+#if defined HAVE_WCTYPE_H
+	wint_t awc;
+	wint_t bwc;
+#else
 	wchar_t awc;
 	wchar_t bwc;
+#endif
 
-	/* Convert UTF-16 unicode characters into wchar_t characters so
-	   that we can then perform a case insensitive comparison.  */
-	int Alen = u16_mbtouc (& awc, (const unsigned short *) astring, 2);
-	int Blen = u16_mbtouc (& bwc, (const unsigned short *) bstring, 2);
+	/* Convert UTF-16 unicode characters into wchar_t characters
+	   so that we can then perform a case insensitive comparison.  */
+	unsigned int Alen = u16_mbtouc (& awc, (const unsigned short *) astring, 2);
+	unsigned int Blen = u16_mbtouc (& bwc, (const unsigned short *) bstring, 2);
 
 	if (Alen != Blen)
 	  return Alen - Blen;
+
+#ifdef HAVE_WCTYPE_H
+	awc = towlower (awc);
+	bwc = towlower (bwc);
+
+	res = awc - bwc;
+#else
 	res = wcsncasecmp (& awc, & bwc, 1);
+#endif
 	if (res)
 	  break;
       }
_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to