This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] nm: sort according to collating order of current locale
Dear Alan,
On Thu, 20 Jun 2002 21:57:04 +0930
Alan Modra <amodra@bigpond.net.au> wrote:
> Is there a reason to not always use strcoll if it's available?
>
> I'd be inclined to rewrite the end of non_numeric_forward like
>
> if (yn == NULL)
> return xn != NULL;
> if (xn == NULL)
> return -1;
>
> #ifdef HAVE_STRCOLL
> return strcoll (xn, yn);
> #else
> return strcmp (xn, yn);
> #endif
> }
There is no reason. I like your simple way.
Thank you very much.
But I found another problem.
Solaris 2.5 has a bug in strcoll. It seems that strcoll returns bogus values
when confronted with empty strings.
The detail is written in the following web page.
http://www.science.uva.nl/pub/solaris/solaris2/Q5.2.html
So, I've made a new patch. How is this?
------
Mitsuru Chinen
// AP Linux Competency Center, Yamato Software Lab., SWG, IBM;
diff -upr binutils-020617.orig/binutils/nm.c binutils-020617/binutils/nm.c
--- binutils-020617.orig/binutils/nm.c Wed Jun 19 15:58:58 2002
+++ binutils-020617/binutils/nm.c Thu Jun 20 23:01:43 2002
@@ -351,6 +351,7 @@ main (argc, argv)
#endif
#if defined (HAVE_SETLOCALE)
setlocale (LC_CTYPE, "");
+ setlocale (LC_COLLATE, "");
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -667,8 +668,23 @@ non_numeric_forward (P_x, P_y)
xn = bfd_asymbol_name (x);
yn = bfd_asymbol_name (y);
- return ((xn == NULL) ? ((yn == NULL) ? 0 : -1) :
- ((yn == NULL) ? 1 : strcmp (xn, yn)));
+ if (yn == NULL)
+ return xn != NULL;
+ if (xn == NULL)
+ return -1;
+
+#ifdef HAVE_STRCOLL
+ /* Solaris 2.5 has a bug in strcoll.
+ strcoll returns invalid values when confronted with empty strings. */
+ if (*yn == '\0')
+ return *xn != '\0';
+ if (*xn == '\0')
+ return -1;
+
+ return strcoll (xn, yn);
+#else
+ return strcmp (xn, yn);
+#endif
}
static int
diff -upr binutils-020617.orig/gettext.m4 binutils-020617/gettext.m4
--- binutils-020617.orig/gettext.m4 Wed Jun 19 15:58:58 2002
+++ binutils-020617/gettext.m4 Wed Jun 19 15:59:29 2002
@@ -174,7 +174,7 @@ AC_DEFUN(CY_GNU_GETTEXT,
AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
unistd.h values.h sys/param.h])
AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
-__argz_count __argz_stringify __argz_next])
+strcoll __argz_count __argz_stringify __argz_next])
if test "${ac_cv_func_stpcpy+set}" != "set"; then
AC_CHECK_FUNCS(stpcpy)