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
I committed the following.
binutils/ChangeLog
2002-06-21 Mitsru Chinen <chinen@jp.ibm.com>
* configure.in: Check for strcoll.
* configure: Regenerate.
* config.in: Regenerate.
* nm.c (main): Set locale for LC_COLLATE category.
(non_numeric_forward): Use strcoll if available.
Index: binutils/configure.in
===================================================================
RCS file: /cvs/src/src/binutils/configure.in,v
retrieving revision 1.32
diff -u -p -r1.32 configure.in
--- binutils/configure.in 27 May 2002 15:15:46 -0000 1.32
+++ binutils/configure.in 21 Jun 2002 02:31:04 -0000
@@ -100,7 +100,7 @@ AC_SUBST(DEMANGLER_NAME)
AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h fcntl.h sys/file.h)
AC_HEADER_SYS_WAIT
AC_FUNC_ALLOCA
-AC_CHECK_FUNCS(sbrk utimes setmode getc_unlocked)
+AC_CHECK_FUNCS(sbrk utimes setmode getc_unlocked strcoll)
# Check whether fopen64 is available and whether _LARGEFILE64_SOURCE
# needs to be defined for it
Index: binutils/nm.c
===================================================================
RCS file: /cvs/src/src/binutils/nm.c,v
retrieving revision 1.26
diff -u -p -r1.26 nm.c
--- binutils/nm.c 19 Jun 2002 03:07:04 -0000 1.26
+++ binutils/nm.c 21 Jun 2002 02:31:05 -0000
@@ -355,6 +355,7 @@ main (argc, argv)
#endif
#if defined (HAVE_SETLOCALE)
setlocale (LC_CTYPE, "");
+ setlocale (LC_COLLATE, "");
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -705,8 +706,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
--
Alan Modra
IBM OzLabs - Linux Technology Centre